forked from tidev/titanium-sdk
/
Locale.yml
274 lines (248 loc) Β· 11.6 KB
/
Locale.yml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
---
name: Titanium.Locale
summary: The top level Locale module.
description: |
The `Locale` module works with localization files to which are generated during compilation
into the operating system specific localization formats. The `Locale` module provides
locale-specific strings which can be referenced at runtime. Additionally, the module
contains a few methods and properties for querying device locale information.
The macro `L` can be used as an alias for the <Titanium.Locale.getString> method.
extends: Titanium.Module
since: "1.5"
methods:
- name: formatTelephoneNumber
summary: Formats a telephone number according to the current system locale.
platforms: [android]
returns:
type: String
parameters:
- name: number
summary: Phone number.
type: String
- name: getCurrencyCode
summary: Returns the ISO 3-letter currency code for the specified locale.
description: |
This method returns one of the ISO 4217 currency codes. For example,
`getCurrencyCode('en-US')` returns `USD`. See the `xe.com` website
[Currency List](http://www.xe.com/iso4217.php#section2) section of the `www.xe.com` website for
reference.
platforms: [android, iphone, ipad, macos]
returns:
type: String
parameters:
- name: locale
summary: |
Locale, as a combination of ISO 2-letter language and country codes. For example,
`en-US` or `en-GB`. See the
[ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
type: String
- name: getCurrencySymbol
summary: Returns the currency symbol for the specified currency code.
description: |
This method returns one of the international currency symbols. For example,
`getCurrencySymbol('USD')` returns `$`. See the
[Currency Symbols](http://www.xe.com/symbols.php#section2) section of the
`www.xe.com` website for reference.
platforms: [android, iphone, ipad, macos]
returns:
type: String
parameters:
- name: currencyCode
summary: |
Currency, as an ISO 3-letter code. For example, `USD` or `GBP`. See the
[Currency List](http://www.xe.com/iso4217.php#section2) section of the `www.xe.com` website for
reference.
type: String
- name: setLanguage
summary: Sets the current language of the application.
description: |
This property holds a value such as `en` or `fr`. See the
[ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) section of wikipedia for reference.
On Android you can also specify combination of a ISO 2-letter language and country codes. For example,
`en-US` or `en-GB`. See the [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
When changing to a language with a different layout direction, such as English to Arabic or vice-versa,
you will need to close and re-open the window in order to apply the new right-to-left setting.
platforms: [iphone, ipad, android, macos]
parameters:
- name: language
summary: The specified ISO 639-1 code.
type: String
- name: getLocaleCurrencySymbol
summary: Returns the currency symbol for the specified locale.
description: |
This method returns one of the international currency symbols. For example,
`getLocaleCurrencySymbol('en-US')` returns `$`. See the
[Currency Symbols](http://www.xe.com/symbols.php#section2) section of the
`www.xe.com` website for reference.
platforms: [android, iphone, ipad, macos]
returns:
type: String
parameters:
- name: locale
summary: |
Locale, as a combination of ISO 2-letter language and country codes. For example,
`en-US` or `en-GB`. See the
[ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
type: String
- name: getString
summary: |
Returns a string, localized according to the current system locale using the appropriate
`/i18n/LANG/strings.xml` localization file.
description: |
This method is functionaly identical to its alias <Global.L>. For example,
`Ti.Locale.getString('thisKey', 'missing key')` produces the same result as
`L('thisKey', 'missing key')`.
When using with <Global.String.format> to localize a phrase with multiple string
substitution placeholders, add the `formatted="false"` directive to the relevant
`strings.xml` element. See example for a demonstration.
returns:
type: String
parameters:
- name: key
summary: Key of string.
type: String
- name: hint
summary: Text to return if key does not exist in the localization file.
type: String
optional: true
examples:
- title: String Localization Demonstration
example: |
Localize two strings, "hello" and "goodbye" (using the keys "greeting" and "signoff")
for English and Spanish system locales.
Note: use the device's system settings to change locales and test this code.
#### `/i18n/en/strings.xml`
``` xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="phrase" formatted="false">You say %2$s and I say %1$s!</string>
<string name="greeting">hello</string>
<string name="signoff">goodbye</string>
</resources>
```
#### `/i18n/es/strings.xml`
``` xml
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="phrase" formatted="false">You say %2$s and I say %1$s!</string>
<string name="greeting">hola</string>
<string name="signoff">adios</string>
</resources>
```
#### `/Resources/app.js`
``` js
var i18nMissingMsg = '<no translation available>';
// for English locales, displays "You say goodbye and I say hello!"
// for Spanish locales, displays "You say adios and I say hola!"
Ti.API.info('You say ' + Ti.Locale.getString('signoff', i18nMissingMsg) + ' and I say ' + Ti.Locale.getString('greeting', i18nMissingMsg) + '!');
// uses alias L() instead of Ti.Locale.getString()
// formatted="false" is used in the strings.xml element for multiple string substitution
// for English locales, displays "You say goodbye and I say hello!"
// for Spanish locales, displays "You say adios and I say hola!"
Ti.API.info(String.format(L('phrase'), L('greeting', i18nMissingMsg), L('signoff', i18nMissingMsg)));
```
- name: parseDecimal
summary: Parses a number from the given string using the current or given locale.
platforms: [android, iphone, ipad, macos]
returns:
type: Number
summary: Returns the parsed number. Returns `NaN` (Not-a-Number) if given string is invalid.
parameters:
- name: text
summary: The string to be parsed.
type: String
- name: locale
summary: |
Locale, as a combination of ISO 2-letter language and country codes. For example,
`en-US` or `en-GB`. See the
[ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
type: String
optional: true
examples:
- title: Parsing Localized Numeric Strings
example: |
``` javascript
// You can convert to/from a localized numeric string like this.
var numericString = String.formatDecimal(1234.5);
var numericValue = Ti.Locale.parseDecimal(numericString);
// The numbers returned will be the same for the 2 different locales.
var number1 = Ti.Locale.parseDecimal('1,234,567.8', 'en-US');
var number2 = Ti.Locale.parseDecimal('1.234.567,8', 'de-DE');
```
events:
- name: change
summary: Fired when the device locale changes.
description: |
On Android, when a listener for this event is not present, by default the application will soft restart
upon a locale change. Once a listener for this event is present, the behaviour for a locale change is developer
defined.
since: "7.5.0"
properties:
- name: currentCountry
summary: Country of the current system locale, as an ISO 2-letter code.
description: |
This property holds a value such as `US` or `GB`. See the
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
country codes section of wikipedia for reference.
platforms: [android, iphone, ipad, macos]
type: String
permission: read-only
- name: applicationLocale
summary: Set the UI locale for the app.
description: |
Set the UI current active locale for the app.
When changed, it automatically causes the activity to be restarted.
platforms: [android]
since: "12.4.0"
type: String
examples:
- title: Setting the UI locale of the app
example: |
``` javascript
// This sets the application UI locale.
Ti.Locale.applicationLocale = 'en-US';
// or
Ti.Locale.applicationLocale = 'de';
```
- name: applicationLocales
permission: read-only
summary: Gets the UI locales for the app.
description: |
Returns an array of objects with the current app UI locales.
Note: This is only available on Android 33 and up.
platforms: [android]
since: "12.4.0"
type: Array
examples:
- title: Getting UI locale(s) of the app
example: |
``` javascript
// This returns an array of objects for each locale defined for the application's UI.
let appLocales = Ti.Locale.applicationLocales;
console.log(appLocales[0].language)
console.log(appLocales);
```
- name: currentLanguage
summary: Language of the current system locale, as an ISO 2-letter code.
description: |
This property holds a value such as `en` or `fr`. See the
[ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) section of wikipedia for reference.
type: String
permission: read-only
- name: currentLocale
summary: Current system locale, as a combination of ISO 2-letter language and country codes.
description: |
This property holds a value such as `en-US` or `en-GB`.
See the [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) and
[ISO 3166-1 alpha-2](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements)
sections of wikipedia for reference.
type: String
permission: read-only