Jumbo 5.0
Search…
Adding New Language
Process to add a new language of your choice
In order to add a new language in the template, you need to follow the below steps.
We are taking the Russian language as an example. So, here are the steps:
  1. 1.
    Create a Locale
    This step can be completed by following below instructions:
    • Create a Local JSON File
      We need a locale data JSON file where we can keep all our labels, messages, etc. language variables to set their translations for the specific language.
      For this, create a file “ru_RU.json” under the folder
      src/i18n/locales
      Now, you can copy the whole content of the file src/i18n/locales/en_US.json
      This file contains all the translation variables with the value of English language strings and paste that into our newly created ru_RU.json file.
      The above step will give us all the labels, messages, etc variables and we can replace their values with the Russian translation.
      For example, let’s change value of pages.samplePage from "Sample Page" to "Пример страницы".
    • Create i18 Context
      Now, in this step, we are going to create an entry file in the foldersrc/i18n/entry/ with the name ru_RU.js.
      This file is needed to import both the react-intl’s local data and our locale data JSON file and setup the i18 context.
  2. 2.
    Add Locale to appLocales
    In this step, we will add our newly created i18 context in the above step to the react-intl’s appLocales. This will be done in two further steps:
    1. 1.
      Open the file src/i18n/index.js and Import i18 context locale entry file into this.
    2. 2.
      Add imported i18 context variable to the appLocale Object. Check the following source code for reference:
      1
      import enLang from './entries/en-US';
      2
      import zhLang from './entries/zh-Hans-CN';
      3
      import arLang from './entries/ar_SA';
      4
      import itLang from './entries/it_IT';
      5
      import esLang from './entries/es_ES';
      6
      import frLang from './entries/fr_FR';
      7
      8
      /* adding the new Russian language */
      9
      import ruLang from './entries/ru_RU';
      10
      11
      const AppLocale = {
      12
      en: enLang,
      13
      zh: zhLang,
      14
      ar: arLang,
      15
      it: itLang,
      16
      es: esLang,
      17
      fr: frLang,
      18
      ru: ruLang
      19
      };
      20
      21
      export default AppLocale;
      Copied!
  3. 3.
    Add an Option to Language Switcher
    For this, we need to access the data.js file which can be found under src/@jumbo/components/AppLayout/partials/LanguageSwitcher/ folder.
    Here in this file, we need to add the following language object to the languageData array:
    1
    2
    {
    3
    languageId: 'russian', // Unique ID for language
    4
    locale : 'ru', // locale name to link with the previously named locale
    5
    name : 'Russian', // Display name of the language
    6
    Icon : 'ru' // To choose the flag of the country
    7
    }
    Copied!
By following the above steps your app is now ready with the new language.
Last modified 1yr ago
Copy link