Skip to content

Commit

Permalink
3.2.0 (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek authored Jun 9, 2024
1 parent a96c20f commit 5b6c463
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.res.Configuration;
import android.icu.number.LocalizedNumberFormatter;
import android.icu.number.NumberFormatter;
import android.icu.util.MeasureUnit;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
Expand Down Expand Up @@ -229,6 +232,23 @@ public class RNLocalizeModuleImpl {
}

public static @NonNull String getTemperatureUnit(ReactApplicationContext reactContext) {
// https://github.com/androidx/androidx/blob/androidx-main/core/core/src/main/java/androidx/core/text/util/LocalePreferences.java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Locale systemLocale = getSystemLocale(reactContext);

LocalizedNumberFormatter formatter = NumberFormatter.with()
.usage("weather")
.unit(MeasureUnit.CELSIUS)
.locale(systemLocale);

String unit = formatter
.format(1)
.getOutputUnit()
.getIdentifier();

return unit.startsWith("fahrenhe") ? "fahrenheit" : "celsius";
}

String currentCountryCode = getCountry(reactContext);
return USES_FAHRENHEIT.contains(currentCountryCode) ? "fahrenheit" : "celsius";
}
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ PODS:
- React-jsi (= 0.73.2)
- React-logger (= 0.73.2)
- React-perflogger (= 0.73.2)
- RNLocalize (3.1.0):
- RNLocalize (3.2.0):
- React-Core
- SocketRocket (0.6.1)
- Yoga (1.14.0)
Expand Down Expand Up @@ -1369,7 +1369,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: df8945a656356ff10f58f65a70820478bfcf33ad
React-utils: f5bc61e7ea3325c0732ae2d755f4441940163b85
ReactCommon: 45b5d4f784e869c44a6f5a8fad5b114ca8f78c53
RNLocalize: e8694475db034bf601e17bd3dfa8986565e769eb
RNLocalize: b77875884750cb6a58cd6865863fe2ba2729b72b
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: 13c8ef87792450193e117976337b8527b49e8c03

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"node": ">=18"
},
"scripts": {
"pod-install": "cd ios && bundle install && bundle exec pod install && cd ..",
"clean": "rm -rf ./node_modules ./ios/Pods",
"install-macos": "yarn add [email protected]",
"preinstall": "cd .. && yarn && yarn build && cd example",
Expand All @@ -31,7 +32,6 @@
"@types/react": "^18.2.47",
"babel-loader": "^9.1.3",
"babel-plugin-module-resolver": "^5.0.0",
"pod-install": "^0.1.39",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
Expand Down
8 changes: 2 additions & 6 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4622,11 +4622,6 @@ pkg-up@^3.1.0:
dependencies:
find-up "^3.0.0"

pod-install@^0.1.39:
version "0.1.39"
resolved "https://registry.yarnpkg.com/pod-install/-/pod-install-0.1.39.tgz#853a0585bafbd332c2ca6543854fd4919958cfb3"
integrity sha512-0kVvdLYe0CtfJEr+ISvTMxAEB0UF4JMRToPjuu9xAAq1mEqA2Ql5u7uLWX1m45BMM+7NfU4LnBbnfNjmQE9GCw==

postcss-value-parser@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
Expand Down Expand Up @@ -4768,7 +4763,8 @@ react-is@^17.0.1:
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==

"react-native-localize@link:..":
version "3.0.6"
version "0.0.0"
uid ""

[email protected]:
version "0.19.10"
Expand Down
2 changes: 1 addition & 1 deletion ios/RNLocalize.mm
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ - (NSString *)getTemperatureUnitImpl {

[formatter setLocale:currentLocale];

NSMeasurement *temperature = [[NSMeasurement alloc] initWithDoubleValue:42.0 unit:[NSUnitTemperature celsius]];
NSMeasurement *temperature = [[NSMeasurement alloc] initWithDoubleValue:1.0 unit:[NSUnitTemperature celsius]];
NSString *formatted = [formatter stringFromMeasurement:temperature];
NSString *unitCharacter = [formatted substringFromIndex:[formatted length] - 1];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-localize",
"version": "3.1.0",
"version": "3.2.0",
"license": "MIT",
"description": "A toolbox for your React Native app localization.",
"author": "Mathieu Acthernoene <[email protected]>",
Expand Down

0 comments on commit 5b6c463

Please sign in to comment.