ReactNativeLocalization
ReactNativeLocalization copied to clipboard
iOS is zh-Hans android is zh-CN
'zh-CN': { title: "运单", subtitle: "创建并监控运单", SD_title: "运单" } if I use this language code the iOS localized not work, if I use zh-Hans(iPhone language Code) the android not work
how to keep same I means that like this code ,use 2 language code ['zh-CN','zh-Hans']:{ title: "运单", subtitle: "创建并监控运单", SD_title: "运单" }
@VesperHan I think you can use Platform.os to check before start app then init the correct locale code.
[UPDATED]: Another solution:
const cnLanguageCodes = [
"zh-Hans-CN",
"zh-Hant-CN",
"zh-HK-CN",
"zh-Hans",
"zh-Hant",
"zh-HK",
"zh",
]
const cnTexts = {
title: "运单",
subtitle: "创建并监控运单",
SD_title: "运单",
};
export const titleTexts = new LocalizedStrings({ ...cnLanguageCodes.reduce((prev, curr) => {
prev[curr] = { ...cnTexts };
return prev;
}, {}),
});
Some off-topic information. "Hant" is for Traditional Chinese (TC) and "Hans" is for Simplified Chinese (SC). People in China(CN) don't use Hant. If you are providing app for both TC and SC, better to provide separate translation.
Another solution:
const cnLanguageCodes = [ "zh-Hans-CN", "zh-Hant-CN", "zh-HK-CN", "zh-Hans", "zh-Hant", "zh-HK", "zh", ] const cnTexts = { title: "运单", subtitle: "创建并监控运单", SD_title: "运单", }; export const titleTexts = new LocalizedStrings({ ...cnLanguageCodes.reduce((prev, curr) => (prev[curr] = cnTexts), {}), });
Actually, it is not correct.
Should be
export const titleTexts = new LocalizedStrings({ ... cnLanguageCodes.reduce((prev, curr) => { prev[curr] = cnStrings; return prev; }, {}), });
Another solution:
const cnLanguageCodes = [ "zh-Hans-CN", "zh-Hant-CN", "zh-HK-CN", "zh-Hans", "zh-Hant", "zh-HK", "zh", ] const cnTexts = { title: "运单", subtitle: "创建并监控运单", SD_title: "运单", }; export const titleTexts = new LocalizedStrings({ ...cnLanguageCodes.reduce((prev, curr) => (prev[curr] = cnTexts), {}), });Actually, it is not correct. Should be
export const titleTexts = new LocalizedStrings({ ... cnLanguageCodes.reduce((prev, curr) => { prev[curr] = cnStrings; return prev; }, {}), });
@SwiftyWang It's the same thing. Mine just does an assignment and return in the same line (admittedly less readable).
Another solution:
const cnLanguageCodes = [ "zh-Hans-CN", "zh-Hant-CN", "zh-HK-CN", "zh-Hans", "zh-Hant", "zh-HK", "zh", ] const cnTexts = { title: "运单", subtitle: "创建并监控运单", SD_title: "运单", }; export const titleTexts = new LocalizedStrings({ ...cnLanguageCodes.reduce((prev, curr) => (prev[curr] = cnTexts), {}), });Actually, it is not correct. Should be
export const titleTexts = new LocalizedStrings({ ... cnLanguageCodes.reduce((prev, curr) => { prev[curr] = cnStrings; return prev; }, {}), });@SwiftyWang It's the same thing. Mine just does an assignment and return in the same line (admittedly less readable).
It is different, yours inside reduce block will return prev[curr] that will cause recursive issue. Mine is returning prev.
@SwiftyWang 👍🏼 You're correct, my mistake, though.. I'm still confused as to why it's working for me in current apps as-is.
@SwiftyWang 👍🏼 You're correct, my mistake, though.. I'm still confused as to why it's working for me in current apps as-is.
If the string data is large at least will cause memory issue I think. I am not a javascript developer, in Java may cause stackoverflow. Anyway, it is a good idea to solve the problem using reduce.