Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23296] Windows: Implement Ti.Locale.setLanguage

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-06-14T19:08:21.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsWindows
Labelsn/a
ReporterJonas Bjurhult
AssigneeKota Iguchi
Created2016-04-20T07:12:35.000+0000
Updated2016-10-13T16:17:23.000+0000

Description

Both iOS and Android supports Ti.Locale.setLanguage, however the function is not documented. Is it supposed to be supported or is it deprecated? *Test code*
var win = Ti.UI.createWindow({ backgroundColor: 'green' });
win.addEventListener('open', function () {
    Ti.Locale.setLanguage('en');
    Ti.API.info('current language is: ' + Ti.Locale.getCurrentLanguage());
    Ti.API.info('before change ' + L('this is my key'));
    Ti.Locale.setLanguage('en-GB');
    Ti.API.info('new language is: ' + Ti.Locale.getCurrentLanguage());
    Ti.API.info('after change ' + L('this is my key'));
});
win.open();
<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="this is my key">this is my value</string>
</resources>
<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <string name="this is my key">this is my en-GB value</string>
</resources>

Comments

  1. Sharif AbuDarda 2016-04-22

  2. Nazmus Salahin 2016-04-26

    Hello, I have found that Ti.Locale.setLanguage works on Android but not on Windows Phone. *Steps:* 1. Create a default classic project. 2. Replace app.js code with following.
       
       var win1 = Titanium.UI.createWindow({  
           title:'Tab 1',
           backgroundColor:'#fff'
       });
       
       
       win1.open();
       
       var lan=Ti.Locale.getCurrentLanguage();
       Ti.API.log("Initial Language: "+lan);
       Ti.Locale.setLanguage("fr");
       lan=Ti.Locale.getCurrentLanguage();
       Ti.API.log("Language Changed To: "+lan);
       
    3. Build and run the app. 4.On Android following console log is produced.
       [INFO] :   Initial Language: en
       [INFO] :   Language Changed To: fr
       
    But on Windows Phone the app fails to run and following error log is produced.
       [ERROR] :  Application Error: {
       [ERROR] :    "line": 2,
       [ERROR] :    "column": 10,
       [ERROR] :    "message": "Error while require(/app) invalid vector<T> subscript",
       [ERROR] :    "native_stack": [
       [ERROR] :      "JSExportClass<class Titanium::GlobalObject>::CallNamedFunction"
       [ERROR] :    ]
       [ERROR] :  }
       
    Thanks *Environment*: *Device info:* Nexus7 (android 6.0.1) , Microsoft Lumia 640 (Windows Phone 8.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.2.2.GA and 5.2.1.GA *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.2 *Appcelerator Studio:* 4.5.0
  3. Jörgen Buder 2016-04-26

    Hi [~sdarda], I am not sure what is happening with this ticket, being able to override the language that is possible in Android and iOS is NOT possible in Windows, the Windows SDK Parity list in the highly build says that the setLanguage is indeed supported, so this is a bugg in the Windows SDK and not a new feature request. The reference Ticket you are mentioning is way too old and before Win was supported. Can you please escalate this as the Win 5.3.0 GA is coming up and you may want to fix all bugs related to this... Regards
  4. Christopher Williams 2016-05-02

    According to our own docs (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Locale), the country/currency/language properties are read-only and there are no set methods. But yes, after looking at the source for iOS and Android we do in fact support Ti.Locale.setLanguage. We need to support this on Windows as well. https://github.com/appcelerator/titanium_mobile/blob/415bd6c66dcc55b1a59a59574f3babd3c3a84ede/android/modules/locale/src/java/ti/modules/titanium/locale/LocaleModule.java#L90 https://github.com/appcelerator/titanium_mobile/blob/415bd6c66dcc55b1a59a59574f3babd3c3a84ede/iphone/Classes/LocaleModule.m#L68
  5. Christopher Williams 2016-05-02

    [~jonasbjurhult] So this looks like a combination of a few things! First, our docs don't list the method, so I opened a ticket to add it to our docs. Second, because it wasn't in our docs we missed it when implementing Ti.Locale on Windows, so this ticket is now about tracking adding support for it. Third, I'm guessing there may actually be a bug that [~nsalahin] found as well in Ti.Locale.getCurrentLanguage(). I'll clone off another ticket to track that.
  6. Jonas Bjurhult 2016-05-02

    Thank you for the update!
  7. Christopher Williams 2016-05-05

    So looks like we should: - accept a single string argument, which may be something like "en" or "en-US". - Set Ti.Locale.currentLocale to the the value (if it's a valid locale) - tell the "system" to use that locale - not really sure how we programmatically change the app/system locale on Windows right now, we'll have to look. See http://stackoverflow.com/questions/20883627/localization-on-the-fly-in-winrt-app and scenario 8 of https://code.msdn.microsoft.com/windowsapps/Application-resources-and-cd0c6eaa Looks like it boils down to using the Windows::Globalization::ApplicationLanguages::PrimaryLanguageOverride property.
  8. Jonas Bjurhult 2016-06-01

    I just tried setLanguage() using the latest nightly and the function itself works, but there is a problem remaining. The macro L() or Ti.locale.getString() is not affected byt the value set in Ti.Locale.setCurrentLanguage()
       Ti.Locale.setLanguage('en');
       Ti.API.info('current language is: ' + Ti.Locale.getCurrentLanguage());
       Ti.API.info('before change ' + L('test'));
       Ti.Locale.setLanguage('sv');
       Ti.API.info('new language is: ' + Ti.Locale.getCurrentLanguage());
       Ti.API.info('after change ' + L('test'));
       
    The L() macro will give the same result no matter what language is set in setLanguage()
  9. Kota Iguchi 2016-06-08

    https://github.com/appcelerator/titanium_mobile_windows/pull/737
  10. Ewan Harris 2016-10-13

    Verified using: OS: Microsoft Windows 10 Pro 10.0.14393 Appc core: 6.0.0-58 Appc NPM: 4.2.8-7 Ti SDK: 6.0.0.v20161013072802 Appc Studio: 4.8.0.201610060953 An apps language can now be set using Ti.Locale.setLanguage. When implementing this into your application please take [this](https://msdn.microsoft.com/pl-pl/windows/uwp/globalizing/manage-language-and-region) documentation from Microsoft into account as setting a users language may differ from what is expected due to the platforms behaviour Closing ticket

JSON Source