react-localization icon indicating copy to clipboard operation
react-localization copied to clipboard

Key not found for language

Open stefensuhat opened this issue 8 years ago β€’ 9 comments

I keep getting this error

🚧 πŸ‘· key '0' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '1' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '2' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '3' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '4' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '5' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '6' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '7' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '8' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '9' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '10' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '11' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '12' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '13' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '14' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '15' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '16' not found in localizedStrings for language id 🚧
index.5a32104….js:151236 🚧 πŸ‘· key '17' not found in localizedStrings for language id 🚧

stefensuhat avatar Jun 28 '17 03:06 stefensuhat

found the culprit. it doesn't support nested object:

en: {
        auth: 'How do you want your egg today?',
    },
    id_ID: {
        auth: { register: 'Registrasi Berhasil. Nikmati makan siangmu sekarang juga!. }',
    },

It works with nested object but it return those warnings. Maybe you can enhance it to support it?.

stefensuhat avatar Jun 28 '17 03:06 stefensuhat

Can you attach an example of your strings so I can add it to the test and try to fix it? Thanks

stefalda avatar Jun 29 '17 21:06 stefalda

@stefensuhat It does support nested object but you are doing it wrong :D Here is working example:

const strings = new LocalizedStrings({
  en: {
    auth: {
      register: 'Registrasi Berhasil. Nikmati makan siangmu sekarang juga!.'
    }
  }
});
// usage
<div>{strings.auth.register}</div>

henrikra avatar Jul 11 '17 15:07 henrikra

Same bug happens to me after 0.0.16, that causes all languages' messages become first langauge's. Verified that it works <=0.0.15.

HaydnChen avatar Jul 28 '17 08:07 HaydnChen

@HaydnChen Show some code so we know your situation :D It is hard to help without it

henrikra avatar Jul 28 '17 08:07 henrikra

I use GNU gettext and po2json to generate language files, such as: zh.js module.exports = {"":{"project-id-version":"i18next-conv","pot-creation-date":"2017-07-28T07:34:42.018Z","po-revision-date":"2017-07-28T02:12:51.988Z","mime-version":"1.0","content-type":"text/plain; charset=UTF-8","content-transfer-encoding":"8bit","plural-forms":"nplurals=2; plural=(n != 1)"},"周岁":"","半年":"","ε­£εΊ¦":"","月":"","倩":"","ζ— ε…³":"","终身":"","{0}εΉ΄":"","至{0}周岁":"","{0}月":"","{0}倩":"","θΆΈδΊ€":"","{0}εΉ΄δΊ€":""};

en.js module.exports = {"":{"project-id-version":"i18next-conv","pot-creation-date":"2017-07-28T07:34:42.018Z","po-revision-date":"2017-07-28T02:12:51.988Z","mime-version":"1.0","content-type":"text/plain; charset=UTF-8","content-transfer-encoding":"8bit","plural-forms":"nplurals=2; plural=(n != 1)"},"周岁":" Years Old","半年":"","ε­£εΊ¦":"","月":"","倩":"","ζ— ε…³":"","终身":"","{0}εΉ΄":"","至{0}周岁":"","{0}月":"","{0}倩":"","θΆΈδΊ€":"","{0}εΉ΄δΊ€":""};

import LocalizedStrings from 'react-localization'; import zh from './zh'; import en from './en';

const strings = new LocalizedStrings({ zh, en, });

export function t(message, ...args) { let trans = strings[message]; if (!trans || trans === '') { trans = message; } if (args && args.length >= 0) { trans = strings.formatString(trans, ...args); } return trans; }

export function lang(langCode) { if (langCode) { strings.setLanguage(langCode); } return strings.getLanguage(); }

After 0.0.16 lang('en') can not work.

HaydnChen avatar Jul 28 '17 09:07 HaydnChen

Can you also format your code with these tools image So I can see what is going on xD

henrikra avatar Jul 28 '17 09:07 henrikra

The format is not a matter, just use my zh and en json data and t function can reproduce this bug, 'key xxx not found in localizedStrings for language id' appears in browser console.

HaydnChen avatar Jul 28 '17 10:07 HaydnChen

Key has empty string cause warning message. You just remove it.

nguyenmanh1507 avatar Oct 23 '17 16:10 nguyenmanh1507