Locales
Fetch the languages configured in your project to power multi-language content and locale detection.
More information about the module's user interface: https://doc.oneentry.cloud/docs/category/languages (opens in a new tab)
The Locales module returns the active languages of your OneEntry project, so you can serve content in several languages. Fetch the list from OneEntry instead of hardcoding languages, and your app adapts to the locales you enable (English, Russian, Arabic, Spanish, etc.).
Languages are configured in the OneEntry admin panel, and the SDK only reads them.
Quickstart
Initialize the module from defineOneEntry:
const { } = defineOneEntry( , { });
Fetch the active locales and read their fields:
// Returns only active locales (isActive: true).
const locales = await Locales.getLocales();
if ('statusCode' in locales) throw new Error(locales.message);
console.log(`${locales.length} active languages`);
locales.forEach((locale) => {
console.log(locale.code, locale.name, locale.shortCode);
});
Locales
A locale is a language and region combination that determines how content is displayed:
- Language code: ISO 639-1 (e.g.
en,ru,ar) - Region code: ISO 3166-1 (e.g.
US,GB,RU) - Locale identifier:
language_REGION(e.g.en_US,ru_RU,ar_SA)
| Locale Code | Language | Region | Description |
|---|---|---|---|
en_US | English | United States | American English |
en_GB | English | United Kingdom | British English |
ru_RU | Russian | Russia | Russian |
es_ES | Spanish | Spain | European Spanish |
es_MX | Spanish | Mexico | Mexican Spanish |
ar_SA | Arabic | Saudi Arabia | Arabic (Saudi Arabia) |
fr_FR | French | France | French |
de_DE | German | Germany | German |
Locale object
Each locale returned by getLocales() (ILocalEntity) has:
{
id: 146, // unique ID
shortCode: 'en', // short code
code: 'en_US', // full code
name: 'English (USA)', // name
nativeName: 'English (USA)', // native name
isActive: true, // is active (always true here)
image: null, // image
position: 1, // position
}
code and shortCode
| Field | Format | Example | Use For |
|---|---|---|---|
code | language_REGION | en_US, ru_RU | Full locale identification |
shortCode | language | en, ru | Language-only identification |
Configured in the admin panel
You can't create, update or delete locales through the SDK; they are configured in the OneEntry admin panel:
OneEntry Admin Panel → Settings → Languages → Add Language → Select Locale
Only active locales
getLocales() returns only active locales (isActive: true). Locales disabled in the admin panel are not returned, so you don't need to filter them on the client. Each locale still carries the isActive flag (always true here), along with code, shortCode, name, nativeName, image and position.
The response has no default-locale field. Choose a fallback language in your app and use it when content is missing for the requested locale. Locales rarely change, so the result is safe to cache.
Methods
| Method | Description | Use Case |
|---|---|---|
| getLocales() | Get all active locales | Fetch available languages |
Related
- Pages Module: localized page content
- Products Module: multi-language products
- GeneralTypes Module: entity type classification