Detect simplified or traditional Chinese (SOLVED)

I’m working on localizing my game into several different languages, among them Simplified Chinese and Traditional Chinese.

Using sys.get_sys_info() I can get the language, device language and territory. Regardless of whether my device is in simplified or traditional Chinese both sys.get_sys_info().language and sys.get_sys_info().device_language return simply "zh".

I can choose between them based on the current territory:

local info = sys.get_sys_info()
// ... other languages
elseif info.device_language == "zh" then
	if info.territory == "TW" or info.territory == "HK" then
		// Traditional Chinese
	else
		// Simplified Chinese
	end
end

But then if I’m outside of Taiwan or Hong Kong, even if my device is set to Traditional Chinese the app will default to Simplified Chinese; conversely if I’m in Taiwan or Hong Kong and my device is set to Simplified Chinese it will default to Traditional Chinese.

Is there no way to differentiate between the two? I was expecting to be able to get a language code such as “zh-CN”, “zh-TW” or “zh-HK” based solely on the device’s settings, not it’s location.

2 Likes

If I remember correctly this is what the combination of language and territory is.

On Android it comes from java.util.Locale.getLanguage() combined with java.util.Locale.getCountry() and on iOS it comes from NSLocale.currentLocale.localeIdentifier. There’s a bit of logic in the code that splits up and extracts the values for sys.get_sys_info() but I believe it should be correct on all platforms (at least according to the localisation team at King).

How are you testing this and on what devices?

3 Likes

Ahhh, of course! I just misunderstood what ‘territory’ meant and stupidly only tested it in my language (so of course I got my country code and thought it was based on location not language). I’ve just checked and yes the territory changes to TW or HK or CN based on the variant of Chinese I select. Thanks!

5 Likes

I don’t want to create a new topic, but not sure where to write it.
I decided to add it here, maybe it will help somebody to save time.

I just found that Indonesian language code on Android is in, I checked ISO-639 and everywhere I see ind or id, but after investigations and tests I found that real code is in.
I hope it will be useful for somebody.

2 Likes