[TIMOB-23296] Windows: Implement Ti.Locale.setLanguage
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-06-14T19:08:21.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.0.0 |
Components | Windows |
Labels | n/a |
Reporter | Jonas Bjurhult |
Assignee | Kota Iguchi |
Created | 2016-04-20T07:12:35.000+0000 |
Updated | 2016-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>
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.3. Build and run the app. 4.On Android following console log is produced.
But on Windows Phone the app fails to run and following error log is produced.
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
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
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
[~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.
Thank you for the update!
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.
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()
The L() macro will give the same result no matter what language is set in setLanguage()
https://github.com/appcelerator/titanium_mobile_windows/pull/737
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