Key not found for language
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 π§
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?.
Can you attach an example of your strings so I can add it to the test and try to fix it? Thanks
@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>
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 Show some code so we know your situation :D It is hard to help without it
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.
Can you also format your code with these tools
So I can see what is going on xD
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.
Key has empty string cause warning message. You just remove it.