Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[localization] Add default temperature unit to the locale #24059

Merged
merged 4 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/public/static/data/unversioned/expo-localization.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/expo-localization/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### 🎉 New features

- Added support for React Native 0.73. ([#24018](https://github.com/expo/expo/pull/24018) by [@kudo](https://github.com/kudo))
- 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))

### 🐛 Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ class LocalizationModule : Module() {
}
}

private fun getRegionCode(locale: Locale): String? {
val miuiRegion = getSystemProperty("ro.miui.region")
return if (!TextUtils.isEmpty(miuiRegion)) {
miuiRegion
} else {
getCountryCode(locale)
}
}

private fun getMeasurementSystem(locale: Locale): String? {
return if (VERSION.SDK_INT >= VERSION_CODES.P) {
when (LocaleData.getMeasurementSystem(ULocale.forLocale(locale))) {
Expand Down Expand Up @@ -167,6 +158,7 @@ class LocalizationModule : Module() {

// currency symbol can be localized to display locale (1st on the list) or to the locale for the currency (as done here).
"currencySymbol" to Currency.getInstance(locale).getSymbol(locale),
"temperatureUnit" to getTemperatureUnit(locale),
)
)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import java.util.*

val USES_IMPERIAL = listOf("US", "LR", "MM")

// https://wisevoter.com/country-rankings/countries-that-use-fahrenheit/
val USES_FAHRENHEIT = listOf("AG", "BZ", "VG", "FM", "MH", "MS", "KN", "BS", "CY", "TC", "US", "LR", "PW", "KY")

val ISOCurrencyCodes: Array<String> by lazy {
Currency.getAvailableCurrencies().map { it.currencyCode as String }.toTypedArray()
}
Expand Down Expand Up @@ -32,3 +35,17 @@ fun getCurrencyCode(locale: Locale): String? {
currency?.currencyCode
}.getOrNull()
}

fun getRegionCode(locale: Locale): String? {
val miuiRegion = getSystemProperty("ro.miui.region")
return if (!TextUtils.isEmpty(miuiRegion)) {
behenate marked this conversation as resolved.
Show resolved Hide resolved
miuiRegion
} else {
getCountryCode(locale)
}
}

fun getTemperatureUnit(locale: Locale): String? {
val countryCode = getRegionCode(locale) ?: return null
return if (USES_FAHRENHEIT.contains(countryCode)) "fahrenheit" else "celsius"
}
2 changes: 1 addition & 1 deletion packages/expo-localization/build/ExpoLocalization.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions packages/expo-localization/build/ExpoLocalization.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-localization/build/ExpoLocalization.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/expo-localization/build/Localization.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-localization/build/Localization.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/expo-localization/build/Localization.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-localization/build/Localization.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/expo-localization/build/Localization.types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading