Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

How to set Titanium.Platform.locale

If I set -

Titanium.Platform.locale = 'ja'

it is not getting updated.

\project-name\i18n\en\strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="m1">ENG-111</string>
  <string name="m2">ENG-222</string>
</resources>

\project-name\i18n\ja\strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="m1">JA-111</string>
  <string name="m2">JA-222</string>
</resources>

app.js

Ti.API.info('Titanium.Platform.locale : ' + Titanium.Platform.locale);

Titanium.Platform.locale = 'ja';
Ti.API.info('currentLanguage : ' + Ti.Locale.currentLanguage + '. ~~But I expect ja here' );
Ti.API.info('Localized string m1 : '+L("m1") + '. ~~But I expect JA-111 here' );

Results:

Titanium.Platform.locale : en-US
currentLanguage : en. ~~But I expect ja here
Localized string m1 : ENG-111. ~~But I expect JA-111 here
— asked May 17th 2011 by Rajeswari Sathyaseelan
  • android
0 Comments

2 Answers

  • Rajeswari

    From what I understand, the user sets their required locale via the device's system config applet, and the Titanium.Platform.locale property simply returns that value. I am not sure it makes much sense for the developer to make this choice for the user.

    Having said that, I will confirm that this is true because, if so, the apidocs need to be updated to reflect the property's read-only nature.

    Cheers

    — answered May 17th 2011 by Paul Dowsett
    permalink
    5 Comments
    • Thanks for the reply.

      I am developing an application with localization support. So I want to test the app with different languages and different timezones.

      If I change the time zone offset in my machine, the same time zone reflects in my emulator. That helps me to test it with diff time zones.

      But in the emulator, I am not able to change the language. It is read only. There should be some provision (like in .net I can set the culture, and test the same app with diff languages)

      Only to test with diff language, do I need to have diff machine with diff languages? I dont think that is the ideal way.

      — commented May 31st 2011 by Rajeswari Sathyaseelan
    • Hi,

      It DOES make sense for the developer to be able to do this…

      I have an app in english and spanish which allows the user to set the language in the apps own settings page… this affects the the content i get from the internal database, but all button controls etc are coming from an i18n strings set up.. I cannot use the string files for all the content as there is about 400 records that are in both english and spanish….

      This means that the app can be set to English but be showing labels in spanish..

      Is the locale setting read only?

      Thanks

      Jez

      — commented June 11th 2011 by Jez Manser
    • I DID NOT mean to change the locale PROGRAMMATICALLY IN CODE. But my question was how to change the locale using emulator settings or some config file.

      I have found the solution - http://stackoverflow.com/questions/5755460/how-to-change-the-default-language-of-android-emulator

      Thanks

      — commented June 16th 2011 by Rajeswari Sathyaseelan
    • Rajeswari

      If you have an alias configured for titanium.py, or have it in your system path, you can run the following commands from the project root:

      adb -e shell "setprop persist.sys.language <languageCode>;setprop persist.sys.country <countryCode>;stop;sleep 5;start"
      titanium.py run --platform=android
      

      Hope it helps

      — commented June 16th 2011 by Paul Dowsett
    • THANKS VERY MUCH. This is what I was expecting. Thanks once again!

      — commented June 17th 2011 by Rajeswari Sathyaseelan
  • To change the Android emulator languge – "Open menu=>Setting=>Language& Keyboard=>Select Language"

    http://stackoverflow.com/questions/5755460/how-to-change-the-default-language-of-android-emulator

    — answered June 16th 2011 by Rajeswari Sathyaseelan
    permalink
    3 Comments
    • Rajeswari

      That's what I meant when I said, "From what I understand, the user sets their required locale via the device's system config applet".

      Sorry if that was not clear.

      I'm glad you got it sorted.

      — commented June 16th 2011 by Paul Dowsett
    • Thanks,
      I agreed with –"From what I understand, the user sets their required locale via the device's system config applet".

      But I didnt agree with – "I am not sure it makes much sense for the developer to make this choice for the user.", since I asked this question to test the app with different locale, NOT to make this choice for the user.

      — commented June 16th 2011 by Rajeswari Sathyaseelan
    • I apologize if my question was not clear. ( I wanted to set the Locale somewhere, which should give different results based on the Locale set, but without making any change in the source code, and without creating a machine with diff language. May be in a similar way, how we set culture in .net)

      — commented June 17th 2011 by Rajeswari Sathyaseelan
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.