The behavior described below may be an SDK issue or a doc issue. The behavior is not consistent across platforms. The documentation is also misleading when you are dealing with iOS. I am setting it to the "iOS" component to start with.
Docs
The Blog (
http://developer.appcelerator.com/blog/2010/08/dealing-with-multiple-screens-and-multiple-languages.html ) says that you can use "en-US" as a folder for your strings.xml to refer to "United States English". For "British English" the code is "en-GB".
iOS
iOS 4.3 only provides two English language options "English" which returns "en" from Ti.Locale.currentLanguage, and "British English" which returns "en-GB"
If you have 2 i18n folders "en-GB" and "en-US", it will use the "en-GB" folder when you have the Language set to either "English" or "British English".
If you have 2 i18n folders "en-GB" and "en", it will use "en" when you have the Language set to "English" and "en-GB when you have the Language set to "British English".
Tested with:
TiSDK 1.7.2
iOS Simulator 4.3
Android
Android works as expected and uses the "en" or "en-US" folder when the Language is set to "English (United States)" as well as using the "en-GB" folder when Language is "English (United Kingdom)". Also, "en-US" is used when "English (United States)" is selected and the "en" folder is present (as expected).
Tested with:
TiSDK 1.7.2
Android Emulator 2.2
Repro Case
Note: to change the language in iOS go to Settings>General>International>Language
Step 1: attached is a file named "i18n.zip", unzip it and put it in the root of your project.
Step 2: copy the code below into your app.js
Step 3: launch the app
Step 4: if the language is set to "English", the label will show "EN GB" but it should show "EN US"
Step 5: change the language to "British English", the label will still show "EN GB".
Step 6: in the i18n folder change the name of your "en-US" folder to "en" and in the strings.xml file that is in that folder change the label of test from "EN US" to "EN"
Step 7: build and run your app again
Step 8: Now, if the language is set to "English", the label will show "EN" as it should
Step 9: change the language to "British English", the label will show "EN GB" as it should
var win = Ti.UI.createWindow({
backgroundColor: 'blue'
});
var label = Ti.UI.createLabel({
text: L('test'),
top: 20,
width: 300,
height: 40
});
label.addEventListener('click', function(e){
Ti.API.info("Ti.Locale.currentCountry: " + Ti.Locale.currentCountry);
Ti.API.info("Ti.Locale.currentLanguage: " + Ti.Locale.currentLanguage);
Ti.API.info("Ti.Locale.currentLocale: " + Ti.Locale.currentLocale);
});
win.add(label);
win.open();
Workaround
Use the folder name "en" instead of "en-US" and it will work as expected.
Associated Helpdesk Ticket
http://appc.me/c/APP-225593
Any news on when this may be tackled? I have an immediate need for this functionality. Thanks, James (the person who originally reported this to Jon Alter)
Apple actually doesn't have any internalization based on dialect , it can only done based on Language, this can be read http://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/Articles/LanguageDesignations.html#//apple_ref/doc/uid/20002144-SW3 The fact that there exist en-GB & en is because apple treats this as a different Language (English and British English)and it can be seen that there is no en-US/en-AU/etc.... The entire list of Languages supported are en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi Otherwise: English , British English (UK), French (France), German, Traditional Chinese, Simplified Chinese, Dutch, Italian, Spanish, Portuguese (Brazil), Portuguese (Portugal), Danish, Swedish, Finnish, Norwegian, Korean, Japanese, Russian, Polish, Turkish, Ukrainian, Hungarian, Arabic, Thai, Czech, Greek, Hebrew, Indonesian, Malay, Romanian, Slovak, Croatian, Catalan, and Vietnamese
Closing ticket as invalid with reference to the above comments.