ReactNativeLocalization icon indicating copy to clipboard operation
ReactNativeLocalization copied to clipboard

iOS is zh-Hans android is zh-CN

Open VesperHan opened this issue 7 years ago • 8 comments

'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 avatar May 15 '18 06:05 VesperHan

@VesperHan I think you can use Platform.os to check before start app then init the correct locale code.

kraisorns avatar Jul 25 '18 10:07 kraisorns

[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;
    }, {}),
});

wkoutre avatar Oct 30 '18 19:10 wkoutre

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.

ElvisChiang avatar Nov 22 '18 05:11 ElvisChiang

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 avatar May 06 '19 04:05 SwiftyWang

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).

wkoutre avatar May 06 '19 14:05 wkoutre

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 avatar May 07 '19 02:05 SwiftyWang

@SwiftyWang 👍🏼 You're correct, my mistake, though.. I'm still confused as to why it's working for me in current apps as-is.

wkoutre avatar May 07 '19 04:05 wkoutre

@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.

SwiftyWang avatar May 08 '19 01:05 SwiftyWang