Localization
You can create many localizations (Locales) in each environment within a project in FoxNose CMS. Locales enable you to manage multilingual content efficiently and flexibly to cater to different regions and audiences.
Default Locale
At least one Locale is mandatory, so an environment will always have a Locale from the start. By default, this Locale is set to English (en), but you can change it to any other language at any time. However, it’s important to note that changing the Locale does not alter the existing data associated with it.
If you don’t need additional Locales, no further action is required. However, if you decide to add more Locales in the future, you can do so at any moment without limitations.
Fallback Mechanism
FoxNose CMS introduces the concept of a Default Locale. This Locale is required for all data, ensuring there is always a complete dataset in at least one language. When saving data for non-default Locales, FoxNose CMS utilizes a fallback system. If certain data is missing for a non-default Locale, the system will automatically copy the missing content from the Default Locale during the save operation.
This fallback process occurs at the time of data saving, ensuring that the non-default Locale is fully populated with both the provided data and any missing data from the Default Locale. It’s important to understand that this is not a runtime fallback during data retrieval—it’s a copy of the content during data storage.
As a result, the overall size of a document increases with each Locale. For example, if the data for the Default Locale occupies 10KB, and the same data is replicated for two additional Locales, each also using 10KB, the total size of the document will be 30KB. Every Locale contributes to the final document size, as the content is stored independently for each Locale.
Accessing Localized Data
When accessing data through the Delivery API, you have two options:
-
Specify the Locale: You can explicitly define which Locale you want to retrieve from the Delivery API. In this case, the data corresponding to the specified Locale will be returned.
-
Use the Default Locale: If no Locale is specified in the request, the data for the Default Locale will be automatically returned.
This system provides flexibility in managing content across multiple languages, ensuring that the right content is delivered based on your preferences or project requirements.
Adding and Deleting Behavior
After Adding a New Locale
After adding a new Locale, it becomes immediately available through the Delivery API. However, since data for this Locale has not yet been saved, the system will return data from the Default Locale due to the fallback mechanism. Once you update the documents with content specific to the new Locale, the Delivery API will return the updated data.
After Deleting a Locale
When you delete a Locale and after the cache expires, data for this Locale will no longer be accessible through the Delivery API. However, the actual data remains in the database and continues to occupy storage space. To completely remove the data associated with the deleted Locale, you need to create a new version of the document and delete the versions that contain data for that Locale.
Be mindful that even though the Locale is deleted, its data still contributes to storage usage. Properly managing and cleaning up data ensures optimal performance and resource utilization.
The Locale API Model
Properties
- Name
name
- Type
- string
- Description
The name of the locale. This parameter is primarily for easier identification of the locale in the interface and has no functional impact beyond that.
- Name
code
- Type
- string
- Description
The locale key used throughout the API to reference a specific locale. Examples include: "en", "en_US", "fr", "es". This value must be unique for each locale.
- Name
project
- Type
- string
- Description
The key of the project that this locale is associated with. This parameter links the locale to a specific project within the system.
- Name
created_at
- Type
- datetime
- Description
The timestamp indicating when the locale was created. This parameter records the date and time of the locale’s creation.
- Name
is_default
- Type
- bool
- Description
A flag that specifies whether this locale is the default for the project. Only one locale can be set as the default. If this parameter is set to true and another default locale already exists, the other locale’s is_default value will automatically be set to false.
Create Locale
This endpoint allows you to add a new locale in the current environment.
- Authentication method: JWT
Required attributes
- Name
name
- Type
- string
- Description
- Minimum length: 1
- Maximum length: 100
- Name
code
- Type
- string
- Description
- Minimum length: 1
- Maximum length: 50
- Must be alphabetic or contain an underscore between alphabetic blocks
- Must be unique within the environment
Optional attributes
- Name
is_default
- Type
- bool
- Description
- Default: false
Errors
- Name
locale_already_exists
- Description
Locale with the same code already exists in an environment.
Request
curl https://api.foxnose.net/7c9h4pwu/v1/7c9h4pwu/locales/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"name": "Français",
"code": "fr",
"is_default": false
}'
Response
{
"name": "Français",
"code": "fr",
"project": "d7hazs1x",
"created_at": "2024-09-29T03:49:07.859748-05:00",
"is_default": false
}
List All Locales
This endpoint allows you to get a list of locales within the current environment.
- Authentication method: JWT
- Returns all results in a single response without pagination.
Request
curl https://api.foxnose.net/v1/7c9h4pwu/locales/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
Response
[
{
"name": "English",
"code": "en_US",
"project": "d7hazs1x",
"created_at": "2024-08-02T15:10:47.867952-05:00",
"is_default": true
},
{
"name": "Français",
"code": "fr",
"project": "d7hazs1x",
"created_at": "2024-09-29T03:49:07.859748-05:00",
"is_default": false
}
]
Retrieve Locale
This endpoint allows you to get a specific locale by its code.
- Authentication method: JWT
Request
curl https://api.foxnose.net/v1/7c9h4pwu/locales/en/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"
Response
{
"name": "Français",
"code": "fr",
"project": "d7hazs1x",
"created_at": "2024-09-29T03:49:07.859748-05:00",
"is_default": false
}
Update Locale
This endpoint allows you to update a specific locale by its code.
- Authentication method: JWT
Required attributes
- Name
name
- Type
- string
- Description
- Minimum length: 1
- Maximum length: 100
- Name
code
- Type
- string
- Description
- Minimum length: 1
- Maximum length: 50
- Must be alphabetic or contain an underscore between alphabetic blocks
- Must be unique within the environment
Optional attributes
- Name
is_default
- Type
- bool
- Description
- Default: false
Errors
- Name
locale_already_exists
- Description
Locale with the same code already exists in an environment.
Request
curl https://api.foxnose.net/v1/7c9h4pwu/locales/en/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"name": "French",
"code": "fr",
"is_default": false
}'
Response
{
"name": "French",
"code": "fr",
"project": "d7hazs1x",
"created_at": "2024-09-29T03:49:07.859748-05:00",
"is_default": false
}
Delete Locale
Removes a specific locale.
- Authentication method: JWT
- Does not accept additional parameters.
- Returns a 204 status code if the operation is successful.
Request
curl https://api.foxnose.net/v1/7c9h4pwu/locales/en/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json"