expo-localization 14.3.0 → 14.5.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 +15 -0
- package/android/build.gradle +11 -8
- package/android/src/main/java/expo/modules/localization/LocalizationModule.kt +1 -9
- package/android/src/main/java/expo/modules/localization/LocalizationUtils.kt +15 -0
- package/build/ExpoLocalization.d.ts.map +1 -1
- package/build/ExpoLocalization.js +22 -0
- package/build/ExpoLocalization.js.map +1 -1
- package/build/Localization.d.ts +5 -3
- package/build/Localization.d.ts.map +1 -1
- package/build/Localization.js +5 -3
- package/build/Localization.js.map +1 -1
- package/build/Localization.types.d.ts +5 -0
- package/build/Localization.types.d.ts.map +1 -1
- package/build/Localization.types.js.map +1 -1
- package/ios/LocalizationModule.swift +16 -1
- package/package.json +2 -2
- package/src/ExpoLocalization.ts +24 -0
- package/src/Localization.ts +5 -3
- package/src/Localization.types.ts +6 -0
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,21 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 14.5.0 — 2023-09-04
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
|
|
18
|
+
- Added a `temperatureUnit` field, which contains the default temperature unit for the locale. ([#24059](https://github.com/expo/expo/pull/24059) by [@behenate](https://github.com/behenate))
|
|
19
|
+
|
|
20
|
+
### 💡 Others
|
|
21
|
+
|
|
22
|
+
- Change documentation to refer to a correct replacement method in a deprecated field. ([#23811](https://github.com/expo/expo/pull/23811) by [@aleqsio](https://github.com/aleqsio))
|
|
23
|
+
|
|
24
|
+
## 14.4.0 — 2023-08-02
|
|
25
|
+
|
|
26
|
+
_This version does not introduce any user-facing changes._
|
|
27
|
+
|
|
13
28
|
## 14.3.0 — 2023-06-21
|
|
14
29
|
|
|
15
30
|
### 🎉 New features
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '14.
|
|
6
|
+
version = '14.5.0'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -53,13 +53,16 @@ afterEvaluate {
|
|
|
53
53
|
android {
|
|
54
54
|
compileSdkVersion safeExtGet("compileSdkVersion", 33)
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
57
|
+
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
58
|
+
compileOptions {
|
|
59
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
60
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
61
|
+
}
|
|
60
62
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
kotlinOptions {
|
|
64
|
+
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
namespace "expo.modules.localization"
|
|
@@ -67,7 +70,7 @@ android {
|
|
|
67
70
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
68
71
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
69
72
|
versionCode 22
|
|
70
|
-
versionName "14.
|
|
73
|
+
versionName "14.5.0"
|
|
71
74
|
}
|
|
72
75
|
lintOptions {
|
|
73
76
|
abortOnError false
|
|
@@ -120,15 +120,6 @@ class LocalizationModule : Module() {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
private fun getRegionCode(locale: Locale): String? {
|
|
124
|
-
val miuiRegion = getSystemProperty("ro.miui.region")
|
|
125
|
-
return if (!TextUtils.isEmpty(miuiRegion)) {
|
|
126
|
-
miuiRegion
|
|
127
|
-
} else {
|
|
128
|
-
getCountryCode(locale)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
123
|
private fun getMeasurementSystem(locale: Locale): String? {
|
|
133
124
|
return if (VERSION.SDK_INT >= VERSION_CODES.P) {
|
|
134
125
|
when (LocaleData.getMeasurementSystem(ULocale.forLocale(locale))) {
|
|
@@ -167,6 +158,7 @@ class LocalizationModule : Module() {
|
|
|
167
158
|
|
|
168
159
|
// currency symbol can be localized to display locale (1st on the list) or to the locale for the currency (as done here).
|
|
169
160
|
"currencySymbol" to Currency.getInstance(locale).getSymbol(locale),
|
|
161
|
+
"temperatureUnit" to getTemperatureUnit(locale),
|
|
170
162
|
)
|
|
171
163
|
)
|
|
172
164
|
} catch (e: Exception) {
|
|
@@ -5,6 +5,9 @@ import java.util.*
|
|
|
5
5
|
|
|
6
6
|
val USES_IMPERIAL = listOf("US", "LR", "MM")
|
|
7
7
|
|
|
8
|
+
// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/
|
|
9
|
+
val USES_FAHRENHEIT = listOf("AG", "BZ", "VG", "FM", "MH", "MS", "KN", "BS", "CY", "TC", "US", "LR", "PW", "KY")
|
|
10
|
+
|
|
8
11
|
val ISOCurrencyCodes: Array<String> by lazy {
|
|
9
12
|
Currency.getAvailableCurrencies().map { it.currencyCode as String }.toTypedArray()
|
|
10
13
|
}
|
|
@@ -32,3 +35,15 @@ fun getCurrencyCode(locale: Locale): String? {
|
|
|
32
35
|
currency?.currencyCode
|
|
33
36
|
}.getOrNull()
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
fun getRegionCode(locale: Locale): String? {
|
|
40
|
+
val miuiRegion = getSystemProperty("ro.miui.region")
|
|
41
|
+
return miuiRegion.ifEmpty {
|
|
42
|
+
getCountryCode(locale)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun getTemperatureUnit(locale: Locale): String? {
|
|
47
|
+
val countryCode = getRegionCode(locale) ?: return null
|
|
48
|
+
return if (USES_FAHRENHEIT.contains(countryCode)) "fahrenheit" else "celsius"
|
|
49
|
+
}
|
|
@@ -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;
|
|
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,QAAQ,KAAK,YAAY,EAAE,cAAc,GAAG,YAAY,CAAC,CAAC;;AAlH1F,wBA4IE"}
|
|
@@ -5,6 +5,23 @@ const getNavigatorLocales = () => {
|
|
|
5
5
|
return Platform.isDOMAvailable ? navigator.languages || [navigator.language] : [];
|
|
6
6
|
};
|
|
7
7
|
const WEB_LANGUAGE_CHANGE_EVENT = 'languagechange';
|
|
8
|
+
// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/
|
|
9
|
+
const USES_FAHRENHEIT = [
|
|
10
|
+
'AG',
|
|
11
|
+
'BZ',
|
|
12
|
+
'VG',
|
|
13
|
+
'FM',
|
|
14
|
+
'MH',
|
|
15
|
+
'MS',
|
|
16
|
+
'KN',
|
|
17
|
+
'BS',
|
|
18
|
+
'CY',
|
|
19
|
+
'TC',
|
|
20
|
+
'US',
|
|
21
|
+
'LR',
|
|
22
|
+
'PW',
|
|
23
|
+
'KY',
|
|
24
|
+
];
|
|
8
25
|
export function addLocaleListener(listener) {
|
|
9
26
|
addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);
|
|
10
27
|
return {
|
|
@@ -99,6 +116,7 @@ export default {
|
|
|
99
116
|
const digitGroupingSeparator = Array.from((10000).toLocaleString(languageTag)).filter((c) => c > '9' || c < '0')[0] ||
|
|
100
117
|
null; // using 1e5 instead of 1e4 since for some locales (like pl-PL) 1e4 does not use digit grouping
|
|
101
118
|
const decimalSeparator = (1.1).toLocaleString(languageTag).substring(1, 2);
|
|
119
|
+
const temperatureUnit = region ? regionToTemperatureUnit(region) : null;
|
|
102
120
|
return {
|
|
103
121
|
languageTag,
|
|
104
122
|
languageCode: language || languageTag.split('-')[0] || 'en',
|
|
@@ -109,6 +127,7 @@ export default {
|
|
|
109
127
|
currencyCode: null,
|
|
110
128
|
currencySymbol: null,
|
|
111
129
|
regionCode: region || null,
|
|
130
|
+
temperatureUnit,
|
|
112
131
|
};
|
|
113
132
|
});
|
|
114
133
|
},
|
|
@@ -141,4 +160,7 @@ export default {
|
|
|
141
160
|
};
|
|
142
161
|
},
|
|
143
162
|
};
|
|
163
|
+
function regionToTemperatureUnit(region) {
|
|
164
|
+
return USES_FAHRENHEIT.includes(region) ? 'fahrenheit' : 'celsius';
|
|
165
|
+
}
|
|
144
166
|
//# sourceMappingURL=ExpoLocalization.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoLocalization.js","sourceRoot":"","sources":["../src/Exp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M,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","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\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}\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\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 };\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"]}
|
|
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,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,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AS,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
|
@@ -57,7 +57,7 @@ export declare const locale: string;
|
|
|
57
57
|
*/
|
|
58
58
|
export declare const locales: string[];
|
|
59
59
|
/**
|
|
60
|
-
* @deprecated Use Localization.
|
|
60
|
+
* @deprecated Use Localization.getCalendars() instead.
|
|
61
61
|
* The current time zone in display format.
|
|
62
62
|
* On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a
|
|
63
63
|
* better estimation you could use the moment-timezone package but it will add significant bloat to
|
|
@@ -89,7 +89,8 @@ export declare const region: string | null;
|
|
|
89
89
|
"measurementSystem": "metric",
|
|
90
90
|
"currencyCode": "PLN",
|
|
91
91
|
"currencySymbol": "zł",
|
|
92
|
-
"regionCode": "PL"
|
|
92
|
+
"regionCode": "PL",
|
|
93
|
+
"temperatureUnit": "celsius"
|
|
93
94
|
}]`
|
|
94
95
|
*/
|
|
95
96
|
export declare const getLocales: () => import("./Localization.types").Locale[];
|
|
@@ -123,7 +124,8 @@ export declare const getCalendars: () => import("./Localization.types").Calendar
|
|
|
123
124
|
"measurementSystem": "metric",
|
|
124
125
|
"currencyCode": "PLN",
|
|
125
126
|
"currencySymbol": "zł",
|
|
126
|
-
"regionCode": "PL"
|
|
127
|
+
"regionCode": "PL",
|
|
128
|
+
"temperatureUnit": "celsius"
|
|
127
129
|
}]`
|
|
128
130
|
*/
|
|
129
131
|
export declare function useLocales(): import("./Localization.types").Locale[];
|
|
@@ -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;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,eAA4B,CAAC;AAGlD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAoC,CAAC;AAGlE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,QAA0C,CAAC;AAG9E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,UAAoC,CAAC;AAGlE;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAA4B,CAAC;AAGlD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,SAAyB,CAAC;AAG5C;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,QAA0B,CAAC;AAG9C;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,UAA2B,CAAC;AAGhD;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,QAA4B,CAAC;AAGlD;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,eAA0B,CAAC;AAE9C
|
|
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;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,eAA4B,CAAC;AAGlD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAoC,CAAC;AAGlE;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,QAA0C,CAAC;AAG9E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,UAAoC,CAAC;AAGlE;;;;GAIG;AACH,eAAO,MAAM,QAAQ,SAA4B,CAAC;AAGlD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,SAAyB,CAAC;AAG5C;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,QAA0B,CAAC;AAG9C;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,UAA2B,CAAC;AAGhD;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,QAA4B,CAAC;AAGlD;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,eAA0B,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,+CAA8B,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,iDAAgC,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,4CAUzB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,8CAU3B;AAGD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,YAAY,CAAC,CAElE"}
|
package/build/Localization.js
CHANGED
|
@@ -67,7 +67,7 @@ export const locale = ExpoLocalization.locale;
|
|
|
67
67
|
export const locales = ExpoLocalization.locales;
|
|
68
68
|
// @needsAudit
|
|
69
69
|
/**
|
|
70
|
-
* @deprecated Use Localization.
|
|
70
|
+
* @deprecated Use Localization.getCalendars() instead.
|
|
71
71
|
* The current time zone in display format.
|
|
72
72
|
* On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a
|
|
73
73
|
* better estimation you could use the moment-timezone package but it will add significant bloat to
|
|
@@ -100,7 +100,8 @@ export const region = ExpoLocalization.region;
|
|
|
100
100
|
"measurementSystem": "metric",
|
|
101
101
|
"currencyCode": "PLN",
|
|
102
102
|
"currencySymbol": "zł",
|
|
103
|
-
"regionCode": "PL"
|
|
103
|
+
"regionCode": "PL",
|
|
104
|
+
"temperatureUnit": "celsius"
|
|
104
105
|
}]`
|
|
105
106
|
*/
|
|
106
107
|
export const getLocales = ExpoLocalization.getLocales;
|
|
@@ -134,7 +135,8 @@ export const getCalendars = ExpoLocalization.getCalendars;
|
|
|
134
135
|
"measurementSystem": "metric",
|
|
135
136
|
"currencyCode": "PLN",
|
|
136
137
|
"currencySymbol": "zł",
|
|
137
|
-
"regionCode": "PL"
|
|
138
|
+
"regionCode": "PL",
|
|
139
|
+
"temperatureUnit": "celsius"
|
|
138
140
|
}]`
|
|
139
141
|
*/
|
|
140
142
|
export function useLocales() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Localization.js","sourceRoot":"","sources":["../src/Localization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,gBAAgB,EAAE,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,cAAc,sBAAsB,CAAC;AAErC,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AAElD,cAAc;AACd;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,gBAAgB,CAAC;AAEl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BAAiB,CAAC,UAAU,CAAC,CAAC;QACnD,OAAO,GAAG,EAAE;YACV,kBAAkB,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,YAAY,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACrD,OAAO,GAAG,EAAE;YACV,kBAAkB,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,OAAO,MAAM,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import { useEffect, useReducer, useMemo } from 'react';\n\nimport ExpoLocalization, {\n addCalendarListener,\n addLocaleListener,\n removeSubscription,\n} from './ExpoLocalization';\nimport { Localization } from './Localization.types';\nexport * from './Localization.types';\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * Three-character ISO 4217 currency code. Returns `null` on web.\n *\n * @example `'USD'`, `'EUR'`, `'CNY'`, `null`\n */\nexport const currency = ExpoLocalization.currency;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * Decimal separator used for formatting numbers.\n *\n * @example `','`, `'.'`\n */\nexport const decimalSeparator = ExpoLocalization.decimalSeparator;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * Digit grouping separator used when formatting numbers larger than 1000.\n *\n * @example `'.'`, `''`, `','`\n */\nexport const digitGroupingSeparator = ExpoLocalization.digitGroupingSeparator;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * A list of all the supported language ISO codes.\n */\nexport const isoCurrencyCodes = ExpoLocalization.isoCurrencyCodes;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * Boolean value that indicates whether the system uses the metric system.\n * On Android and web, this is inferred from the current region.\n */\nexport const isMetric = ExpoLocalization.isMetric;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * Returns if the system's language is written from Right-to-Left.\n * This can be used to build features like [bidirectional icons](https://material.io/design/usability/bidirectionality.html).\n *\n * Returns `false` in Server Side Rendering (SSR) environments.\n */\nexport const isRTL = ExpoLocalization.isRTL;\n\n// @needsAudit\n/**\n * Consider using Localization.getLocales() for a list of user preferred locales instead.\n * An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag),\n * consisting of a two-character language code and optional script, region and variant codes.\n *\n * @example `'en'`, `'en-US'`, `'zh-Hans'`, `'zh-Hans-CN'`, `'en-emodeng'`\n */\nexport const locale = ExpoLocalization.locale;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * List of all the native languages provided by the user settings.\n * These are returned in the order the user defines in their device settings.\n *\n * @example `['en', 'en-US', 'zh-Hans', 'zh-Hans-CN', 'en-emodeng']`\n */\nexport const locales = ExpoLocalization.locales;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getCalendars() instead.\n * The current time zone in display format.\n * On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a\n * better estimation you could use the moment-timezone package but it will add significant bloat to\n * your website's bundle size.\n *\n * @example `'America/Los_Angeles'`\n */\nexport const timezone = ExpoLocalization.timezone;\n\n// @needsAudit\n/**\n * @deprecated Use Localization.getLocales() instead.\n * The region code for your device that comes from the Region setting under Language & Region on iOS.\n * This value is always available on iOS, but might return `null` on Android or web.\n *\n * @example `'US'`, `'NZ'`, `null`\n */\nexport const region = ExpoLocalization.region;\n\n/**\n * List of user's locales, returned as an array of objects of type `Locale`.\n * Guaranteed to contain at least 1 element.\n * These are returned in the order the user defines in their device settings.\n * On the web currency and measurements systems are not provided, instead returned as null.\n * If needed, you can infer them from the current region using a lookup table.\n * @example `[{\n \"languageTag\": \"pl-PL\",\n \"languageCode\": \"pl\",\n \"textDirection\": \"ltr\",\n \"digitGroupingSeparator\": \" \",\n \"decimalSeparator\": \",\",\n \"measurementSystem\": \"metric\",\n \"currencyCode\": \"PLN\",\n \"currencySymbol\": \"zł\",\n \"regionCode\": \"PL\",\n \"temperatureUnit\": \"celsius\"\n }]`\n */\nexport const getLocales = ExpoLocalization.getLocales;\n\n/**\n * List of user's preferred calendars, returned as an array of objects of type `Calendar`.\n * Guaranteed to contain at least 1 element.\n * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.\n * @example `[\n {\n \"calendar\": \"gregory\",\n \"timeZone\": \"Europe/Warsaw\",\n \"uses24hourClock\": true,\n \"firstWeekday\": 1\n }\n ]`\n */\nexport const getCalendars = ExpoLocalization.getCalendars;\n\n/**\n * A hook providing a list of user's locales, returned as an array of objects of type `Locale`.\n * Guaranteed to contain at least 1 element.\n * These are returned in the order the user defines in their device settings.\n * On the web currency and measurements systems are not provided, instead returned as null.\n * If needed, you can infer them from the current region using a lookup table.\n * If the OS settings change, the hook will rerender with a new list of locales.\n * @example `[{\n \"languageTag\": \"pl-PL\",\n \"languageCode\": \"pl\",\n \"textDirection\": \"ltr\",\n \"digitGroupingSeparator\": \" \",\n \"decimalSeparator\": \",\",\n \"measurementSystem\": \"metric\",\n \"currencyCode\": \"PLN\",\n \"currencySymbol\": \"zł\",\n \"regionCode\": \"PL\",\n \"temperatureUnit\": \"celsius\"\n }]`\n */\nexport function useLocales() {\n const [key, invalidate] = useReducer((k) => k + 1, 0);\n const locales = useMemo(() => getLocales(), [key]);\n useEffect(() => {\n const subscription = addLocaleListener(invalidate);\n return () => {\n removeSubscription(subscription);\n };\n }, []);\n return locales;\n}\n\n/**\n * A hook providing a list of user's preferred calendars, returned as an array of objects of type `Calendar`.\n * Guaranteed to contain at least 1 element.\n * For now always returns a single element, but it's likely to return a user preference list on some platforms in the future.\n * If the OS settings change, the hook will rerender with a new list of calendars.\n * @example `[\n {\n \"calendar\": \"gregory\",\n \"timeZone\": \"Europe/Warsaw\",\n \"uses24hourClock\": true,\n \"firstWeekday\": 1\n }\n ]`\n */\nexport function useCalendars() {\n const [key, invalidate] = useReducer((k) => k + 1, 0);\n const calendars = useMemo(() => getCalendars(), [key]);\n useEffect(() => {\n const subscription = addCalendarListener(invalidate);\n return () => {\n removeSubscription(subscription);\n };\n }, []);\n return calendars;\n}\n\n// @needsAudit\n/**\n * Get the latest native values from the device. Locale can be changed on some Android devices\n * without resetting the app.\n * > On iOS, changing the locale will cause the device to reset meaning the constants will always be\n * correct.\n *\n * @example\n * ```ts\n * // When the app returns from the background on Android...\n *\n * const { locale } = await Localization.getLocalizationAsync();\n * ```\n * @deprecated\n * Use Localization.getLocales() or Localization.getCalendars() instead.\n */\nexport async function getLocalizationAsync(): Promise<Localization> {\n return await ExpoLocalization.getLocalizationAsync();\n}\n"]}
|
|
@@ -111,6 +111,11 @@ export type Locale = {
|
|
|
111
111
|
* Ask for user preferences if possible.
|
|
112
112
|
*/
|
|
113
113
|
measurementSystem: `metric` | `us` | `uk` | null;
|
|
114
|
+
/**
|
|
115
|
+
* The temperature unit used in the locale.
|
|
116
|
+
* Returns `null` if the region code is unknown.
|
|
117
|
+
*/
|
|
118
|
+
temperatureUnit: 'celsius' | 'fahrenheit' | null;
|
|
114
119
|
};
|
|
115
120
|
/**
|
|
116
121
|
* An enum mapping days of the week in Gregorian calendar to their index as returned by the `firstWeekday` property.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Localization.types.d.ts","sourceRoot":"","sources":["../src/Localization.types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;;OAKG;IACH,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB;;;;;;;OAOG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;;OAIG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B;;;;OAIG;IACH,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B;;;OAGG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;OAGG;IACH,sBAAsB,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC;;OAEG;IACH,aAAa,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;IACpC;;;;OAIG;IACH,iBAAiB,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,oBAAY,OAAO;IACjB,MAAM,IAAI;IACV,MAAM,IAAI;IACV,OAAO,IAAI;IACX,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,QAAQ,IAAI;CACb;AAED;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,6BAA6B;IAC7B,QAAQ,aAAa;IACrB,mCAAmC;IACnC,OAAO,YAAY;IACnB,sBAAsB;IACtB,MAAM,WAAW;IACjB,kCAAkC;IAClC,KAAK,UAAU;IACf,+DAA+D;IAC/D,OAAO,YAAY;IACnB,6DAA6D;IAC7D,QAAQ,aAAa;IACrB,yBAAyB;IACzB,OAAO,YAAY;IACnB,iCAAiC;IACjC,SAAS,YAAY;IACrB,kCAAkC;IAClC,MAAM,WAAW;IACjB,sBAAsB;IACtB,MAAM,WAAW;IACjB,uBAAuB;IACvB,OAAO,YAAY;IACnB,kGAAkG;IAClG,aAAa,kBAAkB;IAC/B,8CAA8C;IAC9C,YAAY,iBAAiB;IAC7B,wGAAwG;IACxG,YAAY,iBAAiB;IAC7B,oCAAoC;IACpC,gBAAgB,qBAAqB;IACrC,+EAA+E;IAC/E,OAAO,YAAY;IACnB,iCAAiC;IACjC,QAAQ,aAAa;IACrB,uBAAuB;IACvB,OAAO,YAAY;IACnB,0CAA0C;IAC1C,GAAG,QAAQ;CACZ;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB;;;;;;OAMG;IACH,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC;;;OAGG;IACH,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC;;;;OAIG;IACH,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"Localization.types.d.ts","sourceRoot":"","sources":["../src/Localization.types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI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,QAAQ,IAAI;CACb;AAED;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,6BAA6B;IAC7B,QAAQ,aAAa;IACrB,mCAAmC;IACnC,OAAO,YAAY;IACnB,sBAAsB;IACtB,MAAM,WAAW;IACjB,kCAAkC;IAClC,KAAK,UAAU;IACf,+DAA+D;IAC/D,OAAO,YAAY;IACnB,6DAA6D;IAC7D,QAAQ,aAAa;IACrB,yBAAyB;IACzB,OAAO,YAAY;IACnB,iCAAiC;IACjC,SAAS,YAAY;IACrB,kCAAkC;IAClC,MAAM,WAAW;IACjB,sBAAsB;IACtB,MAAM,WAAW;IACjB,uBAAuB;IACvB,OAAO,YAAY;IACnB,kGAAkG;IAClG,aAAa,kBAAkB;IAC/B,8CAA8C;IAC9C,YAAY,iBAAiB;IAC7B,wGAAwG;IACxG,YAAY,iBAAiB;IAC7B,oCAAoC;IACpC,gBAAgB,qBAAqB;IACrC,+EAA+E;IAC/E,OAAO,YAAY;IACnB,iCAAiC;IACjC,QAAQ,aAAa;IACrB,uBAAuB;IACvB,OAAO,YAAY;IACnB,0CAA0C;IAC1C,GAAG,QAAQ;CACZ;AAED,MAAM,MAAM,QAAQ,GAAG;IACrB;;;;;;OAMG;IACH,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACpC;;;OAGG;IACH,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC;;;;OAIG;IACH,YAAY,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Localization.types.js","sourceRoot":"","sources":["../src/Localization.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Localization.types.js","sourceRoot":"","sources":["../src/Localization.types.ts"],"names":[],"mappings":"AA2HA;;GAEG;AACH,MAAM,CAAN,IAAY,OAQX;AARD,WAAY,OAAO;IACjB,yCAAU,CAAA;IACV,yCAAU,CAAA;IACV,2CAAW,CAAA;IACX,+CAAa,CAAA;IACb,6CAAY,CAAA;IACZ,yCAAU,CAAA;IACV,6CAAY,CAAA;AACd,CAAC,EARW,OAAO,KAAP,OAAO,QAQlB;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,kBAuCX;AAvCD,WAAY,kBAAkB;IAC5B,6BAA6B;IAC7B,2CAAqB,CAAA;IACrB,mCAAmC;IACnC,yCAAmB,CAAA;IACnB,sBAAsB;IACtB,uCAAiB,CAAA;IACjB,kCAAkC;IAClC,qCAAe,CAAA;IACf,+DAA+D;IAC/D,yCAAmB,CAAA;IACnB,6DAA6D;IAC7D,2CAAqB,CAAA;IACrB,yBAAyB;IACzB,yCAAmB,CAAA;IACnB,iCAAiC;IACjC,2CAAqB,CAAA;IACrB,kCAAkC;IAClC,uCAAiB,CAAA;IACjB,sBAAsB;IACtB,uCAAiB,CAAA;IACjB,uBAAuB;IACvB,yCAAmB,CAAA;IACnB,kGAAkG;IAClG,qDAA+B,CAAA;IAC/B,8CAA8C;IAC9C,mDAA6B,CAAA;IAC7B,wGAAwG;IACxG,mDAA6B,CAAA;IAC7B,oCAAoC;IACpC,2DAAqC,CAAA;IACrC,+EAA+E;IAC/E,yCAAmB,CAAA;IACnB,iCAAiC;IACjC,2CAAqB,CAAA;IACrB,uBAAuB;IACvB,yCAAmB,CAAA;IACnB,0CAA0C;IAC1C,iCAAW,CAAA;AACb,CAAC,EAvCW,kBAAkB,KAAlB,kBAAkB,QAuC7B","sourcesContent":["// @needsAudit\nexport type Localization = {\n /**\n * Three-character ISO 4217 currency code. Returns `null` on web.\n *\n * @example `'USD'`, `'EUR'`, `'CNY'`, `null`\n */\n currency: string | null;\n /**\n * Decimal separator used for formatting numbers.\n *\n * @example `','`, `'.'`\n */\n decimalSeparator: string;\n /**\n * Digit grouping separator used when formatting numbers larger than 1000.\n *\n * @example `'.'`, `''`, `','`\n */\n digitGroupingSeparator: string;\n /**\n * A list of all the supported language ISO codes.\n */\n isoCurrencyCodes: string[];\n /**\n * Boolean value that indicates whether the system uses the metric system.\n * On Android and web, this is inferred from the current region.\n */\n isMetric: boolean;\n /**\n * Returns if the system's language is written from Right-to-Left.\n * This can be used to build features like [bidirectional icons](https://material.io/design/usability/bidirectionality.html).\n *\n * Returns `false` in Server Side Rendering (SSR) environments.\n */\n isRTL: boolean;\n /**\n * An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag),\n * consisting of a two-character language code and optional script, region and variant codes.\n *\n * @example `'en'`, `'en-US'`, `'zh-Hans'`, `'zh-Hans-CN'`, `'en-emodeng'`\n */\n locale: string;\n /**\n * List of all the native languages provided by the user settings.\n * These are returned in the order that the user defined in the device settings.\n *\n * @example `['en', 'en-US', 'zh-Hans', 'zh-Hans-CN', 'en-emodeng']`\n */\n locales: string[];\n /**\n * The region code for your device that comes from the Region setting under Language & Region on iOS.\n * This value is always available on iOS, but might return `null` on Android or web.\n *\n * @example `'US'`, `'NZ'`, `null`\n */\n region: string | null;\n /**\n * The current time zone in display format.\n * On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a\n * better estimation you could use the moment-timezone package but it will add significant bloat to\n * your website's bundle size.\n *\n * @example `'America/Los_Angeles'`\n */\n timezone: string;\n};\n\nexport type Locale = {\n /**\n * An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) with a region code.\n * @example `'en-US'`, `'es-419'`, `'pl-PL'`.\n */\n languageTag: string;\n /**\n * An [IETF BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) without the region code.\n * @example `'en'`, `'es'`, `'pl'`.\n */\n languageCode: string;\n /**\n * The region code for your device that comes from the Region setting under Language & Region on iOS, Region settings on Android and is parsed from locale on Web (can be `null` on Web).\n */\n regionCode: string | null;\n /**\n * Currency code for the locale.\n * Is `null` on Web, use a table lookup based on region instead.\n * @example `'USD'`, `'EUR'`, `'PLN'`.\n */\n currencyCode: string | null;\n /**\n * Currency symbol for the locale.\n * Is `null` on Web, use a table lookup based on region (if available) instead.\n * @example `'$'`, `'€'`, `'zł'`.\n */\n currencySymbol: string | null;\n /**\n * Decimal separator used for formatting numbers with fractional parts.\n * @example `'.'`, `','`.\n */\n decimalSeparator: string | null;\n /**\n * Digit grouping separator used for formatting large numbers.\n * @example `'.'`, `','`.\n */\n digitGroupingSeparator: string | null;\n /**\n * Text direction for the locale. One of: `'ltr'`, `'rtl'`, but can also be `null` on some browsers without support for the [textInfo](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/textInfo) property in [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) API.\n */\n textDirection: 'ltr' | 'rtl' | null;\n /**\n * The measurement system used in the locale.\n * Is `null` on Web, as user chosen measurement system is not exposed on the web and using locale to determine measurement systems is unreliable.\n * Ask for user preferences if possible.\n */\n measurementSystem: `metric` | `us` | `uk` | null;\n\n /**\n * The temperature unit used in the locale.\n * Returns `null` if the region code is unknown.\n */\n temperatureUnit: 'celsius' | 'fahrenheit' | null;\n};\n\n/**\n * An enum mapping days of the week in Gregorian calendar to their index as returned by the `firstWeekday` property.\n */\nexport enum Weekday {\n SUNDAY = 1,\n MONDAY = 2,\n TUESDAY = 3,\n WEDNESDAY = 4,\n THURSDAY = 5,\n FRIDAY = 6,\n SATURDAY = 7,\n}\n\n/**\n * The calendar identifier, one of [Unicode calendar types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar).\n * Gregorian calendar is aliased and can be referred to as both `CalendarIdentifier.GREGORIAN` and `CalendarIdentifier.GREGORY`.\n */\nexport enum CalendarIdentifier {\n /** Thai Buddhist calendar */\n BUDDHIST = 'buddhist',\n /** Traditional Chinese calendar */\n CHINESE = 'chinese',\n /** Coptic calendar */\n COPTIC = 'coptic',\n /** Traditional Korean calendar */\n DANGI = 'dangi',\n /** Ethiopic calendar, Amete Alem (epoch approx. 5493 B.C.E) */\n ETHIOAA = 'ethioaa',\n /** Ethiopic calendar, Amete Mihret (epoch approx, 8 C.E.) */\n ETHIOPIC = 'ethiopic',\n /** Gregorian calendar */\n GREGORY = 'gregory',\n /** Gregorian calendar (alias) */\n GREGORIAN = 'gregory',\n /** Traditional Hebrew calendar */\n HEBREW = 'hebrew',\n /** Indian calendar */\n INDIAN = 'indian',\n /** Islamic calendar */\n ISLAMIC = 'islamic',\n /** Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - civil epoch) */\n ISLAMIC_CIVIL = 'islamic-civil',\n /** Islamic calendar, Saudi Arabia sighting */\n ISLAMIC_RGSA = 'islamic-rgsa',\n /**Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - astronomical epoch) */\n ISLAMIC_TBLA = 'islamic-tbla',\n /** Islamic calendar, Umm al-Qura */\n ISLAMIC_UMALQURA = 'islamic-umalqura',\n /** ISO calendar (Gregorian calendar using the ISO 8601 calendar week rules) */\n ISO8601 = 'iso8601',\n /** Japanese imperial calendar */\n JAPANESE = 'japanese',\n /** Persian calendar */\n PERSIAN = 'persian',\n /** Civil (algorithmic) Arabic calendar */\n ROC = 'roc',\n}\n\nexport type Calendar = {\n /**\n * The calendar identifier, one of [Unicode calendar types](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/calendar).\n *\n * On Android is limited to one of device's [available calendar types](https://developer.android.com/reference/java/util/Calendar#getAvailableCalendarTypes()).\n *\n * On iOS uses [calendar identifiers](https://developer.apple.com/documentation/foundation/calendar/identifier), but maps them to the corresponding Unicode types, will also never contain `'dangi'` or `'islamic-rgsa'` due to it not being implemented on iOS.\n */\n calendar: CalendarIdentifier | null;\n /**\n * True when current device settings use 24 hour time format.\n * Can be null on some browsers that don't support the [hourCycle](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle) property in [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) API.\n */\n uses24hourClock: boolean | null;\n /**\n * The first day of the week. For most calendars Sunday is numbered `1`, with Saturday being number `7`.\n * Can be null on some browsers that don't support the [weekInfo](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/weekInfo) property in [Intl](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) API.\n * @example `1`, `7`.\n */\n firstWeekday: Weekday | null;\n /**\n * Time zone for the calendar. Can be `null` on Web.\n * @example `'America/Los_Angeles'`, `'Europe/Warsaw'`, `'GMT+1'`.\n */\n timeZone: string | null;\n};\n"]}
|
|
@@ -142,7 +142,8 @@ public class LocalizationModule: Module {
|
|
|
142
142
|
"digitGroupingSeparator": userSettingsLocale.groupingSeparator,
|
|
143
143
|
"measurementSystem": getMeasurementSystemForLocale(userSettingsLocale),
|
|
144
144
|
"currencyCode": languageLocale.currencyCode,
|
|
145
|
-
"currencySymbol": languageLocale.currencySymbol
|
|
145
|
+
"currencySymbol": languageLocale.currencySymbol,
|
|
146
|
+
"temperatureUnit": getTemperatureUnit()
|
|
146
147
|
]
|
|
147
148
|
}
|
|
148
149
|
}
|
|
@@ -154,6 +155,20 @@ public class LocalizationModule: Module {
|
|
|
154
155
|
sendEvent(CALENDAR_SETTINGS_CHANGED)
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
static func getTemperatureUnit() -> String? {
|
|
159
|
+
let formatter = MeasurementFormatter()
|
|
160
|
+
formatter.locale = Locale.current
|
|
161
|
+
|
|
162
|
+
let temperature = Measurement(value: 0, unit: UnitTemperature.celsius)
|
|
163
|
+
let formatted = formatter.string(from: temperature)
|
|
164
|
+
|
|
165
|
+
guard let unitCharacter = formatted.last else {
|
|
166
|
+
return nil
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return unitCharacter == "F" ? "fahrenheit" : "celsius"
|
|
170
|
+
}
|
|
171
|
+
|
|
157
172
|
// https://stackoverflow.com/a/28183182
|
|
158
173
|
static func uses24HourClock() -> Bool {
|
|
159
174
|
let dateFormat = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)!
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-localization",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.5.0",
|
|
4
4
|
"description": "Provides an interface for native user localization information.",
|
|
5
5
|
"main": "build/Localization.js",
|
|
6
6
|
"types": "build/Localization.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"expo": "*"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "79607a7325f47aa17c36d266100d09a4ff2cc544"
|
|
51
51
|
}
|
package/src/ExpoLocalization.ts
CHANGED
|
@@ -20,6 +20,23 @@ type ExtendedLocale = Intl.Locale &
|
|
|
20
20
|
}>;
|
|
21
21
|
|
|
22
22
|
const WEB_LANGUAGE_CHANGE_EVENT = 'languagechange';
|
|
23
|
+
// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/
|
|
24
|
+
const USES_FAHRENHEIT = [
|
|
25
|
+
'AG',
|
|
26
|
+
'BZ',
|
|
27
|
+
'VG',
|
|
28
|
+
'FM',
|
|
29
|
+
'MH',
|
|
30
|
+
'MS',
|
|
31
|
+
'KN',
|
|
32
|
+
'BS',
|
|
33
|
+
'CY',
|
|
34
|
+
'TC',
|
|
35
|
+
'US',
|
|
36
|
+
'LR',
|
|
37
|
+
'PW',
|
|
38
|
+
'KY',
|
|
39
|
+
];
|
|
23
40
|
|
|
24
41
|
export function addLocaleListener(listener: (event) => void): Subscription {
|
|
25
42
|
addEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener);
|
|
@@ -34,6 +51,7 @@ export function addCalendarListener(listener: (event) => void): Subscription {
|
|
|
34
51
|
remove: () => removeEventListener(WEB_LANGUAGE_CHANGE_EVENT, listener),
|
|
35
52
|
};
|
|
36
53
|
}
|
|
54
|
+
|
|
37
55
|
export function removeSubscription(subscription: Subscription) {
|
|
38
56
|
subscription.remove();
|
|
39
57
|
}
|
|
@@ -122,6 +140,7 @@ export default {
|
|
|
122
140
|
Array.from((10000).toLocaleString(languageTag)).filter((c) => c > '9' || c < '0')[0] ||
|
|
123
141
|
null; // using 1e5 instead of 1e4 since for some locales (like pl-PL) 1e4 does not use digit grouping
|
|
124
142
|
const decimalSeparator = (1.1).toLocaleString(languageTag).substring(1, 2);
|
|
143
|
+
const temperatureUnit = region ? regionToTemperatureUnit(region) : null;
|
|
125
144
|
|
|
126
145
|
return {
|
|
127
146
|
languageTag,
|
|
@@ -133,6 +152,7 @@ export default {
|
|
|
133
152
|
currencyCode: null,
|
|
134
153
|
currencySymbol: null,
|
|
135
154
|
regionCode: region || null,
|
|
155
|
+
temperatureUnit,
|
|
136
156
|
};
|
|
137
157
|
});
|
|
138
158
|
},
|
|
@@ -177,3 +197,7 @@ export default {
|
|
|
177
197
|
};
|
|
178
198
|
},
|
|
179
199
|
};
|
|
200
|
+
|
|
201
|
+
function regionToTemperatureUnit(region: string) {
|
|
202
|
+
return USES_FAHRENHEIT.includes(region) ? 'fahrenheit' : 'celsius';
|
|
203
|
+
}
|
package/src/Localization.ts
CHANGED
|
@@ -82,7 +82,7 @@ export const locales = ExpoLocalization.locales;
|
|
|
82
82
|
|
|
83
83
|
// @needsAudit
|
|
84
84
|
/**
|
|
85
|
-
* @deprecated Use Localization.
|
|
85
|
+
* @deprecated Use Localization.getCalendars() instead.
|
|
86
86
|
* The current time zone in display format.
|
|
87
87
|
* On Web time zone is calculated with Intl.DateTimeFormat().resolvedOptions().timeZone. For a
|
|
88
88
|
* better estimation you could use the moment-timezone package but it will add significant bloat to
|
|
@@ -117,7 +117,8 @@ export const region = ExpoLocalization.region;
|
|
|
117
117
|
"measurementSystem": "metric",
|
|
118
118
|
"currencyCode": "PLN",
|
|
119
119
|
"currencySymbol": "zł",
|
|
120
|
-
"regionCode": "PL"
|
|
120
|
+
"regionCode": "PL",
|
|
121
|
+
"temperatureUnit": "celsius"
|
|
121
122
|
}]`
|
|
122
123
|
*/
|
|
123
124
|
export const getLocales = ExpoLocalization.getLocales;
|
|
@@ -153,7 +154,8 @@ export const getCalendars = ExpoLocalization.getCalendars;
|
|
|
153
154
|
"measurementSystem": "metric",
|
|
154
155
|
"currencyCode": "PLN",
|
|
155
156
|
"currencySymbol": "zł",
|
|
156
|
-
"regionCode": "PL"
|
|
157
|
+
"regionCode": "PL",
|
|
158
|
+
"temperatureUnit": "celsius"
|
|
157
159
|
}]`
|
|
158
160
|
*/
|
|
159
161
|
export function useLocales() {
|
|
@@ -113,6 +113,12 @@ export type Locale = {
|
|
|
113
113
|
* Ask for user preferences if possible.
|
|
114
114
|
*/
|
|
115
115
|
measurementSystem: `metric` | `us` | `uk` | null;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The temperature unit used in the locale.
|
|
119
|
+
* Returns `null` if the region code is unknown.
|
|
120
|
+
*/
|
|
121
|
+
temperatureUnit: 'celsius' | 'fahrenheit' | null;
|
|
116
122
|
};
|
|
117
123
|
|
|
118
124
|
/**
|
package/tsconfig.json
CHANGED