question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Must use different character for nsSeparator and keySeparator

See original GitHub issue

Using the same character for nsSeparator and keySeparator ('.') fails to translate keys within objects.

clients.json (CLIENTS namespace):

{
    "MAINTENANCE": {
        "DELETE_PROMPT": "Are you sure you want to delete this client?"
    }
}
i18next.t('CLIENTS.MAINTENANCE.DELETE_PROMPT') // nope!

Changing the namespace separator to ':' works as expected.

i18next.t('CLIENTS:MAINTENANCE.DELETE_PROMPT') // yaas!

Ideally you should be able to use the same character to separate the namespace from key paths, but if not, at the very least the documentation should make it very clear this is not an option. 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jamuhlcommented, Feb 2, 2017

argh…always the index 😉…just published i18next@6.1.2 fixing it - and added some tests for this feature.

There is no documentation for contribution. npm i to install build dependencies. npm test is all that should be done before submitting a PR. The PR will run through travis CI and coveralls anyway, so failing tests would show up in the PR anyway.

0reactions
codeandcatscommented, Feb 2, 2017

Hi Jamuhl,

Thanks for adding that change, I’ve had some time to test it this morning and although it worked for most translations, I noticed one of my namespaces, whichever namespace is first in the config, would consistently not get translated.

I narrowed it down to this line of code:

if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0])) namespaces = parts.shift();

I believe should be:

if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();

I can submit a PR if you like, I’m just curious (for this and any future contributions) if you have any doco for contributing, e.g. install + build steps, conventions, etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

i18next json dot in key or label - Stack Overflow
Documentation explains that dot is by default treated as a key separator. ... It allows you using i18next translation without having the key...
Read more >
Configuration Options - i18next documentation
experimental: enable to update default values using the saveMissing (Works only if defaultValue is different from translated value.
Read more >
Translation features - i18next
using multiple keys (first found will be translated) ... Hint: You can change namespace and/or key separator by setting options on init: nsseparator...
Read more >
Documentation: 15: 24.3. Character Set Support - PostgreSQL
It can be overridden when you create a database, so you can have multiple databases each with a different character set. An important...
Read more >
Continuation characters - BMC Documentation
Control statements must contain 80-character fixed length records. ... statement on another line, you must use a continuation character.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found