@capawesome/capacitor-localization 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorLocalization.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +193 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/Localization.java +108 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/LocalizationPlugin.java +85 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/classes/results/GetLocalesResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/classes/results/GetSettingsResult.java +31 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/classes/results/LocaleResult.java +75 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/localization/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +333 -0
- package/dist/esm/definitions.d.ts +157 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +75 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +89 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +92 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Results/GetLocalesResult.swift +17 -0
- package/ios/Plugin/Classes/Results/GetSettingsResult.swift +22 -0
- package/ios/Plugin/Classes/Results/LocaleResult.swift +50 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Localization.swift +92 -0
- package/ios/Plugin/LocalizationPlugin.swift +53 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +91 -0
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "LocalizationPlugin",
|
|
4
|
+
"slug": "localizationplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "getLocales",
|
|
10
|
+
"signature": "() => Promise<GetLocalesResult>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<GetLocalesResult>",
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "since",
|
|
16
|
+
"text": "0.1.0"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"docs": "Get the user's preferred locales, ordered by preference.\n\nThe first entry is the most preferred locale.",
|
|
20
|
+
"complexTypes": [
|
|
21
|
+
"GetLocalesResult"
|
|
22
|
+
],
|
|
23
|
+
"slug": "getlocales"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "getSettings",
|
|
27
|
+
"signature": "() => Promise<GetSettingsResult>",
|
|
28
|
+
"parameters": [],
|
|
29
|
+
"returns": "Promise<GetSettingsResult>",
|
|
30
|
+
"tags": [
|
|
31
|
+
{
|
|
32
|
+
"name": "since",
|
|
33
|
+
"text": "0.1.0"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"docs": "Get the user's regional formatting settings.",
|
|
37
|
+
"complexTypes": [
|
|
38
|
+
"GetSettingsResult"
|
|
39
|
+
],
|
|
40
|
+
"slug": "getsettings"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"properties": []
|
|
44
|
+
},
|
|
45
|
+
"interfaces": [
|
|
46
|
+
{
|
|
47
|
+
"name": "GetLocalesResult",
|
|
48
|
+
"slug": "getlocalesresult",
|
|
49
|
+
"docs": "",
|
|
50
|
+
"tags": [
|
|
51
|
+
{
|
|
52
|
+
"text": "0.1.0",
|
|
53
|
+
"name": "since"
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
"methods": [],
|
|
57
|
+
"properties": [
|
|
58
|
+
{
|
|
59
|
+
"name": "locales",
|
|
60
|
+
"tags": [
|
|
61
|
+
{
|
|
62
|
+
"text": "0.1.0",
|
|
63
|
+
"name": "since"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"docs": "The user's preferred locales, ordered by preference.\n\nThe first entry is the most preferred locale.",
|
|
67
|
+
"complexTypes": [
|
|
68
|
+
"Locale"
|
|
69
|
+
],
|
|
70
|
+
"type": "Locale[]"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"name": "Locale",
|
|
76
|
+
"slug": "locale",
|
|
77
|
+
"docs": "",
|
|
78
|
+
"tags": [
|
|
79
|
+
{
|
|
80
|
+
"text": "0.1.0",
|
|
81
|
+
"name": "since"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"methods": [],
|
|
85
|
+
"properties": [
|
|
86
|
+
{
|
|
87
|
+
"name": "currencyCode",
|
|
88
|
+
"tags": [
|
|
89
|
+
{
|
|
90
|
+
"text": "'EUR'",
|
|
91
|
+
"name": "example"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"text": "0.1.0",
|
|
95
|
+
"name": "since"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"docs": "The ISO 4217 currency code of the locale.\n\nReturns `null` if the currency cannot be determined.",
|
|
99
|
+
"complexTypes": [],
|
|
100
|
+
"type": "string | null"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
"name": "currencySymbol",
|
|
104
|
+
"tags": [
|
|
105
|
+
{
|
|
106
|
+
"text": "'€'",
|
|
107
|
+
"name": "example"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"text": "0.1.0",
|
|
111
|
+
"name": "since"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"docs": "The currency symbol of the locale.\n\nReturns `null` if the currency symbol cannot be determined.",
|
|
115
|
+
"complexTypes": [],
|
|
116
|
+
"type": "string | null"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "decimalSeparator",
|
|
120
|
+
"tags": [
|
|
121
|
+
{
|
|
122
|
+
"text": "','",
|
|
123
|
+
"name": "example"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"text": "0.1.0",
|
|
127
|
+
"name": "since"
|
|
128
|
+
}
|
|
129
|
+
],
|
|
130
|
+
"docs": "The character used to separate the integer part from the fractional part\nof a number.\n\nReturns `null` if the separator cannot be determined.",
|
|
131
|
+
"complexTypes": [],
|
|
132
|
+
"type": "string | null"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "groupingSeparator",
|
|
136
|
+
"tags": [
|
|
137
|
+
{
|
|
138
|
+
"text": "'.'",
|
|
139
|
+
"name": "example"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"text": "0.1.0",
|
|
143
|
+
"name": "since"
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"docs": "The character used to group digits of the integer part of a number.\n\nReturns `null` if the separator cannot be determined.",
|
|
147
|
+
"complexTypes": [],
|
|
148
|
+
"type": "string | null"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "languageCode",
|
|
152
|
+
"tags": [
|
|
153
|
+
{
|
|
154
|
+
"text": "'de'",
|
|
155
|
+
"name": "example"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"text": "0.1.0",
|
|
159
|
+
"name": "since"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"docs": "The ISO 639 language code of the locale.",
|
|
163
|
+
"complexTypes": [],
|
|
164
|
+
"type": "string"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "languageTag",
|
|
168
|
+
"tags": [
|
|
169
|
+
{
|
|
170
|
+
"text": "'de-DE'",
|
|
171
|
+
"name": "example"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"text": "0.1.0",
|
|
175
|
+
"name": "since"
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
"docs": "The BCP 47 language tag of the locale.",
|
|
179
|
+
"complexTypes": [],
|
|
180
|
+
"type": "string"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"name": "measurementSystem",
|
|
184
|
+
"tags": [
|
|
185
|
+
{
|
|
186
|
+
"text": "'metric'",
|
|
187
|
+
"name": "example"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"text": "0.1.0",
|
|
191
|
+
"name": "since"
|
|
192
|
+
}
|
|
193
|
+
],
|
|
194
|
+
"docs": "The measurement system used by the locale.\n\nReturns `null` if the measurement system cannot be determined.",
|
|
195
|
+
"complexTypes": [
|
|
196
|
+
"MeasurementSystem"
|
|
197
|
+
],
|
|
198
|
+
"type": "MeasurementSystem | null"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "regionCode",
|
|
202
|
+
"tags": [
|
|
203
|
+
{
|
|
204
|
+
"text": "'DE'",
|
|
205
|
+
"name": "example"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"text": "0.1.0",
|
|
209
|
+
"name": "since"
|
|
210
|
+
}
|
|
211
|
+
],
|
|
212
|
+
"docs": "The ISO 3166 region code of the locale.\n\nReturns `null` if the region cannot be determined.",
|
|
213
|
+
"complexTypes": [],
|
|
214
|
+
"type": "string | null"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "textDirection",
|
|
218
|
+
"tags": [
|
|
219
|
+
{
|
|
220
|
+
"text": "'ltr'",
|
|
221
|
+
"name": "example"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"text": "0.1.0",
|
|
225
|
+
"name": "since"
|
|
226
|
+
}
|
|
227
|
+
],
|
|
228
|
+
"docs": "The writing direction of the locale's language.",
|
|
229
|
+
"complexTypes": [
|
|
230
|
+
"TextDirection"
|
|
231
|
+
],
|
|
232
|
+
"type": "TextDirection"
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "GetSettingsResult",
|
|
238
|
+
"slug": "getsettingsresult",
|
|
239
|
+
"docs": "",
|
|
240
|
+
"tags": [
|
|
241
|
+
{
|
|
242
|
+
"text": "0.1.0",
|
|
243
|
+
"name": "since"
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
"methods": [],
|
|
247
|
+
"properties": [
|
|
248
|
+
{
|
|
249
|
+
"name": "firstDayOfWeek",
|
|
250
|
+
"tags": [
|
|
251
|
+
{
|
|
252
|
+
"text": "1",
|
|
253
|
+
"name": "example"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"text": "0.1.0",
|
|
257
|
+
"name": "since"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
"docs": "The first day of the week as configured by the user.\n\nThe value follows the ISO 8601 convention where `1` is Monday and `7` is\nSunday.",
|
|
261
|
+
"complexTypes": [],
|
|
262
|
+
"type": "number"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"name": "timeZone",
|
|
266
|
+
"tags": [
|
|
267
|
+
{
|
|
268
|
+
"text": "'Europe/Berlin'",
|
|
269
|
+
"name": "example"
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"text": "0.1.0",
|
|
273
|
+
"name": "since"
|
|
274
|
+
}
|
|
275
|
+
],
|
|
276
|
+
"docs": "The identifier of the user's current time zone.",
|
|
277
|
+
"complexTypes": [],
|
|
278
|
+
"type": "string"
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
"name": "uses24HourClock",
|
|
282
|
+
"tags": [
|
|
283
|
+
{
|
|
284
|
+
"text": "0.1.0",
|
|
285
|
+
"name": "since"
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
"docs": "Whether the user prefers a 24-hour clock over a 12-hour clock.",
|
|
289
|
+
"complexTypes": [],
|
|
290
|
+
"type": "boolean"
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
],
|
|
295
|
+
"enums": [],
|
|
296
|
+
"typeAliases": [
|
|
297
|
+
{
|
|
298
|
+
"name": "MeasurementSystem",
|
|
299
|
+
"slug": "measurementsystem",
|
|
300
|
+
"docs": "The measurement system used by a locale.\n\n- `metric`: The metric system (e.g. meters, kilograms).\n- `us`: The United States customary system (e.g. feet, pounds).\n- `uk`: The United Kingdom imperial system.",
|
|
301
|
+
"types": [
|
|
302
|
+
{
|
|
303
|
+
"text": "'metric'",
|
|
304
|
+
"complexTypes": []
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"text": "'us'",
|
|
308
|
+
"complexTypes": []
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"text": "'uk'",
|
|
312
|
+
"complexTypes": []
|
|
313
|
+
}
|
|
314
|
+
]
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"name": "TextDirection",
|
|
318
|
+
"slug": "textdirection",
|
|
319
|
+
"docs": "The writing direction of a language.\n\n- `ltr`: Left-to-right (e.g. English, German).\n- `rtl`: Right-to-left (e.g. Arabic, Hebrew).",
|
|
320
|
+
"types": [
|
|
321
|
+
{
|
|
322
|
+
"text": "'ltr'",
|
|
323
|
+
"complexTypes": []
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"text": "'rtl'",
|
|
327
|
+
"complexTypes": []
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
"pluginConfigs": []
|
|
333
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
export interface LocalizationPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Get the user's preferred locales, ordered by preference.
|
|
4
|
+
*
|
|
5
|
+
* The first entry is the most preferred locale.
|
|
6
|
+
*
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
*/
|
|
9
|
+
getLocales(): Promise<GetLocalesResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the user's regional formatting settings.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.1.0
|
|
14
|
+
*/
|
|
15
|
+
getSettings(): Promise<GetSettingsResult>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @since 0.1.0
|
|
19
|
+
*/
|
|
20
|
+
export interface GetLocalesResult {
|
|
21
|
+
/**
|
|
22
|
+
* The user's preferred locales, ordered by preference.
|
|
23
|
+
*
|
|
24
|
+
* The first entry is the most preferred locale.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.1.0
|
|
27
|
+
*/
|
|
28
|
+
locales: Locale[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @since 0.1.0
|
|
32
|
+
*/
|
|
33
|
+
export interface GetSettingsResult {
|
|
34
|
+
/**
|
|
35
|
+
* The first day of the week as configured by the user.
|
|
36
|
+
*
|
|
37
|
+
* The value follows the ISO 8601 convention where `1` is Monday and `7` is
|
|
38
|
+
* Sunday.
|
|
39
|
+
*
|
|
40
|
+
* @example 1
|
|
41
|
+
* @since 0.1.0
|
|
42
|
+
*/
|
|
43
|
+
firstDayOfWeek: number;
|
|
44
|
+
/**
|
|
45
|
+
* The identifier of the user's current time zone.
|
|
46
|
+
*
|
|
47
|
+
* @example 'Europe/Berlin'
|
|
48
|
+
* @since 0.1.0
|
|
49
|
+
*/
|
|
50
|
+
timeZone: string;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the user prefers a 24-hour clock over a 12-hour clock.
|
|
53
|
+
*
|
|
54
|
+
* @since 0.1.0
|
|
55
|
+
*/
|
|
56
|
+
uses24HourClock: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @since 0.1.0
|
|
60
|
+
*/
|
|
61
|
+
export interface Locale {
|
|
62
|
+
/**
|
|
63
|
+
* The ISO 4217 currency code of the locale.
|
|
64
|
+
*
|
|
65
|
+
* Returns `null` if the currency cannot be determined.
|
|
66
|
+
*
|
|
67
|
+
* @example 'EUR'
|
|
68
|
+
* @since 0.1.0
|
|
69
|
+
*/
|
|
70
|
+
currencyCode: string | null;
|
|
71
|
+
/**
|
|
72
|
+
* The currency symbol of the locale.
|
|
73
|
+
*
|
|
74
|
+
* Returns `null` if the currency symbol cannot be determined.
|
|
75
|
+
*
|
|
76
|
+
* @example '€'
|
|
77
|
+
* @since 0.1.0
|
|
78
|
+
*/
|
|
79
|
+
currencySymbol: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* The character used to separate the integer part from the fractional part
|
|
82
|
+
* of a number.
|
|
83
|
+
*
|
|
84
|
+
* Returns `null` if the separator cannot be determined.
|
|
85
|
+
*
|
|
86
|
+
* @example ','
|
|
87
|
+
* @since 0.1.0
|
|
88
|
+
*/
|
|
89
|
+
decimalSeparator: string | null;
|
|
90
|
+
/**
|
|
91
|
+
* The character used to group digits of the integer part of a number.
|
|
92
|
+
*
|
|
93
|
+
* Returns `null` if the separator cannot be determined.
|
|
94
|
+
*
|
|
95
|
+
* @example '.'
|
|
96
|
+
* @since 0.1.0
|
|
97
|
+
*/
|
|
98
|
+
groupingSeparator: string | null;
|
|
99
|
+
/**
|
|
100
|
+
* The ISO 639 language code of the locale.
|
|
101
|
+
*
|
|
102
|
+
* @example 'de'
|
|
103
|
+
* @since 0.1.0
|
|
104
|
+
*/
|
|
105
|
+
languageCode: string;
|
|
106
|
+
/**
|
|
107
|
+
* The BCP 47 language tag of the locale.
|
|
108
|
+
*
|
|
109
|
+
* @example 'de-DE'
|
|
110
|
+
* @since 0.1.0
|
|
111
|
+
*/
|
|
112
|
+
languageTag: string;
|
|
113
|
+
/**
|
|
114
|
+
* The measurement system used by the locale.
|
|
115
|
+
*
|
|
116
|
+
* Returns `null` if the measurement system cannot be determined.
|
|
117
|
+
*
|
|
118
|
+
* @example 'metric'
|
|
119
|
+
* @since 0.1.0
|
|
120
|
+
*/
|
|
121
|
+
measurementSystem: MeasurementSystem | null;
|
|
122
|
+
/**
|
|
123
|
+
* The ISO 3166 region code of the locale.
|
|
124
|
+
*
|
|
125
|
+
* Returns `null` if the region cannot be determined.
|
|
126
|
+
*
|
|
127
|
+
* @example 'DE'
|
|
128
|
+
* @since 0.1.0
|
|
129
|
+
*/
|
|
130
|
+
regionCode: string | null;
|
|
131
|
+
/**
|
|
132
|
+
* The writing direction of the locale's language.
|
|
133
|
+
*
|
|
134
|
+
* @example 'ltr'
|
|
135
|
+
* @since 0.1.0
|
|
136
|
+
*/
|
|
137
|
+
textDirection: TextDirection;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The writing direction of a language.
|
|
141
|
+
*
|
|
142
|
+
* - `ltr`: Left-to-right (e.g. English, German).
|
|
143
|
+
* - `rtl`: Right-to-left (e.g. Arabic, Hebrew).
|
|
144
|
+
*
|
|
145
|
+
* @since 0.1.0
|
|
146
|
+
*/
|
|
147
|
+
export type TextDirection = 'ltr' | 'rtl';
|
|
148
|
+
/**
|
|
149
|
+
* The measurement system used by a locale.
|
|
150
|
+
*
|
|
151
|
+
* - `metric`: The metric system (e.g. meters, kilograms).
|
|
152
|
+
* - `us`: The United States customary system (e.g. feet, pounds).
|
|
153
|
+
* - `uk`: The United Kingdom imperial system.
|
|
154
|
+
*
|
|
155
|
+
* @since 0.1.0
|
|
156
|
+
*/
|
|
157
|
+
export type MeasurementSystem = 'metric' | 'us' | 'uk';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalizationPlugin {\n /**\n * Get the user's preferred locales, ordered by preference.\n *\n * The first entry is the most preferred locale.\n *\n * @since 0.1.0\n */\n getLocales(): Promise<GetLocalesResult>;\n /**\n * Get the user's regional formatting settings.\n *\n * @since 0.1.0\n */\n getSettings(): Promise<GetSettingsResult>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetLocalesResult {\n /**\n * The user's preferred locales, ordered by preference.\n *\n * The first entry is the most preferred locale.\n *\n * @since 0.1.0\n */\n locales: Locale[];\n}\n\n/**\n * @since 0.1.0\n */\nexport interface GetSettingsResult {\n /**\n * The first day of the week as configured by the user.\n *\n * The value follows the ISO 8601 convention where `1` is Monday and `7` is\n * Sunday.\n *\n * @example 1\n * @since 0.1.0\n */\n firstDayOfWeek: number;\n /**\n * The identifier of the user's current time zone.\n *\n * @example 'Europe/Berlin'\n * @since 0.1.0\n */\n timeZone: string;\n /**\n * Whether the user prefers a 24-hour clock over a 12-hour clock.\n *\n * @since 0.1.0\n */\n uses24HourClock: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface Locale {\n /**\n * The ISO 4217 currency code of the locale.\n *\n * Returns `null` if the currency cannot be determined.\n *\n * @example 'EUR'\n * @since 0.1.0\n */\n currencyCode: string | null;\n /**\n * The currency symbol of the locale.\n *\n * Returns `null` if the currency symbol cannot be determined.\n *\n * @example '€'\n * @since 0.1.0\n */\n currencySymbol: string | null;\n /**\n * The character used to separate the integer part from the fractional part\n * of a number.\n *\n * Returns `null` if the separator cannot be determined.\n *\n * @example ','\n * @since 0.1.0\n */\n decimalSeparator: string | null;\n /**\n * The character used to group digits of the integer part of a number.\n *\n * Returns `null` if the separator cannot be determined.\n *\n * @example '.'\n * @since 0.1.0\n */\n groupingSeparator: string | null;\n /**\n * The ISO 639 language code of the locale.\n *\n * @example 'de'\n * @since 0.1.0\n */\n languageCode: string;\n /**\n * The BCP 47 language tag of the locale.\n *\n * @example 'de-DE'\n * @since 0.1.0\n */\n languageTag: string;\n /**\n * The measurement system used by the locale.\n *\n * Returns `null` if the measurement system cannot be determined.\n *\n * @example 'metric'\n * @since 0.1.0\n */\n measurementSystem: MeasurementSystem | null;\n /**\n * The ISO 3166 region code of the locale.\n *\n * Returns `null` if the region cannot be determined.\n *\n * @example 'DE'\n * @since 0.1.0\n */\n regionCode: string | null;\n /**\n * The writing direction of the locale's language.\n *\n * @example 'ltr'\n * @since 0.1.0\n */\n textDirection: TextDirection;\n}\n\n/**\n * The writing direction of a language.\n *\n * - `ltr`: Left-to-right (e.g. English, German).\n * - `rtl`: Right-to-left (e.g. Arabic, Hebrew).\n *\n * @since 0.1.0\n */\nexport type TextDirection = 'ltr' | 'rtl';\n\n/**\n * The measurement system used by a locale.\n *\n * - `metric`: The metric system (e.g. meters, kilograms).\n * - `us`: The United States customary system (e.g. feet, pounds).\n * - `uk`: The United Kingdom imperial system.\n *\n * @since 0.1.0\n */\nexport type MeasurementSystem = 'metric' | 'us' | 'uk';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const Localization = registerPlugin('Localization', {
|
|
3
|
+
web: () => import('./web').then(m => new m.LocalizationWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { Localization };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { LocalizationPlugin } from './definitions';\n\nconst Localization = registerPlugin<LocalizationPlugin>('Localization', {\n web: () => import('./web').then(m => new m.LocalizationWeb()),\n});\n\nexport * from './definitions';\nexport { Localization };\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { GetLocalesResult, GetSettingsResult, LocalizationPlugin } from './definitions';
|
|
3
|
+
export declare class LocalizationWeb extends WebPlugin implements LocalizationPlugin {
|
|
4
|
+
private static readonly rtlLanguageCodes;
|
|
5
|
+
getLocales(): Promise<GetLocalesResult>;
|
|
6
|
+
getSettings(): Promise<GetSettingsResult>;
|
|
7
|
+
private createLocale;
|
|
8
|
+
private determineFirstDayOfWeek;
|
|
9
|
+
private determineSeparators;
|
|
10
|
+
private determineTextDirection;
|
|
11
|
+
private determineUses24HourClock;
|
|
12
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class LocalizationWeb extends WebPlugin {
|
|
3
|
+
async getLocales() {
|
|
4
|
+
const languageTags = navigator.languages && navigator.languages.length > 0
|
|
5
|
+
? navigator.languages
|
|
6
|
+
: [navigator.language];
|
|
7
|
+
const locales = languageTags.map(languageTag => this.createLocale(languageTag));
|
|
8
|
+
return { locales };
|
|
9
|
+
}
|
|
10
|
+
async getSettings() {
|
|
11
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
12
|
+
const uses24HourClock = this.determineUses24HourClock();
|
|
13
|
+
const firstDayOfWeek = this.determineFirstDayOfWeek(navigator.language);
|
|
14
|
+
return { timeZone, uses24HourClock, firstDayOfWeek };
|
|
15
|
+
}
|
|
16
|
+
createLocale(languageTag) {
|
|
17
|
+
var _a;
|
|
18
|
+
const locale = new Intl.Locale(languageTag);
|
|
19
|
+
const separators = this.determineSeparators(languageTag);
|
|
20
|
+
return {
|
|
21
|
+
languageTag,
|
|
22
|
+
languageCode: locale.language,
|
|
23
|
+
regionCode: (_a = locale.region) !== null && _a !== void 0 ? _a : null,
|
|
24
|
+
currencyCode: null,
|
|
25
|
+
currencySymbol: null,
|
|
26
|
+
decimalSeparator: separators.decimalSeparator,
|
|
27
|
+
groupingSeparator: separators.groupingSeparator,
|
|
28
|
+
textDirection: this.determineTextDirection(locale),
|
|
29
|
+
measurementSystem: null,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
determineFirstDayOfWeek(languageTag) {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
const locale = new Intl.Locale(languageTag);
|
|
35
|
+
const weekInfo = (_b = (_a = locale.getWeekInfo) === null || _a === void 0 ? void 0 : _a.call(locale)) !== null && _b !== void 0 ? _b : locale.weekInfo;
|
|
36
|
+
return (_c = weekInfo === null || weekInfo === void 0 ? void 0 : weekInfo.firstDay) !== null && _c !== void 0 ? _c : 1;
|
|
37
|
+
}
|
|
38
|
+
determineSeparators(languageTag) {
|
|
39
|
+
var _a, _b, _c, _d;
|
|
40
|
+
const parts = new Intl.NumberFormat(languageTag).formatToParts(1000000.1);
|
|
41
|
+
const decimalSeparator = (_b = (_a = parts.find(part => part.type === 'decimal')) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null;
|
|
42
|
+
const groupingSeparator = (_d = (_c = parts.find(part => part.type === 'group')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null;
|
|
43
|
+
return { decimalSeparator, groupingSeparator };
|
|
44
|
+
}
|
|
45
|
+
determineTextDirection(locale) {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const textInfo = (_b = (_a = locale.getTextInfo) === null || _a === void 0 ? void 0 : _a.call(locale)) !== null && _b !== void 0 ? _b : locale.textInfo;
|
|
48
|
+
if (textInfo) {
|
|
49
|
+
return textInfo.direction;
|
|
50
|
+
}
|
|
51
|
+
return LocalizationWeb.rtlLanguageCodes.includes(locale.language)
|
|
52
|
+
? 'rtl'
|
|
53
|
+
: 'ltr';
|
|
54
|
+
}
|
|
55
|
+
determineUses24HourClock() {
|
|
56
|
+
const resolvedOptions = Intl.DateTimeFormat(navigator.language, {
|
|
57
|
+
hour: 'numeric',
|
|
58
|
+
}).resolvedOptions();
|
|
59
|
+
const hourCycle = resolvedOptions.hourCycle;
|
|
60
|
+
return hourCycle === 'h23' || hourCycle === 'h24';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
LocalizationWeb.rtlLanguageCodes = [
|
|
64
|
+
'ar',
|
|
65
|
+
'ckb',
|
|
66
|
+
'dv',
|
|
67
|
+
'fa',
|
|
68
|
+
'he',
|
|
69
|
+
'ps',
|
|
70
|
+
'sd',
|
|
71
|
+
'ug',
|
|
72
|
+
'ur',
|
|
73
|
+
'yi',
|
|
74
|
+
];
|
|
75
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"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","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n GetLocalesResult,\n GetSettingsResult,\n Locale,\n LocalizationPlugin,\n TextDirection,\n} from './definitions';\n\ninterface LocaleTextInfo {\n direction: TextDirection;\n}\n\ninterface LocaleWeekInfo {\n firstDay: number;\n}\n\ninterface ExtendedLocale extends Intl.Locale {\n getTextInfo?: () => LocaleTextInfo;\n getWeekInfo?: () => LocaleWeekInfo;\n textInfo?: LocaleTextInfo;\n weekInfo?: LocaleWeekInfo;\n}\n\nexport class LocalizationWeb extends WebPlugin implements LocalizationPlugin {\n private static readonly rtlLanguageCodes = [\n 'ar',\n 'ckb',\n 'dv',\n 'fa',\n 'he',\n 'ps',\n 'sd',\n 'ug',\n 'ur',\n 'yi',\n ];\n\n async getLocales(): Promise<GetLocalesResult> {\n const languageTags =\n navigator.languages && navigator.languages.length > 0\n ? navigator.languages\n : [navigator.language];\n const locales = languageTags.map(languageTag =>\n this.createLocale(languageTag),\n );\n return { locales };\n }\n\n async getSettings(): Promise<GetSettingsResult> {\n const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n const uses24HourClock = this.determineUses24HourClock();\n const firstDayOfWeek = this.determineFirstDayOfWeek(navigator.language);\n return { timeZone, uses24HourClock, firstDayOfWeek };\n }\n\n private createLocale(languageTag: string): Locale {\n const locale = new Intl.Locale(languageTag) as ExtendedLocale;\n const separators = this.determineSeparators(languageTag);\n return {\n languageTag,\n languageCode: locale.language,\n regionCode: locale.region ?? null,\n currencyCode: null,\n currencySymbol: null,\n decimalSeparator: separators.decimalSeparator,\n groupingSeparator: separators.groupingSeparator,\n textDirection: this.determineTextDirection(locale),\n measurementSystem: null,\n };\n }\n\n private determineFirstDayOfWeek(languageTag: string): number {\n const locale = new Intl.Locale(languageTag) as ExtendedLocale;\n const weekInfo = locale.getWeekInfo?.() ?? locale.weekInfo;\n return weekInfo?.firstDay ?? 1;\n }\n\n private determineSeparators(languageTag: string): {\n decimalSeparator: string | null;\n groupingSeparator: string | null;\n } {\n const parts = new Intl.NumberFormat(languageTag).formatToParts(1000000.1);\n const decimalSeparator =\n parts.find(part => part.type === 'decimal')?.value ?? null;\n const groupingSeparator =\n parts.find(part => part.type === 'group')?.value ?? null;\n return { decimalSeparator, groupingSeparator };\n }\n\n private determineTextDirection(locale: ExtendedLocale): TextDirection {\n const textInfo = locale.getTextInfo?.() ?? locale.textInfo;\n if (textInfo) {\n return textInfo.direction;\n }\n return LocalizationWeb.rtlLanguageCodes.includes(locale.language)\n ? 'rtl'\n : 'ltr';\n }\n\n private determineUses24HourClock(): boolean {\n const resolvedOptions = Intl.DateTimeFormat(navigator.language, {\n hour: 'numeric',\n }).resolvedOptions() as Intl.ResolvedDateTimeFormatOptions & {\n hourCycle?: string;\n };\n const hourCycle = resolvedOptions.hourCycle;\n return hourCycle === 'h23' || hourCycle === 'h24';\n }\n}\n"]}
|