Skip to main content

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 CodeLanguageRegionDescription
en_USEnglishUnited StatesAmerican English
en_GBEnglishUnited KingdomBritish English
ru_RURussianRussiaRussian
es_ESSpanishSpainEuropean Spanish
es_MXSpanishMexicoMexican Spanish
ar_SAArabicSaudi ArabiaArabic (Saudi Arabia)
fr_FRFrenchFranceFrench
de_DEGermanGermanyGerman

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​

FieldFormatExampleUse For
codelanguage_REGIONen_US, ru_RUFull locale identification
shortCodelanguageen, ruLanguage-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​

MethodDescriptionUse Case
getLocales()Get all active localesFetch available languages