开发者

Titanium Mobile: set locale (language) in app

I don't quite get how the user locale is handled in Titanium Mobile. I have now set up two language files, and at least the English version is working fine. Now I would like to be able to set the locale within the app, so a user may change the language of the app.

How is开发者_开发百科 this done? And what is the best way to handle other locale issues such as currency, date formatting, etc.?

Thanks you for your answers! Cheers Chris


Use and external JS library like https://github.com/fnando/i18n-js to be able to force switch language within app. The library is already quite robust.

http://i18njs.com/


For changing the language of the app you can try this, as I am using same for the same purpose :-

I have added this in alloy.js

var language = Ti.App.Properties.getString('selectedLanguage','es');
Alloy.Globals.language = language;
Ti.Locale.setLanguage(language);

for changing the app language, I have created a tableView for selection on table's click listener I am changing the app language

if(e.index == 0){
    Alloy.Globals.language = 'es';
    Ti.App.Properties.setString('selectedLanguage','es');
}else{
    Alloy.Globals.language = 'en';
    Ti.App.Properties.setString('selectedLanguage','en');
}

and after all that I am refreshing my screen, in my function updateScreenForLanguage();

function updateScreenForLanguage(){
    $.Back.text = (L('Back'));
    $.Title.text = (L('Profile'));
    $.labelLanguagePreference.text = (L("Language_Preference"));    
}

hope this will help you. for more Titanium internationalization


You can use below modules

https://marketplace.appcelerator.com/listing?q=locale%20-#!/list/page/1/search=locale%20-

This modules helps you to follow same i18n folder string.xml and it will force the language only inside your app.


Titanium language locale can be use like this

var language = Titanium.Platform.locale;
Titanium.App.Properties.setString('locale',language);
Titanium.App.language = language;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜