localization key in your FrogBot Config:
Config Options
Add thelocalization property to your FrogBot Config to enable Localization project-wide. You’ll need to provide a list of all locales that you’d like to support as well as set a few other options.
To configure locales, use the localization.locales property in your FrogBot Config:
Locales
The locales array is a list of all the languages that you would like to support. This can be strings for each language code, or full configuration objects for more advanced options. The locale codes do not need to be in any specific format. It’s up to you to define how to represent your locales. Common patterns are to use two-letter ISO 639 language codes or four-letter language and country codes (ISO 3166‑1) such asen-US, en-UK, es-MX, etc.
Locale Object
Filter Available Options
In some projects you may want to filter the available locales shown in the admin UI selector. You can do this by providing afilterAvailableLocales function in your FrogBot Config. This is called on the server side and is passed the array of locales and req, the current FrogBotRequest with req.frogbot. This means that you can determine what locales are visible in the localizer selection menu at the top of the admin panel. You could do this per user, or implement a function that scopes these to tenants and more. Here is an example using request headers in a multi-tenant application:
router.refresh in a custom component that watches when values that affect the result change. In the example above, you would want to do this when supportedLocales changes on the tenant document.
Field Localization
FrogBot Localization works on a field level—not a document level. In addition to configuring the base FrogBot Config to support Localization, you need to specify each field that you would like to localize. Here is an example of how to enable Localization for a field:title field will now be saved in the database as an object of all locales instead of a single string.
All field types with a name property support the localized property—even the more complex field types like arrays and blocks.
Note: Enabling Localization for field types that support nested fields
will automatically create localized “sets” of all fields contained within the
field. For example, if you have a page layout using a blocks field type, you
have the choice of either localizing the full layout, by enabling Localization
on the top-level blocks field, or only certain fields within the layout.
Status Localization
When Localization is enabled and a collection has drafts enabled and at least one localized field, FrogBot localizes the_status field. Publication status is then tracked per locale, so you can publish in English while keeping Spanish as a draft.
When the status field is localized, it is stored as an object keyed by locale:
_status isn’t localized, the status field remains a single string ('draft' or 'published') representing document status across all locales.
Publishing and unpublishing per locale
When the_status field is localized, publishing and unpublishing are scoped to a single locale by default. The locale being acted on is the one provided to the operation (via the locale parameter, or the request locale). This means publishing in one locale leaves the other locales’ statuses untouched.
publishAllLocales or unpublishAllLocales. These set the status for all locales the user has access to, regardless of the active locale:
locale: 'all' together with _status: 'published' also publishes every locale, and is equivalent to publishAllLocales: true.
When the
_status field is not localized, publishing and unpublishing always apply to the whole
document, and publishAllLocales / unpublishAllLocales have no effect.Retrieving Localized Docs
When retrieving documents, you can specify which locale you’d like to receive as well as which fallback locale should be used.REST API
REST API locale functionality relies on URL query parameters.?locale=
Specify your desired locale by providing the locale query parameter directly in the endpoint URL.
?fallback-locale=
Specify fallback locale to be used by providing the fallback-locale query parameter. This can be provided as either a
valid locale as provided to your base FrogBot Config, or 'null', 'false', or 'none' to disable falling back.
Example:
GraphQL API
In the GraphQL API, you can specifylocale and fallbackLocale args to all relevant queries and mutations.
The locale arg will only accept valid locales, but locales will be formatted automatically as valid GraphQL enum
values (dashes or special characters will be converted to underscores, spaces will be removed, etc.). If you are curious
to see how locales are auto-formatted, you can use the GraphQL playground.
The fallbackLocale arg will accept valid locales, an array of locales, as well as none to disable falling back.
Example:
In GraphQL, specifying the locale at the top level of a query will
automatically apply it throughout all nested relationship fields. You can
override this behavior by re-specifying locale arguments in nested related
document queries.
Local API
You can specifylocale as well as fallbackLocale within the Local API as well as properties on the options
argument. The locale property will accept any valid locale, and the fallbackLocale property will accept any valid
locale, array of locales, as well as 'null', 'false', false, and 'none'.
Example: