Skip to main content

Introduction

🎯 What does this module do?

The Locales module lets you manage multi-language support in your OneEntry project - retrieve available languages, detect user locale, and build internationalized applications that serve content in multiple languages.

Think of it as your language manager - instead of hardcoding languages in your app, you fetch the list of active languages from OneEntry dynamically, allowing your content to automatically adapt to different locales (English, Russian, Arabic, Spanish, etc.).


📖 Simple Explanation

In modern applications, you often need to support multiple languages:

  • 🌍 E-commerce sites - Serve customers in different countries (English, French, German)
  • 📱 Mobile apps - Adapt UI to user's device language
  • 🌐 Websites - Show content in visitor's preferred language
  • 📚 Documentation - Provide help in multiple languages
  • 🎮 Games - Translate interface and content

The problem with hardcoding languages:

Issues:

  • 🔄 Hard to update - Need to redeploy to add new languages
  • 🌍 Not synchronized - App languages may differ from CMS languages
  • Translation mismatches - Content exists in CMS but not in app
  • 🔧 Manual maintenance - Update code every time languages change

The Locales solution:

Benefits:

  • 🔄 Always in sync - Languages match what's configured in OneEntry
  • 🌍 Dynamic - Add/remove languages without code changes
  • Validated - Only show languages that have content
  • 🎯 Centralized - Manage languages in one place

✨ Key Concepts

What is a Locale?

A locale is a language and region combination that determines how content is displayed:

  • Language Code - ISO 639-1 language code (e.g., en, ru, ar)
  • Region Code - ISO 3166-1 country code (e.g., US, GB, RU)
  • Locale Identifier - Combined format: language_REGION (e.g., en_US, ru_RU, ar_SA)

Examples:

Locale CodeLanguageRegionDescription
en_USEnglishUnited StatesAmerican English
en_GBEnglishGreat BritainBritish English
ru_RURussianRussiaRussian
es_ESSpanishSpainEuropean Spanish
es_MXSpanishMexicoMexican Spanish
ar_SAArabicSaudi ArabiaArabic (Saudi Arabia)
fr_FRFrenchFranceFrench
de_DEGermanGermanyGerman

Locale Structure

Each locale in OneEntry 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
image: null, // image
position: 1, // position
}

Why Use Locales Module?

BenefitDescription
Multi-language SupportServe content in user's preferred language
Dynamic Language ListLanguages sync with OneEntry configuration
Default Locale DetectionAutomatically identify default language
Active Locale FilteringShow only enabled languages
Centralized ManagementUpdate languages in admin panel, not code
User ExperienceLet users choose their language

Common Use Cases

Use CaseDescriptionExample
Language SelectorDropdown menu to switch languagesWebsite header with language flags
Content LocalizationFetch content in user's languageBlog posts in English or Russian
RoutingURL structure per language/en/about, /ru/about
Fallback LogicShow default language if translation missingShow English if Spanish not available
User PreferencesRemember user's language choiceSave locale in cookies/localStorage

📋 What You Need to Know

1. Locales are Configured in Admin Panel

You cannot create locales via the SDK - they're configured in the OneEntry admin panel:

OneEntry Admin Panel → Settings → Languages → Add Language → Select Locale

The SDK is for fetching locale information, not creating locales.

2. Active vs. Inactive Locales

Not all configured locales may be active:

StatusMeaningWhen to Use
Active (isActive: true)Locale is enabled and has contentShow in language selector
Inactive (isActive: false)Locale is disabled or being preparedHide from users

Best practice: Always filter by isActive when building language selectors

3. Default Locale

Every OneEntry project has one default locale:

  • Default locale (isDefault: true) - The primary language
  • Used when no locale is specified
  • Fallback when translation is missing

4. Locale Code vs. Short Code

Each locale has two code formats:

FieldFormatExampleUse For
codelanguage_REGIONen_US, ru_RUFull locale identification
shortCodelanguageen, ruLanguage-only identification

📊 Quick Reference Table

MethodDescriptionReturnsUse Case
getLocales()Get all locales (active and inactive)Promise<Locale[]>Fetch available languages

Locale Structure:

interface Locale {
id: number;
shortCode: string; // Language code only (e.g., "en")
code: string; // Full locale code (e.g., "en_US")
name: string; // Display name (e.g., "English (United States)")
nativeName: 'English (USA)',
isActive: boolean; // Is locale enabled
isDefault: boolean; // Is default locale
createdAt: string;
updatedAt: string;
image: null,
position: number,
}

❓ Frequently Asked Questions (FAQ)

1. How do I add new languages to my project?

You cannot add locales via the SDK. Locales are configured in the OneEntry Admin Panel:

1. Log in to OneEntry Admin Panel
2. Go to Settings → Languages
3. Click "Add Language"
4. Select locale from dropdown (e.g., "French (France)")
5. Activate the locale
6. Save

Now fetch it via SDK:
const locales = await Locales.getLocales();
// Returns: [..., { code: "fr_FR", name: "French (France)", isActive: true }]

2. What's the difference between code and shortCode?

FieldFormatExampleUse For
codeFull locale (language + region)en_US, en_GBSpecific regional content
shortCodeLanguage onlyenLanguage-level grouping

Best practice: Use code for fetching content, use shortCode for grouping/filtering.


3. How do I set the default language?

You cannot set default locale via SDK. The default locale is configured in OneEntry Admin Panel:

1. Go to Settings → Languages
2. Find the locale you want as default
3. Click "Set as Default"
4. Save

The SDK will reflect this change:
const locales = await Locales.getLocales();
const defaultLocale = locales.find(l => l.isDefault);
console.log(defaultLocale.code); // e.g., "en_US"

Note: Only one locale can be default at a time.


4. Should I show inactive locales to users?

No! Always filter by isActive:

Why? Inactive locales may:

  • Be in development (content not ready)
  • Be temporarily disabled
  • Not have translations for all content

5. How do I handle missing translations?

Use fallback logic


6. Can I cache locales?

Yes! Locales rarely change, so caching is recommended


8. Can I use Locales with Next.js i18n?

Yes! Integrate OneEntry locales with Next.js:


9. How do I group locales by language?

Group variants of the same language


10. What if I need to translate UI elements (not CMS content)?

OneEntry Locales module is for CMS content locales only. For UI translation:

Option 1: Use i18n library (react-i18next, next-i18next)

npm install react-i18next i18next

Option 2: Store UI translations in OneEntry

Create a "translations" page type and fetch translation strings


💡 Important Notes

⚠️ Locales are Read-Only

The Locales module is read-only:

  • ✅ Fetch locales
  • ✅ Filter by active status
  • ✅ Find default locale
  • ❌ Cannot create locales
  • ❌ Cannot update locales
  • ❌ Cannot delete locales

To modify: Use OneEntry Admin Panel.

🌍 Always Filter Active Locales

Only show active locales to users`

Why? Inactive locales may not have complete translations.

Locales rarely change - implement caching

🔄 Sync with Content Locales

Ensure UI languages match available content


🎓 Best Practices

✅ DO:

  1. Always filter active locales - Show only enabled languages
  2. Cache locales - They rarely change, cache for performance
  3. Use default locale as fallback - Handle missing translations
  4. Save user preference - Remember language choice
  5. Validate locale codes - Check locale exists before using
  6. Detect browser language - Auto-select user's language
  7. Group by language - Show language variants logically
  8. Use TypeScript for type safety - Leverage Locale interface

❌ DON'T:

  1. Don't show inactive locales - Users can't access content
  2. Don't hardcode locales - Always fetch dynamically
  3. Don't ignore default locale - Essential for fallback
  4. Don't fetch on every page load - Implement caching
  5. Don't use IDs for locale selection - Use codes instead
  6. Don't assume locales exist - Validate before using
  7. Don't mix locale code formats - Be consistent (use code or shortCode)
  8. Don't forget error handling - Always use try/catch

Definition of the Locales module

The 'Locales' module enables multi-language support in OneEntry.

Thanks to the support of multiple languages in OneEntry Platform, you can flexibly customize the interface of your dashboard and conveniently manage languages in your project. In this section, you can learn about the principles of working with languages.

More information about the module's user interface https://doc.oneentry.cloud/docs/category/languages


const { Locales } = defineOneEntry(
"your-project-url", {
"token": "your-app-token"
}
);