expo-localization 14.8.3 → 15.0.0
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/CHANGELOG.md +14 -3
- package/android/build.gradle +7 -93
- package/android/src/main/java/expo/modules/localization/LocalizationModule.kt +18 -9
- package/build/ExpoLocalization.d.ts +1 -1
- package/build/ExpoLocalization.d.ts.map +1 -1
- package/build/ExpoLocalization.js +1 -1
- package/build/ExpoLocalization.js.map +1 -1
- package/build/Localization.d.ts +62 -47
- package/build/Localization.d.ts.map +1 -1
- package/build/Localization.js +62 -47
- package/build/Localization.js.map +1 -1
- package/build/Localization.types.d.ts +31 -23
- package/build/Localization.types.d.ts.map +1 -1
- package/build/Localization.types.js.map +1 -1
- package/ios/ExpoLocalization.podspec +2 -0
- package/ios/LocalizationModule.swift +1 -0
- package/ios/PrivacyInfo.xcprivacy +24 -0
- package/package.json +2 -2
- package/src/Localization.ts +62 -47
- package/src/Localization.types.ts +31 -24
package/CHANGELOG.md
CHANGED
|
@@ -10,15 +10,26 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 15.0.0 — 2024-04-18
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- [iOS] Add privacy manifest describing required reason API usage. ([#27770](https://github.com/expo/expo/pull/27770) by [@aleqsio](https://github.com/aleqsio))
|
|
18
|
+
- [Android] Fix es-419 locale returning empty list. ([#27250](https://github.com/expo/expo/pull/27250) by [@aleqsio](https://github.com/aleqsio))
|
|
19
|
+
|
|
20
|
+
### 💡 Others
|
|
21
|
+
|
|
22
|
+
- Removed deprecated backward compatible Gradle settings. ([#28083](https://github.com/expo/expo/pull/28083) by [@kudo](https://github.com/kudo))
|
|
23
|
+
|
|
24
|
+
## 14.8.3 - 2024-01-18
|
|
14
25
|
|
|
15
26
|
_This version does not introduce any user-facing changes._
|
|
16
27
|
|
|
17
|
-
## 14.8.2
|
|
28
|
+
## 14.8.2 - 2024-01-10
|
|
18
29
|
|
|
19
30
|
_This version does not introduce any user-facing changes._
|
|
20
31
|
|
|
21
|
-
## 14.8.1
|
|
32
|
+
## 14.8.1 - 2023-12-19
|
|
22
33
|
|
|
23
34
|
_This version does not introduce any user-facing changes._
|
|
24
35
|
|
package/android/build.gradle
CHANGED
|
@@ -1,109 +1,23 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
-
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven-publish'
|
|
4
2
|
|
|
5
3
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
4
|
+
version = '15.0.0'
|
|
7
5
|
|
|
8
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
useExpoPublishing()
|
|
15
|
-
useCoreDependencies()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
buildscript {
|
|
20
|
-
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
-
ext.safeExtGet = { prop, fallback ->
|
|
22
|
-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Ensures backward compatibility
|
|
26
|
-
ext.getKotlinVersion = {
|
|
27
|
-
if (ext.has("kotlinVersion")) {
|
|
28
|
-
ext.kotlinVersion()
|
|
29
|
-
} else {
|
|
30
|
-
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
repositories {
|
|
35
|
-
mavenCentral()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dependencies {
|
|
39
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
44
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
45
|
-
afterEvaluate {
|
|
46
|
-
publishing {
|
|
47
|
-
publications {
|
|
48
|
-
release(MavenPublication) {
|
|
49
|
-
from components.release
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
repositories {
|
|
53
|
-
maven {
|
|
54
|
-
url = mavenLocal().url
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useDefaultAndroidSdkVersions()
|
|
11
|
+
useExpoPublishing()
|
|
60
12
|
|
|
61
13
|
android {
|
|
62
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
63
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
64
|
-
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
65
|
-
|
|
66
|
-
defaultConfig {
|
|
67
|
-
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
68
|
-
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
publishing {
|
|
72
|
-
singleVariant("release") {
|
|
73
|
-
withSourcesJar()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
lintOptions {
|
|
78
|
-
abortOnError false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
83
|
-
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
84
|
-
compileOptions {
|
|
85
|
-
sourceCompatibility JavaVersion.VERSION_11
|
|
86
|
-
targetCompatibility JavaVersion.VERSION_11
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
kotlinOptions {
|
|
90
|
-
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
14
|
namespace "expo.modules.localization"
|
|
95
15
|
defaultConfig {
|
|
96
16
|
versionCode 22
|
|
97
|
-
versionName "
|
|
17
|
+
versionName "15.0.0"
|
|
98
18
|
}
|
|
99
19
|
}
|
|
100
20
|
|
|
101
21
|
dependencies {
|
|
102
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
103
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
104
|
-
implementation project(':expo-modules-core')
|
|
105
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
106
|
-
}
|
|
107
|
-
|
|
108
22
|
implementation "androidx.core:core-ktx:1.6.0"
|
|
109
23
|
}
|
|
@@ -19,8 +19,6 @@ import expo.modules.kotlin.modules.ModuleDefinition
|
|
|
19
19
|
import java.text.DecimalFormatSymbols
|
|
20
20
|
import java.util.*
|
|
21
21
|
|
|
22
|
-
// EXPO_VERSIONING_NEEDS_PACKAGE_R
|
|
23
|
-
|
|
24
22
|
// must be kept in sync with https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/modules/i18nmanager/I18nUtil.java
|
|
25
23
|
private const val SHARED_PREFS_NAME = "com.facebook.react.modules.i18nmanager.I18nUtil"
|
|
26
24
|
private const val KEY_FOR_PREFS_ALLOWRTL = "RCTI18nUtil_allowRTL"
|
|
@@ -38,7 +36,7 @@ class LocalizationModule : Module() {
|
|
|
38
36
|
bundledConstants.toShallowMap()
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
AsyncFunction("getLocalizationAsync") {
|
|
39
|
+
AsyncFunction<Bundle>("getLocalizationAsync") {
|
|
42
40
|
return@AsyncFunction bundledConstants
|
|
43
41
|
}
|
|
44
42
|
|
|
@@ -53,7 +51,7 @@ class LocalizationModule : Module() {
|
|
|
53
51
|
Events(LOCALE_SETTINGS_CHANGED, CALENDAR_SETTINGS_CHANGED)
|
|
54
52
|
|
|
55
53
|
OnCreate {
|
|
56
|
-
appContext
|
|
54
|
+
appContext.reactContext?.let {
|
|
57
55
|
setRTLFromStringResources(it)
|
|
58
56
|
}
|
|
59
57
|
observer = {
|
|
@@ -139,6 +137,21 @@ class LocalizationModule : Module() {
|
|
|
139
137
|
}
|
|
140
138
|
}
|
|
141
139
|
|
|
140
|
+
private fun getCurrencyProperties(locale: Locale): Map<String, Any?> {
|
|
141
|
+
return try {
|
|
142
|
+
mapOf(
|
|
143
|
+
"currencyCode" to Currency.getInstance(locale).currencyCode,
|
|
144
|
+
// currency symbol can be localized to display locale (1st on the list) or to the locale for the currency (as done here).
|
|
145
|
+
"currencySymbol" to Currency.getInstance(locale).getSymbol(locale)
|
|
146
|
+
)
|
|
147
|
+
} catch (e: Exception) {
|
|
148
|
+
mapOf(
|
|
149
|
+
"currencyCode" to null,
|
|
150
|
+
"currencySymbol" to null
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
142
155
|
private fun getPreferredLocales(): List<Map<String, Any?>> {
|
|
143
156
|
val locales = mutableListOf<Map<String, Any?>>()
|
|
144
157
|
val localeList: LocaleListCompat = LocaleListCompat.getDefault()
|
|
@@ -158,12 +171,8 @@ class LocalizationModule : Module() {
|
|
|
158
171
|
"digitGroupingSeparator" to decimalFormat.groupingSeparator.toString(),
|
|
159
172
|
|
|
160
173
|
"measurementSystem" to getMeasurementSystem(locale),
|
|
161
|
-
"currencyCode" to decimalFormat.currency.currencyCode,
|
|
162
|
-
|
|
163
|
-
// currency symbol can be localized to display locale (1st on the list) or to the locale for the currency (as done here).
|
|
164
|
-
"currencySymbol" to Currency.getInstance(locale).getSymbol(locale),
|
|
165
174
|
"temperatureUnit" to getTemperatureUnit(locale)
|
|
166
|
-
)
|
|
175
|
+
) + getCurrencyProperties(locale)
|
|
167
176
|
)
|
|
168
177
|
} catch (e: Exception) {
|
|
169
178
|
// warn about the problematic locale
|
|
@@ -16,7 +16,7 @@ declare const _default: {
|
|
|
16
16
|
readonly region: string | null;
|
|
17
17
|
getLocales(): Locale[];
|
|
18
18
|
getCalendars(): Calendar[];
|
|
19
|
-
getLocalizationAsync(): Promise<Omit<Localization,
|
|
19
|
+
getLocalizationAsync(): Promise<Omit<Localization, "getCalendars" | "getLocales">>;
|
|
20
20
|
};
|
|
21
21
|
export default _default;
|
|
22
22
|
//# sourceMappingURL=ExpoLocalization.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoLocalization.d.ts","sourceRoot":"","sources":["../src/ExpoLocalization.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAsB,MAAM,sBAAsB,CAAC;AAoC1F,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,GAAG,YAAY,CAKzE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,GAAG,YAAY,CAK3E;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,QAE5D;;;;;;;;;;;;kBAsEe,MAAM,EAAE;oBAgCN,QAAQ,EAAE;4BAcI,
|
|
1
|
+
{"version":3,"file":"ExpoLocalization.d.ts","sourceRoot":"","sources":["../src/ExpoLocalization.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAsB,MAAM,sBAAsB,CAAC;AAoC1F,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,GAAG,YAAY,CAKzE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,CAAC,KAAK,KAAA,KAAK,IAAI,GAAG,YAAY,CAK3E;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,QAE5D;;;;;;;;;;;;kBAsEe,MAAM,EAAE;oBAgCN,QAAQ,EAAE;4BAcI,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC;;AAlH1F,wBA4IE"}
|
|
@@ -139,7 +139,7 @@ export default {
|
|
|
139
139
|
{
|
|
140
140
|
calendar: (locale?.calendar || locale?.calendars?.[0]) || null,
|
|
141
141
|
timeZone: locale?.timeZone || locale?.timeZones?.[0] || null,
|
|
142
|
-
uses24hourClock: (locale?.hourCycle || locale?.hourCycles?.[0])?.startsWith('h2') ?? null,
|
|
142
|
+
uses24hourClock: (locale?.hourCycle || locale?.hourCycles?.[0])?.startsWith('h2') ?? null, //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle
|
|
143
143
|
firstWeekday: locale?.weekInfo?.firstDay || null,
|
|
144
144
|
},
|
|
145
145
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoLocalization.js","sourceRoot":"","sources":["../src/ExpoLocalization.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAE,QAAQ,EAAgB,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAIxC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,OAAO,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpF,CAAC,CAAC;AAaF,MAAM,yBAAyB,GAAG,gBAAgB,CAAC;AACnD,wEAAwE;AACxE,MAAM,eAAe,GAAG;IACtB,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ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ACL,MAAM;YACN,OAAO;YACP,MAAM;YACN,QAAQ;SACT,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,uBAAuB,CAAC,MAAc;IAC7C,OAAO,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC","sourcesContent":["/* eslint-env browser */\nimport { Platform, Subscription } from 'expo-modules-core';\nimport * as rtlDetect from 'rtl-detect';\n\nimport { Localization, Calendar, Locale, CalendarIdentifier } from './Localization.types';\n\nconst getNavigatorLocales = () => {\n return Platform.isDOMAvailable ? navigator.languages || [navigator.language] : [];\n};\n\ntype ExtendedLocale = Intl.Locale &\n // typescript definitions for navigator language don't include some modern Intl properties\n Partial<{\n textInfo: { direction: 'ltr' | 'rtl' };\n timeZones: string[];\n weekInfo: { firstDay: number };\n hourCycles: string[];\n timeZone: string;\n calendars: string[];\n }>;\n\nconst WEB_LANGUAGE_CHANGE_EVENT = 'languagechange';\n// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/\nconst USES_FAHRENHEIT = [\n 'AG',\n 'BZ',\n 'VG',\n 'FM',\n 'MH',\n 'MS',\n 'KN',\n 'BS',\n 'CY',\n 'TC',\n 'US',\n 'LR',\n 'PW',\n 'KY',\n];\n\nexport function addLocaleListener(listener: (event) => void): Subscription {\n addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);\n return {\n remove: () => removeEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener),\n };\n}\n\nexport function addCalendarListener(listener: (event) => void): Subscription {\n addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);\n return {\n remove: () => removeEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener),\n };\n}\n\nexport function removeSubscription(subscription: Subscription) {\n subscription.remove();\n}\n\nexport default {\n get currency(): string | null {\n // TODO: Add support\n return null;\n },\n get decimalSeparator(): string {\n return (1.1).toLocaleString().substring(1, 2);\n },\n get digitGroupingSeparator(): string {\n const value = (1000).toLocaleString();\n return value.length === 5 ? value.substring(1, 2) : '';\n },\n get isRTL(): boolean {\n return rtlDetect.isRtlLang(this.locale) ?? false;\n },\n get isMetric(): boolean {\n const { region } = this;\n switch (region) {\n case 'US': // USA\n case 'LR': // Liberia\n case 'MM': // Myanmar\n return false;\n }\n return true;\n },\n get locale(): string {\n if (!Platform.isDOMAvailable) {\n return '';\n }\n const locale =\n navigator.language ||\n navigator['systemLanguage'] ||\n navigator['browserLanguage'] ||\n navigator['userLanguage'] ||\n this.locales[0];\n return locale;\n },\n get locales(): string[] {\n if (!Platform.isDOMAvailable) {\n return [];\n }\n const { languages = [] } = navigator;\n return Array.from(languages);\n },\n get timezone(): string {\n const defaultTimeZone = 'Etc/UTC';\n if (typeof Intl === 'undefined') {\n return defaultTimeZone;\n }\n return Intl.DateTimeFormat().resolvedOptions().timeZone || defaultTimeZone;\n },\n get isoCurrencyCodes(): string[] {\n // TODO(Bacon): Add this - very low priority\n return [];\n },\n get region(): string | null {\n // There is no way to obtain the current region, as is possible on native.\n // Instead, use the country-code from the locale when possible (e.g. \"en-US\").\n const { locale } = this;\n const [, ...suffixes] = typeof locale === 'string' ? locale.split('-') : [];\n for (const suffix of suffixes) {\n if (suffix.length === 2) {\n return suffix.toUpperCase();\n }\n }\n return null;\n },\n\n getLocales(): Locale[] {\n const locales = getNavigatorLocales();\n return locales?.map((languageTag) => {\n // TextInfo is an experimental API that is not available in all browsers.\n // We might want to consider using a locale lookup table instead.\n const locale =\n typeof Intl !== 'undefined'\n ? (new Intl.Locale(languageTag) as unknown as ExtendedLocale)\n : { region: null, textInfo: null, language: null };\n const { region, textInfo, language } = locale;\n\n // Properties added only for compatibility with native, use `toLocaleString` instead.\n const digitGroupingSeparator =\n Array.from((10000).toLocaleString(languageTag)).filter((c) => c > '9' || c < '0')[0] ||\n null; // using 1e5 instead of 1e4 since for some locales (like pl-PL) 1e4 does not use digit grouping\n const decimalSeparator = (1.1).toLocaleString(languageTag).substring(1, 2);\n const temperatureUnit = region ? regionToTemperatureUnit(region) : null;\n\n return {\n languageTag,\n languageCode: language || languageTag.split('-')[0] || 'en',\n textDirection: (textInfo?.direction as 'ltr' | 'rtl') || null,\n digitGroupingSeparator,\n decimalSeparator,\n measurementSystem: null,\n currencyCode: null,\n currencySymbol: null,\n regionCode: region || null,\n temperatureUnit,\n };\n });\n },\n getCalendars(): Calendar[] {\n const locale = ((typeof Intl !== 'undefined'\n ? Intl.DateTimeFormat().resolvedOptions()\n : null) ?? null) as unknown as null | ExtendedLocale;\n return [\n {\n calendar: ((locale?.calendar || locale?.calendars?.[0]) as CalendarIdentifier) || null,\n timeZone: locale?.timeZone || locale?.timeZones?.[0] || null,\n uses24hourClock: (locale?.hourCycle || locale?.hourCycles?.[0])?.startsWith('h2') ?? null, //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle\n firstWeekday: locale?.weekInfo?.firstDay || null,\n },\n ];\n },\n\n async getLocalizationAsync(): Promise<Omit<Localization, 'getCalendars' | 'getLocales'>> {\n const {\n currency,\n decimalSeparator,\n digitGroupingSeparator,\n isoCurrencyCodes,\n isMetric,\n isRTL,\n locale,\n locales,\n region,\n timezone,\n } = this;\n return {\n currency,\n decimalSeparator,\n digitGroupingSeparator,\n isoCurrencyCodes,\n isMetric,\n isRTL,\n locale,\n locales,\n region,\n timezone,\n };\n },\n};\n\nfunction regionToTemperatureUnit(region: string) {\n return USES_FAHRENHEIT.includes(region) ? 'fahrenheit' : 'celsius';\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoLocalization.js","sourceRoot":"","sources":["../src/ExpoLocalization.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAE,QAAQ,EAAgB,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AAIxC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IAC/B,OAAO,QAAQ,CAAC,cAAc,CAA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E,QAAQ,EAAE,QAAQ,IAAI,IAAI;aACjD;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,oBAAoB;QACxB,MAAM,EACJ,QAAQ,EACR,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,QAAQ,EACR,KAAK,EACL,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,GACT,GAAG,IAAI,CAAC;QACT,OAAO;YACL,QAAQ;YACR,gBAAgB;YAChB,sBAAsB;YACtB,gBAAgB;YAChB,QAAQ;YACR,KAAK;YACL,MAAM;YACN,OAAO;YACP,MAAM;YACN,QAAQ;SACT,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,SAAS,uBAAuB,CAAC,MAAc;IAC7C,OAAO,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC","sourcesContent":["/* eslint-env browser */\nimport { Platform, Subscription } from 'expo-modules-core';\nimport * as rtlDetect from 'rtl-detect';\n\nimport { Localization, Calendar, Locale, CalendarIdentifier } from './Localization.types';\n\nconst getNavigatorLocales = () => {\n return Platform.isDOMAvailable ? navigator.languages || [navigator.language] : [];\n};\n\ntype ExtendedLocale = Intl.Locale &\n // typescript definitions for navigator language don't include some modern Intl properties\n Partial<{\n textInfo: { direction: 'ltr' | 'rtl' };\n timeZones: string[];\n weekInfo: { firstDay: number };\n hourCycles: string[];\n timeZone: string;\n calendars: string[];\n }>;\n\nconst WEB_LANGUAGE_CHANGE_EVENT = 'languagechange';\n// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/\nconst USES_FAHRENHEIT = [\n 'AG',\n 'BZ',\n 'VG',\n 'FM',\n 'MH',\n 'MS',\n 'KN',\n 'BS',\n 'CY',\n 'TC',\n 'US',\n 'LR',\n 'PW',\n 'KY',\n];\n\nexport function addLocaleListener(listener: (event) => void): Subscription {\n addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);\n return {\n remove: () => removeEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener),\n };\n}\n\nexport function addCalendarListener(listener: (event) => void): Subscription {\n addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);\n return {\n remove: () => removeEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener),\n };\n}\n\nexport function removeSubscription(subscription: Subscription) {\n subscription.remove();\n}\n\nexport default {\n get currency(): string | null {\n // TODO: Add support\n return null;\n },\n get decimalSeparator(): string {\n return (1.1).toLocaleString().substring(1, 2);\n },\n get digitGroupingSeparator(): string {\n const value = (1000).toLocaleString();\n return value.length === 5 ? value.substring(1, 2) : '';\n },\n get isRTL(): boolean {\n return rtlDetect.isRtlLang(this.locale) ?? false;\n },\n get isMetric(): boolean {\n const { region } = this;\n switch (region) {\n case 'US': // USA\n case 'LR': // Liberia\n case 'MM': // Myanmar\n return false;\n }\n return true;\n },\n get locale(): string {\n if (!Platform.isDOMAvailable) {\n return '';\n }\n const locale =\n navigator.language ||\n navigator['systemLanguage'] ||\n navigator['browserLanguage'] ||\n navigator['userLanguage'] ||\n this.locales[0];\n return locale;\n },\n get locales(): string[] {\n if (!Platform.isDOMAvailable) {\n return [];\n }\n const { languages = [] } = navigator;\n return Array.from(languages);\n },\n get timezone(): string {\n const defaultTimeZone = 'Etc/UTC';\n if (typeof Intl === 'undefined') {\n return defaultTimeZone;\n }\n return Intl.DateTimeFormat().resolvedOptions().timeZone || defaultTimeZone;\n },\n get isoCurrencyCodes(): string[] {\n // TODO(Bacon): Add this - very low priority\n return [];\n },\n get region(): string | null {\n // There is no way to obtain the current region, as is possible on native.\n // Instead, use the country-code from the locale when possible (e.g. \"en-US\").\n const { locale } = this;\n const [, ...suffixes] = typeof locale === 'string' ? locale.split('-') : [];\n for (const suffix of suffixes) {\n if (suffix.length === 2) {\n return suffix.toUpperCase();\n }\n }\n return null;\n },\n\n getLocales(): Locale[] {\n const locales = getNavigatorLocales();\n return locales?.map((languageTag) => {\n // TextInfo is an experimental API that is not available in all browsers.\n // We might want to consider using a locale lookup table instead.\n const locale =\n typeof Intl !== 'undefined'\n ? (new Intl.Locale(languageTag) as unknown as ExtendedLocale)\n : { region: null, textInfo: null, language: null };\n const { region, textInfo, language } = locale;\n\n // Properties added only for compatibility with native, use `toLocaleString` instead.\n const digitGroupingSeparator =\n Array.from((10000).toLocaleString(languageTag)).filter((c) => c > '9' || c < '0')[0] ||\n null; // using 1e5 instead of 1e4 since for some locales (like pl-PL) 1e4 does not use digit grouping\n const decimalSeparator = (1.1).toLocaleString(languageTag).substring(1, 2);\n const temperatureUnit = region ? regionToTemperatureUnit(region) : null;\n\n return {\n languageTag,\n languageCode: language || languageTag.split('-')[0] || 'en',\n textDirection: (textInfo?.direction as 'ltr' | 'rtl') || null,\n digitGroupingSeparator,\n decimalSeparator,\n measurementSystem: null,\n currencyCode: null,\n currencySymbol: null,\n regionCode: region || null,\n temperatureUnit,\n };\n });\n },\n getCalendars(): Calendar[] {\n const locale = ((typeof Intl !== 'undefined'\n ? Intl.DateTimeFormat().resolvedOptions()\n : null) ?? null) as unknown as null | ExtendedLocale;\n return [\n {\n calendar: ((locale?.calendar || locale?.calendars?.[0]) as CalendarIdentifier) || null,\n timeZone: locale?.timeZone || locale?.timeZones?.[0] || null,\n uses24hourClock: (locale?.hourCycle || locale?.hourCycles?.[0])?.startsWith('h2') ?? null, //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle\n firstWeekday: locale?.weekInfo?.firstDay || null,\n },\n ];\n },\n\n async getLocalizationAsync(): Promise<Omit<Localization, 'getCalendars' | 'getLocales'>> {\n const {\n currency,\n decimalSeparator,\n digitGroupingSeparator,\n isoCurrencyCodes,\n isMetric,\n isRTL,\n locale,\n locales,\n region,\n timezone,\n } = this;\n return {\n currency,\n decimalSeparator,\n digitGroupingSeparator,\n isoCurrencyCodes,\n isMetric,\n isRTL,\n locale,\n locales,\n region,\n timezone,\n };\n },\n};\n\nfunction regionToTemperatureUnit(region: string) {\n return USES_FAHRENHEIT.includes(region) ? 'fahrenheit' : 'celsius';\n}\n"]}
|
package/build/Localization.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export * from './Localization.types';
|
|
|
5
5
|
* @deprecated Use Localization.getLocales() instead.
|
|
6
6
|
* Three-character ISO 4217 currency code. Returns `null` on web.
|
|
7
7
|
*
|
|
8
|
-
* @example
|
|
8
|
+
* @example
|
|
9
|
+
* `'USD'`, `'EUR'`, `'CNY'`, `null`
|
|
9
10
|
*/
|
|
10
11
|
export declare const currency: string | null;
|
|
11
12
|
/**
|
|
@@ -13,7 +14,8 @@ export declare const currency: string | null;
|
|
|
13
14
|
* @deprecated Use Localization.getLocales() instead.
|
|
14
15
|
* Decimal separator used for formatting numbers.
|
|
15
16
|
*
|
|
16
|
-
* @example
|
|
17
|
+
* @example
|
|
18
|
+
* `','`, `'.'`
|
|
17
19
|
*/
|
|
18
20
|
export declare const decimalSeparator: string;
|
|
19
21
|
/**
|
|
@@ -21,7 +23,8 @@ export declare const decimalSeparator: string;
|
|
|
21
23
|
* @deprecated Use Localization.getLocales() instead.
|
|
22
24
|
* Digit grouping separator used when formatting numbers larger than 1000.
|
|
23
25
|
*
|
|
24
|
-
* @example
|
|
26
|
+
* @example
|
|
27
|
+
* `'.'`, `''`, `','`
|
|
25
28
|
*/
|
|
26
29
|
export declare const digitGroupingSeparator: string;
|
|
27
30
|
/**
|
|
@@ -51,7 +54,8 @@ export declare const isRTL: boolean;
|
|
|
51
54
|
* An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag),
|
|
52
55
|
* consisting of a two-character language code and optional script, region and variant codes.
|
|
53
56
|
*
|
|
54
|
-
* @example
|
|
57
|
+
* @example
|
|
58
|
+
* `'en'`, `'en-US'`, `'zh-Hans'`, `'zh-Hans-CN'`, `'en-emodeng'`
|
|
55
59
|
*/
|
|
56
60
|
export declare const locale: string;
|
|
57
61
|
/**
|
|
@@ -60,7 +64,8 @@ export declare const locale: string;
|
|
|
60
64
|
* List of all the native languages provided by the user settings.
|
|
61
65
|
* These are returned in the order the user defines in their device settings.
|
|
62
66
|
*
|
|
63
|
-
* @example
|
|
67
|
+
* @example
|
|
68
|
+
* `['en', 'en-US', 'zh-Hans', 'zh-Hans-CN', 'en-emodeng']`
|
|
64
69
|
*/
|
|
65
70
|
export declare const locales: string[];
|
|
66
71
|
/**
|
|
@@ -71,7 +76,8 @@ export declare const locales: string[];
|
|
|
71
76
|
* better estimation you could use the moment-timezone package but it will add significant bloat to
|
|
72
77
|
* your website's bundle size.
|
|
73
78
|
*
|
|
74
|
-
* @example
|
|
79
|
+
* @example
|
|
80
|
+
* `'America/Los_Angeles'`
|
|
75
81
|
*/
|
|
76
82
|
export declare const timezone: string;
|
|
77
83
|
/**
|
|
@@ -80,7 +86,8 @@ export declare const timezone: string;
|
|
|
80
86
|
* The region code for your device that comes from the Region setting under Language & Region on iOS.
|
|
81
87
|
* This value is always available on iOS, but might return `null` on Android or web.
|
|
82
88
|
*
|
|
83
|
-
* @example
|
|
89
|
+
* @example
|
|
90
|
+
* `'US'`, `'NZ'`, `null`
|
|
84
91
|
*/
|
|
85
92
|
export declare const region: string | null;
|
|
86
93
|
/**
|
|
@@ -89,32 +96,36 @@ export declare const region: string | null;
|
|
|
89
96
|
* These are returned in the order the user defines in their device settings.
|
|
90
97
|
* On the web currency and measurements systems are not provided, instead returned as null.
|
|
91
98
|
* If needed, you can infer them from the current region using a lookup table.
|
|
92
|
-
* @example
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
* @example
|
|
100
|
+
* ```js
|
|
101
|
+
* [{
|
|
102
|
+
* "languageTag": "pl-PL",
|
|
103
|
+
* "languageCode": "pl",
|
|
104
|
+
* "textDirection": "ltr",
|
|
105
|
+
* "digitGroupingSeparator": " ",
|
|
106
|
+
* "decimalSeparator": ",",
|
|
107
|
+
* "measurementSystem": "metric",
|
|
108
|
+
* "currencyCode": "PLN",
|
|
109
|
+
* "currencySymbol": "zł",
|
|
110
|
+
* "regionCode": "PL",
|
|
111
|
+
* "temperatureUnit": "celsius"
|
|
112
|
+
* }]
|
|
113
|
+
* ```
|
|
104
114
|
*/
|
|
105
115
|
export declare const getLocales: () => import("./Localization.types").Locale[];
|
|
106
116
|
/**
|
|
107
117
|
* List of user's preferred calendars, returned as an array of objects of type `Calendar`.
|
|
108
118
|
* Guaranteed to contain at least 1 element.
|
|
109
119
|
* For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
|
|
110
|
-
* @example
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
* @example
|
|
121
|
+
* ```js
|
|
122
|
+
* [{
|
|
123
|
+
* "calendar": "gregory",
|
|
124
|
+
* "timeZone": "Europe/Warsaw",
|
|
125
|
+
* "uses24hourClock": true,
|
|
126
|
+
* "firstWeekday": 1
|
|
127
|
+
* }]
|
|
128
|
+
* ```
|
|
118
129
|
*/
|
|
119
130
|
export declare const getCalendars: () => import("./Localization.types").Calendar[];
|
|
120
131
|
/**
|
|
@@ -124,18 +135,21 @@ export declare const getCalendars: () => import("./Localization.types").Calendar
|
|
|
124
135
|
* On the web currency and measurements systems are not provided, instead returned as null.
|
|
125
136
|
* If needed, you can infer them from the current region using a lookup table.
|
|
126
137
|
* If the OS settings change, the hook will rerender with a new list of locales.
|
|
127
|
-
* @example
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
* @example
|
|
139
|
+
* ```js
|
|
140
|
+
* [{
|
|
141
|
+
* "languageTag": "pl-PL",
|
|
142
|
+
* "languageCode": "pl",
|
|
143
|
+
* "textDirection": "ltr",
|
|
144
|
+
* "digitGroupingSeparator": " ",
|
|
145
|
+
* "decimalSeparator": ",",
|
|
146
|
+
* "measurementSystem": "metric",
|
|
147
|
+
* "currencyCode": "PLN",
|
|
148
|
+
* "currencySymbol": "zł",
|
|
149
|
+
* "regionCode": "PL",
|
|
150
|
+
* "temperatureUnit": "celsius"
|
|
151
|
+
* }]
|
|
152
|
+
* ```
|
|
139
153
|
*/
|
|
140
154
|
export declare function useLocales(): import("./Localization.types").Locale[];
|
|
141
155
|
/**
|
|
@@ -143,14 +157,15 @@ export declare function useLocales(): import("./Localization.types").Locale[];
|
|
|
143
157
|
* Guaranteed to contain at least 1 element.
|
|
144
158
|
* For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.
|
|
145
159
|
* If the OS settings change, the hook will rerender with a new list of calendars.
|
|
146
|
-
* @example
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
160
|
+
* @example
|
|
161
|
+
* ```js
|
|
162
|
+
* [{
|
|
163
|
+
* "calendar": "gregory",
|
|
164
|
+
* "timeZone": "Europe/Warsaw",
|
|
165
|
+
* "uses24hourClock": true,
|
|
166
|
+
* "firstWeekday": 1
|
|
167
|
+
* }]
|
|
168
|
+
* ```
|
|
154
169
|
*/
|
|
155
170
|
export declare function useCalendars(): import("./Localization.types").Calendar[];
|
|
156
171
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Localization.d.ts","sourceRoot":"","sources":["../src/Localization.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,cAAc,sBAAsB,CAAC;AAGrC
|
|
1
|
+
{"version":3,"file":"Localization.d.ts","sourceRoot":"","sources":["../src/Localization.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,cAAc,sBAAsB,CAAC;AAGrC;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,eAA4B,CAAC;AAGlD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAoC,CAAC;AAGlE;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,QAA0C,CAAC;AAG9E;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,UAAoC,CAAC;AAGlE;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,SAA4B,CAAC;AAGlD;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,SAAyB,CAAC;AAG5C;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,QAA0B,CAAC;AAG9C;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,UAA2B,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,QAA4B,CAAC;AAGlD;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,eAA0B,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,UAAU,+CAA8B,CAAC;AAEtD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,iDAAgC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,4CAUzB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,8CAU3B;AAGD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,YAAY,CAAC,CAElE"}
|