i18next json dot in key or label

10.6k views Asked by At

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 remove the "." (dot) from the label and the function t, than the text is translated.

How to solve this?

3

There are 3 answers

0
Aditya Tomar On

You can set "keySeparator" : false in your init option.

1
Peter Petrik On

Documentation explains that dot is by default treated as a key separator. You can

  • replace dot with .
  • put dot outside translated string i18n.t("SOME TEXT TO BE TRANSLATED") + "."
  • change key separator

    You can change namespace and/or key separator by setting options on init:

    nsSeparator: ':::'
    keySeparator: '::'
    
0
Cheton Wu On

You could try using https://github.com/cheton/i18next-text. It allows you using i18next translation without having the key as strings, and you do not need to worry about i18n key naming. Furthermore, you can also register the i18n helper with Handlebars.

Following 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 JSFiddle.