I18next json dot in key or shortcut

JS: i18n.t("SOME TEXT TO BE TRANSLATED.")

JSON: "SOME TEXT TO BE TRANSLATED.": "Een stukje tekst om te vertalen"

i18n.t("SOME TEXT TO BE TRANSLATED.")

gives me "SOME TEXT TO BE TRANSLATED.".

If I delete "." (dot) from label and function t than the text is translated.

How to solve this?

+3


source to share


3 answers


The documentation explains that period is treated as a key separator by default. You can



  • replace dot with .

  • put period outside the translated string i18n.t("SOME TEXT TO BE TRANSLATED") + "."

  • change key separator

    You can change the namespace and / or key separator by setting parameters in init:

    nsseparator = ':::'
    keyseparator = '::'
    
          

+4


source


You can try using https://github.com/cheton/i18next-text . This allows the i18next translation to be used without having a key in strings, and you don't have to worry about naming the i18n keys. Alternatively, you can also register the i18n helper with Handlebars.

Below is a simple example:



var i18n = require('i18next');

// extends i18n object to provide a new _() method
i18n._ = require('i18next-text')._;

i18n._('Save your time and work more efficiently.');

      

Check out the demo on the JSFiddle.

0


source


You can set "keySeparator": false in the init parameter.

0


source







All Articles