/
Locale.js
81 lines (62 loc) 路 2.22 KB
/
Locale.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
define(["require", "Ti/_/lang", "Ti/_/Evented", "Ti/API"], function(require, lang, Evented, API) {
var locale = lang.val(navigator.language,navigator.browserLanguage).replace(/^([^\-\_]+)[\-\_](.+)?$/, function(o, l, c){ return l.toLowerCase() + (c && "-" + c.toUpperCase()); }),
languageParts = locale.split("-"),
language = languageParts[0];
strings = {},
cfg = require.config,
app = cfg.app;
document.title = app.name = app.names[language] || app.name;
try {
~cfg.locales.indexOf(language) && (strings = require("./Locale/" + language + "/i18n"));
} catch (e) {}
function getString(key, hint) {
return strings[key] || hint || key || "";
}
Object.defineProperty(window, "L", { value: getString, enumarable: true });
// format a date into a locale specific date format. Optionally pass a second argument (string) as either "short" (default), "medium" or "long" for controlling the date format.
String.formatDate = function(dt, fmt) {
API.debug('Method "String.formatDate" is not implemented yet.');
return dt.toString();
};
// format a date into a locale specific time format.
String.formatTime = function(dt) {
API.debug('Method "String.formatTime" is not implemented yet.');
return dt.toString();
};
// format a number into a locale specific currency format.
String.formatCurrency = function(amt) {
API.debug('Method "String.formatCurrency" is not implemented yet.');
return amt;
};
// format a number into a locale specific decimal format.
String.formatDecimal = function(dec) {
API.debug('Method "String.formatDecimal" is not implemented yet.');
return dec;
};
return lang.setObject("Ti.Locale", Evented, {
constants: {
currentCountry: languageParts[1] || "",
currentLanguage: languageParts[0] || "",
currentLocale: locale
},
formatTelephoneNumber: function(s) {
return s;
},
getCurrencyCode: function(locale) {
// locale = "en-US" => "USD"
return "";
},
getCurrencySymbol: function(currencyCode) {
// currencyCode = "en-US" => "$"
return "";
},
getLocaleCurrencySymbol: function(locale) {
// locale = "en-US" => "$"
return "";
},
getString: getString,
_getString: function(key, hint) {
return lang.val(hint, getString(key, hint));
}
});
});