Skip to content

Commit 5b6c463

Browse files
authored
3.2.0 (#259)
1 parent a96c20f commit 5b6c463

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

android/src/main/java/com/zoontek/rnlocalize/RNLocalizeModuleImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import android.annotation.SuppressLint;
44
import android.content.ContentResolver;
55
import android.content.res.Configuration;
6+
import android.icu.number.LocalizedNumberFormatter;
7+
import android.icu.number.NumberFormatter;
8+
import android.icu.util.MeasureUnit;
69
import android.os.Build;
710
import android.provider.Settings;
811
import android.text.TextUtils;
@@ -229,6 +232,23 @@ public class RNLocalizeModuleImpl {
229232
}
230233

231234
public static @NonNull String getTemperatureUnit(ReactApplicationContext reactContext) {
235+
// https://github.com/androidx/androidx/blob/androidx-main/core/core/src/main/java/androidx/core/text/util/LocalePreferences.java
236+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
237+
Locale systemLocale = getSystemLocale(reactContext);
238+
239+
LocalizedNumberFormatter formatter = NumberFormatter.with()
240+
.usage("weather")
241+
.unit(MeasureUnit.CELSIUS)
242+
.locale(systemLocale);
243+
244+
String unit = formatter
245+
.format(1)
246+
.getOutputUnit()
247+
.getIdentifier();
248+
249+
return unit.startsWith("fahrenhe") ? "fahrenheit" : "celsius";
250+
}
251+
232252
String currentCountryCode = getCountry(reactContext);
233253
return USES_FAHRENHEIT.contains(currentCountryCode) ? "fahrenheit" : "celsius";
234254
}

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ PODS:
11111111
- React-jsi (= 0.73.2)
11121112
- React-logger (= 0.73.2)
11131113
- React-perflogger (= 0.73.2)
1114-
- RNLocalize (3.1.0):
1114+
- RNLocalize (3.2.0):
11151115
- React-Core
11161116
- SocketRocket (0.6.1)
11171117
- Yoga (1.14.0)
@@ -1369,7 +1369,7 @@ SPEC CHECKSUMS:
13691369
React-runtimescheduler: df8945a656356ff10f58f65a70820478bfcf33ad
13701370
React-utils: f5bc61e7ea3325c0732ae2d755f4441940163b85
13711371
ReactCommon: 45b5d4f784e869c44a6f5a8fad5b114ca8f78c53
1372-
RNLocalize: e8694475db034bf601e17bd3dfa8986565e769eb
1372+
RNLocalize: b77875884750cb6a58cd6865863fe2ba2729b72b
13731373
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
13741374
Yoga: 13c8ef87792450193e117976337b8527b49e8c03
13751375

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"node": ">=18"
77
},
88
"scripts": {
9+
"pod-install": "cd ios && bundle install && bundle exec pod install && cd ..",
910
"clean": "rm -rf ./node_modules ./ios/Pods",
1011
"install-macos": "yarn add [email protected]",
1112
"preinstall": "cd .. && yarn && yarn build && cd example",
@@ -31,7 +32,6 @@
3132
"@types/react": "^18.2.47",
3233
"babel-loader": "^9.1.3",
3334
"babel-plugin-module-resolver": "^5.0.0",
34-
"pod-install": "^0.1.39",
3535
"typescript": "^5.3.3",
3636
"webpack": "^5.89.0",
3737
"webpack-cli": "^5.1.4",

example/yarn.lock

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,11 +4622,6 @@ pkg-up@^3.1.0:
46224622
dependencies:
46234623
find-up "^3.0.0"
46244624

4625-
pod-install@^0.1.39:
4626-
version "0.1.39"
4627-
resolved "https://registry.yarnpkg.com/pod-install/-/pod-install-0.1.39.tgz#853a0585bafbd332c2ca6543854fd4919958cfb3"
4628-
integrity sha512-0kVvdLYe0CtfJEr+ISvTMxAEB0UF4JMRToPjuu9xAAq1mEqA2Ql5u7uLWX1m45BMM+7NfU4LnBbnfNjmQE9GCw==
4629-
46304625
postcss-value-parser@^4.2.0:
46314626
version "4.2.0"
46324627
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
@@ -4768,7 +4763,8 @@ react-is@^17.0.1:
47684763
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
47694764

47704765
"react-native-localize@link:..":
4771-
version "3.0.6"
4766+
version "0.0.0"
4767+
uid ""
47724768

47734769
47744770
version "0.19.10"

ios/RNLocalize.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ - (NSString *)getTemperatureUnitImpl {
154154

155155
[formatter setLocale:currentLocale];
156156

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-localize",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"license": "MIT",
55
"description": "A toolbox for your React Native app localization.",
66
"author": "Mathieu Acthernoene <[email protected]>",

0 commit comments

Comments
 (0)