Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
¿Cómo configurar el idioma alternativo de i18n.js?

Estoy usando la biblioteca i18n-js .

Para establecer su configuración, estoy haciendo lo siguiente:

 export function setI18nConfig(locale = undefined) { // Fallback if no available language fits const fallback = DEFAULT_APP_LANGUAGE; const language = APP_LANGUAGES.find((language) => language.locale === locale) ?? fallback; const { locale: _locale, isRTL } = language; // Clear the translation cache translate.cache.clear(); // Update the layout direction I18nManager.forceRTL(isRTL); // Set the i18n-js config i18n.locale = _locale; i18n.translations = { [_locale]: translationGetters[_locale]() }; // Set moment config moment.locale(_locale); // Return the appropiate locale return _locale; }

Como puede ver, para configurar el diccionario de traducciones, llamo a este getter:

 export const translationGetters = { en: () => require("../../../assets/languages/en/translations.json"), es: () => require("../../../assets/languages/es/translations.json"), fr: () => require("../../../assets/languages/fr/translations.json"), it: () => require("../../../assets/languages/it/translations.json"), pt: () => require("../../../assets/languages/pt/translations.json"), };

Para establecer el idioma alternativo, solo estoy tratando de encontrar la configuración regional dada (argumento de función) en mi variedad de idiomas de aplicaciones.

 export const APP_LANGUAGES = [ { name: "English", locale: "en", isRTL: false, }, { name: "French", locale: "fr", isRTL: false, }, { name: "Italian", locale: "it", isRTL: false, }, { name: "Portuguese", locale: "pt", isRTL: false, }, { name: "Spanish", locale: "es", isRTL: false, }, ];

Si no está en la lista, entonces uso DAFAULT_APP_LANGUAGE como traducción.

 export const DEFAULT_APP_LANGUAGE = APP_LANGUAGES[0];

¿Es esta la forma típica o correcta de configurar los respaldos de i18n.js?

¿No hay una forma sencilla de hacerlo?

Quiero decir, algo como:

 i18n.fallbackLanguage = "en"; i18n.locale = locale; i18n.translations = { [locale]: translationGetters[locale](), [fallbackLanguage]: translationGetters[fallbackLanguage]() };

Nota: ¡También necesito configurar la configuración de isRTL para el respaldo!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!