[TIMOB-2401] iOS: Several localization enhancements
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:59:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.6.0 M02 |
Components | iOS |
Labels | feature, ios, iphone, release-1.6.0 |
Reporter | Bill Dawson |
Assignee | Stephen Tramer |
Created | 2011-04-15T03:18:43.000+0000 |
Updated | 2011-04-17T01:59:00.000+0000 |
Description
See #1870 for the initial, Android implementation directives from our customer.
Add to Ti.Locale:
getCurrentLanguage()
- returns language string such
as "en".
getCurrentCountry()
- returns "US" for example.
getCurrentLocale()
- returns "en-US" for
example.
getCurrencyCode(locale_string)
- e.g., pass "en-US"
and it will return "USD"
getCurrencySymbol(currency_code)
- e.g., pass "USD"
and it will return "$"
getLocaleCurrencySymbol(locale_string)
- e.g., pass
"en-US" and it will return "$"
Locale and format string support for
String.formatDecimal
:
String.formatDecimal(2.5)
- returns 2.5 formatted
in current locale. If a european locale, for example, will return
"2,5".
String.formatDecimal(2.5, "000.000")
- e.g.,
returns "002.500" if current locale is en_US, or "002,500" if
current locale is de_AT.
String.formatDecimal(2.5, 'de-AT')
- returns
"2,5"
String.formatDecimal(2.5, 'de-AT', '000.0000')
-
returns "002,50000"
You can exercise these with this simple program (app.js):
/*global Ti, Titanium, alert, JSON */
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
title:'Test',
backgroundColor:'#fff',
fullscreen: true,
exitOnClose: true
});
var rows = [];
function makeRow(title) {
rows.push(Ti.UI.createTableViewRow({title: title}));
}
var statements =
['Ti.Locale.getCurrentLanguage()',
'Ti.Locale.getCurrentCountry()',
'Ti.Locale.getCurrentLocale()',
'Ti.Locale.getCurrencyCode(Ti.Locale.getCurrentLocale())',
'Ti.Locale.getCurrencyCode("en-GB")',
'Ti.Locale.getCurrencyCode("-GB")',
'Ti.Locale.getCurrencySymbol("EUR")',
'Ti.Locale.getCurrencySymbol("GBP")',
'Ti.Locale.getLocaleCurrencySymbol("en-US")',
'String.formatDecimal(2.5)',
'String.formatDecimal(2.5, "000.00")',
'String.formatDecimal(2.5, "de-DE")',
'String.formatDecimal(2.5, "de-DE", "000.00")'
];
for (var i = 0; i < statements.length; i++) {
makeRow(statements[i] + " = " + eval(statements[i]));
}
win.add(Ti.UI.createTableView({data:rows}));
win.open();
NOTE: I put a locale.js test suite into the drillbit/tests folder. It's okay that it won't pass for iOS (based on Ralf's comment in his e-mail, namely all tests must pass except "tests for features or bugs not scheduled for the next release. For example I don't want to slow down test creation.") Since we're not sure yet when this feature will be scheduled, this rule applies.
I decided to go ahead and do the api doc additions for the #1870 changes; I just know I'd never get around to it otherwise, and I didn't want you guys to have to do it. I marked them Android Only, so if you do get this into 1.5, be sure to just open apidoc/Titanium/Locale/Locale.tdoc and search for 'Android' and take out those comments.
(from [5d84d4aaa3503788da996a4f7846f60c31255f28]) [#2401 state:fixed-in-qa] Localization enhancements for iOS. https://github.com/appcelerator/titanium_mobile/commit/5d84d4aaa3503788da996a4f7846f60c31255f28"> https://github.com/appcelerator/titanium_mobile/commit/5d84d4aaa350...
[INFO] Titanium SDK version: 1.6.0 (01/12/11 09:38 db09d1e) 4GT ipod touch, 3G iphone 3.1.3. English and Spanish checked for langs, and usa and japan checked for locale. moved test to QATests