Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespaced key with spaces doesn't work #1670

Closed
jamesots opened this issue Oct 1, 2021 · 2 comments
Closed

Namespaced key with spaces doesn't work #1670

jamesots opened this issue Oct 1, 2021 · 2 comments

Comments

@jamesots
Copy link

jamesots commented Oct 1, 2021

馃悰 Bug Report

If I try to translate a key which includes a namespace and a space, but doesn't include a key separator, the key is not translated.

To Reproduce

const i18next = require('i18next')

i18next.init({
  lng: 'en',
  resources: {
    en: {
      translation: {
        errorCodes: {
          'UNAUTHORIZED': 'Unauthorized',
          'BAD REQUEST': 'Bad request'
        },
        'UNAUTHORIZED': 'Unauthorized',
        'BAD REQUEST': 'Bad request'
      }
    }
  }
})

let errorCode = 'UNAUTHORIZED' 
console.log(i18next.t(`translation:errorCodes.${errorCode}`))
console.log(i18next.t(`translation:${errorCode}`))
console.log(i18next.t(`${errorCode}`, {ns: 'translation'}))
errorCode = 'BAD REQUEST'
console.log(i18next.t(`translation:errorCodes.${errorCode}`))
console.log(i18next.t(`translation:${errorCode}`))
console.log(i18next.t(`${errorCode}`, {ns: 'translation'}))

Expected behavior

With version 20.6.1, the code above prints

Unauthorized
Unauthorized
Unauthorized
Bad request
Bad request
Bad request

With version 21.2.0, it prints

Unauthorized
Unauthorized
Unauthorized
Bad request
translation:BAD REQUEST
Bad request

Your Environment

  • runtime version: node 14, Chrome
  • i18next version: 21.2.0
  • os: Mac, Windows, Linux

(This is very similar to #1661, but includes namespaces, which that defect did not.)

@adrai
Copy link
Member

adrai commented Oct 1, 2021

This is because of of the new natural language detection feature... https://www.i18next.com/misc/migration-guide#natural-language-detection
The only way to omit that check is to provide the keySeparator option with the new v21.2.1

@jamesots
Copy link
Author

jamesots commented Oct 1, 2021

Great! We already have ns and key separators set, so I'll just upgrade to 21.2.1 now that it's available. Thanks.

@jamesots jamesots closed this as completed Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants