Chinese Localization Problem

Hello,

I am trying to get some of my apps localized in various languages. Everything works fine on iOS and most languages work fine on Android except my app is crashing on just Android when either traditional or simplified Chinese is selected. Am I doing something wrong? Does Android use a different code besides zh-Hans and zh-Hant?

Thanks,
Scott [import]uid: 79834 topic_id: 34379 reply_id: 334379[/import]

I’m using zh-Hans in my apps on both Android and iOS with no problems.
I only localized to Simplified Chinese, so if I detect zh-Hant, I just switch my app to internally use the zh-Hans strings.
Not sure why your app is crashing though… [import]uid: 70847 topic_id: 34379 reply_id: 136654[/import]

Thanks for your reply! Do you load different images in your app? I determined why it was crashing, but still am unable to figure out how to distinguish between traditional and simplified on Android. Here is the code I am using in the main.lua:

function verifyTextLang()  
 if (\_G.language ~= "it") then   
 if (\_G.language ~= "es") then   
 if (\_G.language ~= "zh-Hans") then   
 if (\_G.language ~= "zh-Hant") then   
 --if (\_G.language ~= "zh") then   
 if (\_G.language ~= "ja") then   
 if (\_G.language ~= "ko") then   
 if (\_G.language ~= "fr") then   
 if (\_G.language ~= "ru") then   
 if (\_G.language ~= "de") then  
 \_G.language = "en";  
 end  
 end  
 end  
 --end  
 end  
 end  
 end  
 end  
 end  
 end  
 --foriegn asian fonts unneeded- if the specified font doesn't have the characters,  
 --it looks like it just grabs the native font.  
 end  
 verifyTextLang();  

The “if (_G.language ~= “zh”) then” line is what was causing the crash as I do not have images with just zh attached to it (using zh-Hans and zh-Hant) and the Android device was determining that _G.language == zh NOT zh-Hans or zh-Hant. After removing the above line, no more crashing, but it defaults to English for both simplified and traditional Chinese.

Any thoughts? [import]uid: 79834 topic_id: 34379 reply_id: 136655[/import]

I’ve coded my own localization module based on .po files that contain the translations. I can’t post the whole module, but I can briefly explain the concept.

First I have a table that defines which languages my app supports:

local languages =   
{  
 ["en"] = {"English", "English"},  
 ["fr"] = {"French", "Français"},  
 ["de"] = {"German", "Deutsch"},  
 ["zh-Hans"] = {"Chinese", "????"},  
 ["ja"] = {"Japanese", "???"},  
 ["ko"] = {"Korean", "???"},  
 ["es"] = {"Spanish", "Español"}  
}  
  
local languages\_mt =   
{  
 \_\_index = function(table, key)  
 return false; -- ignore all other languages   
 end  
}  
  
setmetatable(languages, languages\_mt);  

Then to determine the default language I have this function

local getDefaultLanguage = function()  
 local systemLang = system.getPreference("ui", "language");  
  
 if (not languages[systemLang]) then  
 if (systemLang == "zh-Hant") then  
 return "zh-Hans";  
 else  
 return "en";  
 end  
 else  
 return systemLang;  
 end  
end  

The user can of course choose whichever language supported which I store in my application settings.
When I start my app I just make a call to set the user’s preferred language, which loads the appropriate po file into memory.

localize.setLanguage(settings.language);  

.po files have the following layout (Simplified chinese sample)

#: later  
msgid "Later"  
msgstr "????"  
  
#: demo-mode  
msgid "Demo Mode"  
msgstr "????"  

#: is the tag used in the app to get the translation
msgid is the English term used by the translator
msgstr is the translated string [import]uid: 70847 topic_id: 34379 reply_id: 136657[/import]

Thanks everyone for your help! I determined the problem and the solution.

On Android devices when the language selected is either in Traditional or Simplified Chinese system.getPreference( “locale”, “language” ) only returns “zh” for both.

system.getPreference( “locale”, “identifier” ); however, will give you either “zh_TW” when set to traditional or “zh_CN” when set to simplified.

To solve this I simply edited this section of code:

if system.getPreference( "locale", "identifier" ) == "zh\_CN" then  
 \_G.language = "zh-Hans"  
elseif system.getPreference( "locale", "identifier" ) == "zh\_TW" then  
 \_G.language = "zh-Hant"  
else  
 \_G.language = system.getPreference( "locale", "language" );  
end  

[import]uid: 79834 topic_id: 34379 reply_id: 136713[/import]

Glad to hear that you got it working!

On a slight tangent, I would recommend using the user’s User Interface setting on the device to decide the initial language settings in your app instead of locale.

I’ve been a victim of this for the past 15 years living and working in different countries like Italy, Saudi Arabia and Korea. I always set the locale to the region I’m in as it affects things like relevant info on news-feeds and the like, but I prefer to have my user interface in english.
Many apps (both mobile and desktop) still set their initial interface language based on locale. Sure, I can change it later, but it’s a nuisance. A user’s locale doesn’t necessarily dictate the preferred language, however the user interface setting does.

It’s true that for the majority of people this isn’t an issue, but it’s nice to accommodate everybody :slight_smile:
[import]uid: 70847 topic_id: 34379 reply_id: 136726[/import]

I’m using zh-Hans in my apps on both Android and iOS with no problems.
I only localized to Simplified Chinese, so if I detect zh-Hant, I just switch my app to internally use the zh-Hans strings.
Not sure why your app is crashing though… [import]uid: 70847 topic_id: 34379 reply_id: 136654[/import]

Thanks for your reply! Do you load different images in your app? I determined why it was crashing, but still am unable to figure out how to distinguish between traditional and simplified on Android. Here is the code I am using in the main.lua:

function verifyTextLang()  
 if (\_G.language ~= "it") then   
 if (\_G.language ~= "es") then   
 if (\_G.language ~= "zh-Hans") then   
 if (\_G.language ~= "zh-Hant") then   
 --if (\_G.language ~= "zh") then   
 if (\_G.language ~= "ja") then   
 if (\_G.language ~= "ko") then   
 if (\_G.language ~= "fr") then   
 if (\_G.language ~= "ru") then   
 if (\_G.language ~= "de") then  
 \_G.language = "en";  
 end  
 end  
 end  
 --end  
 end  
 end  
 end  
 end  
 end  
 end  
 --foriegn asian fonts unneeded- if the specified font doesn't have the characters,  
 --it looks like it just grabs the native font.  
 end  
 verifyTextLang();  

The “if (_G.language ~= “zh”) then” line is what was causing the crash as I do not have images with just zh attached to it (using zh-Hans and zh-Hant) and the Android device was determining that _G.language == zh NOT zh-Hans or zh-Hant. After removing the above line, no more crashing, but it defaults to English for both simplified and traditional Chinese.

Any thoughts? [import]uid: 79834 topic_id: 34379 reply_id: 136655[/import]

I’ve coded my own localization module based on .po files that contain the translations. I can’t post the whole module, but I can briefly explain the concept.

First I have a table that defines which languages my app supports:

local languages =   
{  
 ["en"] = {"English", "English"},  
 ["fr"] = {"French", "Français"},  
 ["de"] = {"German", "Deutsch"},  
 ["zh-Hans"] = {"Chinese", "????"},  
 ["ja"] = {"Japanese", "???"},  
 ["ko"] = {"Korean", "???"},  
 ["es"] = {"Spanish", "Español"}  
}  
  
local languages\_mt =   
{  
 \_\_index = function(table, key)  
 return false; -- ignore all other languages   
 end  
}  
  
setmetatable(languages, languages\_mt);  

Then to determine the default language I have this function

local getDefaultLanguage = function()  
 local systemLang = system.getPreference("ui", "language");  
  
 if (not languages[systemLang]) then  
 if (systemLang == "zh-Hant") then  
 return "zh-Hans";  
 else  
 return "en";  
 end  
 else  
 return systemLang;  
 end  
end  

The user can of course choose whichever language supported which I store in my application settings.
When I start my app I just make a call to set the user’s preferred language, which loads the appropriate po file into memory.

localize.setLanguage(settings.language);  

.po files have the following layout (Simplified chinese sample)

#: later  
msgid "Later"  
msgstr "????"  
  
#: demo-mode  
msgid "Demo Mode"  
msgstr "????"  

#: is the tag used in the app to get the translation
msgid is the English term used by the translator
msgstr is the translated string [import]uid: 70847 topic_id: 34379 reply_id: 136657[/import]

Thanks everyone for your help! I determined the problem and the solution.

On Android devices when the language selected is either in Traditional or Simplified Chinese system.getPreference( “locale”, “language” ) only returns “zh” for both.

system.getPreference( “locale”, “identifier” ); however, will give you either “zh_TW” when set to traditional or “zh_CN” when set to simplified.

To solve this I simply edited this section of code:

if system.getPreference( "locale", "identifier" ) == "zh\_CN" then  
 \_G.language = "zh-Hans"  
elseif system.getPreference( "locale", "identifier" ) == "zh\_TW" then  
 \_G.language = "zh-Hant"  
else  
 \_G.language = system.getPreference( "locale", "language" );  
end  

[import]uid: 79834 topic_id: 34379 reply_id: 136713[/import]

Glad to hear that you got it working!

On a slight tangent, I would recommend using the user’s User Interface setting on the device to decide the initial language settings in your app instead of locale.

I’ve been a victim of this for the past 15 years living and working in different countries like Italy, Saudi Arabia and Korea. I always set the locale to the region I’m in as it affects things like relevant info on news-feeds and the like, but I prefer to have my user interface in english.
Many apps (both mobile and desktop) still set their initial interface language based on locale. Sure, I can change it later, but it’s a nuisance. A user’s locale doesn’t necessarily dictate the preferred language, however the user interface setting does.

It’s true that for the majority of people this isn’t an issue, but it’s nice to accommodate everybody :slight_smile:
[import]uid: 70847 topic_id: 34379 reply_id: 136726[/import]