@react-native-gpui/localize 0.0.0-stage → 3.7.0-alpha.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@react-native-gpui/localize` are listed here. Each version's section becomes the notes of its GitHub release.
4
+
5
+ ## 3.7.0-alpha.1 - 2026-11-27
6
+
7
+ - First release, for `react-native-localize` 3.7.x: reports the locales, country, currencies, calendar, units, number format and time zone of the machine.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Streetwriters
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # @react-native-gpui/localize
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Adapter for [`react-native-localize`](https://github.com/zoontek/react-native-localize) (MIT): reports the locales, country, currencies, calendar, units, number format and time zone of the machine.
4
+
5
+ ## About
6
+
7
+ This package is the desktop adapter for [`react-native-localize`](https://github.com/zoontek/react-native-localize) 3.7. Install the original library next to it; its JavaScript runs unchanged on desktop, and this package provides the native side. The upstream library is licensed under the MIT license.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install react-native-localize @react-native-gpui/localize
13
+ ```
14
+
15
+ The module is autolinked on desktop.
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import * as RNLocalize from 'react-native-localize';
21
+
22
+ const locales = RNLocalize.getLocales();
23
+ ```
24
+
25
+ ## Platforms
26
+
27
+ macOS is tested. Windows and Linux are not tested yet.
28
+
29
+ ## Limitations
30
+
31
+ The values are derived from the system locale (and the time zone from the system). The currency, clock, unit and separator tables cover common countries only, and the calendar is always Gregorian. `usesAutoDateAndTime` and `usesAutoTimeZone` return `undefined`. `openAppLanguageSettings` opens System Settings on macOS.
32
+
33
+ ## License
34
+
35
+ MIT. See [LICENSE](LICENSE). The upstream library, [`react-native-localize`](https://github.com/zoontek/react-native-localize), is MIT licensed.
@@ -0,0 +1,12 @@
1
+ [package]
2
+ name = "rn-gpui-localize"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ rn-gpui-module = { version = "0.1" }
8
+ sys-locale = "0.3"
9
+ iana-time-zone = "0.1"
10
+
11
+ [build-dependencies]
12
+ rn-gpui-module-build = { version = "0.1" }
@@ -0,0 +1,3 @@
1
+ fn main() {
2
+ rn_gpui_module_build::generate(&["../src/NativeRNLocalize.ts"]);
3
+ }
@@ -0,0 +1,188 @@
1
+ rn_gpui_module::include_specs!();
2
+
3
+ use rn_gpui_module::{ModuleError, Value};
4
+
5
+ pub struct RNLocalize;
6
+
7
+ struct Region {
8
+ country: String,
9
+ language: String,
10
+ script: Option<String>,
11
+ }
12
+
13
+ fn region() -> Region {
14
+ let tag = sys_locale::get_locale().unwrap_or_else(|| "en-US".into());
15
+ let parts: Vec<&str> = tag.split(['-', '_']).collect();
16
+ let language = parts.first().copied().unwrap_or("en").to_lowercase();
17
+ let script = parts
18
+ .get(1)
19
+ .filter(|part| part.len() == 4)
20
+ .map(|part| part.to_string());
21
+ let country = parts
22
+ .iter()
23
+ .skip(1)
24
+ .find(|part| part.len() == 2 || part.len() == 3 && part.chars().all(|c| c.is_ascii_digit()))
25
+ .map(|part| part.to_uppercase())
26
+ .unwrap_or_else(|| default_country(&language).into());
27
+ Region { country, language, script }
28
+ }
29
+
30
+ fn default_country(language: &str) -> &'static str {
31
+ match language {
32
+ "de" => "DE",
33
+ "fr" => "FR",
34
+ "es" => "ES",
35
+ "it" => "IT",
36
+ "ja" => "JP",
37
+ "zh" => "CN",
38
+ "pt" => "BR",
39
+ "ru" => "RU",
40
+ "ko" => "KR",
41
+ "nl" => "NL",
42
+ "sv" => "SE",
43
+ "ar" => "EG",
44
+ _ => "US",
45
+ }
46
+ }
47
+
48
+ fn is_rtl(language: &str) -> bool {
49
+ matches!(language, "ar" | "he" | "fa" | "ur" | "ps" | "sd" | "yi" | "ug")
50
+ }
51
+
52
+ fn metric_country(country: &str) -> bool {
53
+ !matches!(country, "US" | "LR" | "MM")
54
+ }
55
+
56
+ fn currency(country: &str) -> &'static str {
57
+ match country {
58
+ "US" => "USD",
59
+ "GB" => "GBP",
60
+ "JP" => "JPY",
61
+ "CN" => "CNY",
62
+ "IN" => "INR",
63
+ "CA" => "CAD",
64
+ "AU" => "AUD",
65
+ "CH" => "CHF",
66
+ "BR" => "BRL",
67
+ "RU" => "RUB",
68
+ "KR" => "KRW",
69
+ "MX" => "MXN",
70
+ "SE" => "SEK",
71
+ "NO" => "NOK",
72
+ "DK" => "DKK",
73
+ "PL" => "PLN",
74
+ "EG" => "EGP",
75
+ "SA" => "SAR",
76
+ "AE" => "AED",
77
+ "DE" | "FR" | "ES" | "IT" | "NL" | "BE" | "AT" | "PT" | "IE" | "FI" | "GR" => "EUR",
78
+ _ => "USD",
79
+ }
80
+ }
81
+
82
+ fn twelve_hour_country(country: &str) -> bool {
83
+ matches!(country, "US" | "CA" | "AU" | "NZ" | "IN" | "PH" | "PK" | "EG" | "SA")
84
+ }
85
+
86
+ fn open_settings_url() -> bool {
87
+ #[cfg(target_os = "macos")]
88
+ {
89
+ return std::process::Command::new("open")
90
+ .arg("x-apple.systempreferences:com.apple.Localization-Settings.extension")
91
+ .status()
92
+ .map(|status| status.success())
93
+ .unwrap_or(false);
94
+ }
95
+ #[allow(unreachable_code)]
96
+ false
97
+ }
98
+
99
+ impl NativeRNLocalizeSpec for RNLocalize {
100
+ fn new(_events: NativeRNLocalizeEvents) -> Self {
101
+ Self
102
+ }
103
+
104
+ fn get_calendar(&self) -> Result<String, ModuleError> {
105
+ Ok("gregorian".into())
106
+ }
107
+
108
+ fn get_country(&self) -> Result<String, ModuleError> {
109
+ Ok(region().country)
110
+ }
111
+
112
+ fn get_currencies(&self) -> Result<Vec<String>, ModuleError> {
113
+ Ok(vec![currency(&region().country).into()])
114
+ }
115
+
116
+ fn get_locales(&self) -> Result<Vec<Value>, ModuleError> {
117
+ let mut tags: Vec<String> = sys_locale::get_locales().collect();
118
+ if tags.is_empty() {
119
+ tags.push(sys_locale::get_locale().unwrap_or_else(|| "en-US".into()));
120
+ }
121
+ Ok(tags
122
+ .into_iter()
123
+ .map(|tag| {
124
+ let tag = tag.replace('_', "-");
125
+ let parts: Vec<&str> = tag.split('-').collect();
126
+ let language = parts.first().copied().unwrap_or("en").to_lowercase();
127
+ let country = parts
128
+ .iter()
129
+ .skip(1)
130
+ .find(|part| part.len() == 2)
131
+ .map(|part| part.to_uppercase())
132
+ .unwrap_or_else(|| default_country(&language).into());
133
+ Value::object([
134
+ ("languageTag", Value::String(tag.clone())),
135
+ ("languageCode", Value::String(language.clone())),
136
+ ("countryCode", Value::String(country)),
137
+ ("isRTL", Value::Bool(is_rtl(&language))),
138
+ ])
139
+ })
140
+ .collect())
141
+ }
142
+
143
+ fn get_number_format_settings(&self) -> Result<Value, ModuleError> {
144
+ let region = region();
145
+ let comma = matches!(
146
+ region.language.as_str(),
147
+ "de" | "fr" | "es" | "it" | "nl" | "pt" | "ru" | "sv" | "da" | "fi" | "nb" | "pl" | "tr"
148
+ );
149
+ let (decimal, grouping) = if comma { (",", ".") } else { (".", ",") };
150
+ let _ = region.script;
151
+ Ok(Value::object([
152
+ ("decimalSeparator", Value::String(decimal.into())),
153
+ ("groupingSeparator", Value::String(grouping.into())),
154
+ ]))
155
+ }
156
+
157
+ fn get_temperature_unit(&self) -> Result<String, ModuleError> {
158
+ Ok(if metric_country(&region().country) { "celsius" } else { "fahrenheit" }.into())
159
+ }
160
+
161
+ fn get_time_zone(&self) -> Result<String, ModuleError> {
162
+ Ok(iana_time_zone::get_timezone().unwrap_or_else(|_| "UTC".into()))
163
+ }
164
+
165
+ fn uses24_hour_clock(&self) -> Result<bool, ModuleError> {
166
+ Ok(!twelve_hour_country(&region().country))
167
+ }
168
+
169
+ fn uses_metric_system(&self) -> Result<bool, ModuleError> {
170
+ Ok(metric_country(&region().country))
171
+ }
172
+
173
+ fn uses_auto_date_and_time(&self) -> Result<Option<bool>, ModuleError> {
174
+ Ok(None)
175
+ }
176
+
177
+ fn uses_auto_time_zone(&self) -> Result<Option<bool>, ModuleError> {
178
+ Ok(None)
179
+ }
180
+
181
+ async fn open_app_language_settings(&self) -> Result<bool, ModuleError> {
182
+ Ok(open_settings_url())
183
+ }
184
+ }
185
+
186
+ pub fn rn_gpui_register() {
187
+ rn_gpui_module::register(native_rn_localize_module::<RNLocalize>());
188
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@react-native-gpui/localize",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "3.7.0-alpha.1",
4
+ "description": "Adapter for react-native-localize (MIT): the locale, calendar, units and time zone of the machine",
5
+ "license": "MIT",
6
+ "main": "src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "desktop",
10
+ "react-native.config.js",
11
+ "README.md",
12
+ "CHANGELOG.md",
13
+ "LICENSE"
14
+ ],
15
+ "codegenConfig": {
16
+ "name": "RNLocalizeSpec",
17
+ "type": "modules",
18
+ "jsSrcsDir": "src"
19
+ },
20
+ "peerDependencies": {
21
+ "react-native": "0.87.x",
22
+ "react-native-localize": "3.7.x"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
27
+ "directory": "modules/localize"
28
+ },
29
+ "homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/localize#readme",
30
+ "bugs": {
31
+ "url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "tag": "latest"
36
+ }
37
+ }
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ desktop: {
5
+ crate: 'rn-gpui-localize',
6
+ },
7
+ },
8
+ },
9
+ };
@@ -0,0 +1,19 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ getCalendar(): string;
6
+ getCountry(): string;
7
+ getCurrencies(): string[];
8
+ getLocales(): Object[];
9
+ getNumberFormatSettings(): Object;
10
+ getTemperatureUnit(): string;
11
+ getTimeZone(): string;
12
+ uses24HourClock(): boolean;
13
+ usesMetricSystem(): boolean;
14
+ usesAutoDateAndTime(): boolean | null;
15
+ usesAutoTimeZone(): boolean | null;
16
+ openAppLanguageSettings(): Promise<boolean>;
17
+ }
18
+
19
+ export default TurboModuleRegistry.getEnforcing<Spec>('RNLocalize');
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};