From 4778d7a66a3be6d08368f1d05ea4ee649ba1793b Mon Sep 17 00:00:00 2001 From: qi-hey <63509385+qi-hey@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:33:57 +0800 Subject: [PATCH 1/3] fix(mobile): apply Android language changes immediately --- apps/mobile/src/i18n/native-locale.test.ts | 65 +++++++++++ patches/gt-react-native@11.4.18.patch | 129 +++++++++++++++++++++ pnpm-lock.yaml | 5 +- pnpm-workspace.yaml | 1 + 4 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 apps/mobile/src/i18n/native-locale.test.ts create mode 100644 patches/gt-react-native@11.4.18.patch diff --git a/apps/mobile/src/i18n/native-locale.test.ts b/apps/mobile/src/i18n/native-locale.test.ts new file mode 100644 index 0000000000000..c09c42f61f8d8 --- /dev/null +++ b/apps/mobile/src/i18n/native-locale.test.ts @@ -0,0 +1,65 @@ +import * as NodeChildProcess from "node:child_process"; +import * as NodeURL from "node:url"; +import { expect, it } from "vite-plus/test"; + +it("uses the new Android locale before native storage finishes writing it", () => { + // Load the real GT store in a subprocess because mobile's Vite config replaces GT. + const output = NodeChildProcess.execFileSync( + process.execPath, + [ + "--input-type=module", + "-e", + ` + import { createRequire, registerHooks } from "node:module"; + import { pathToFileURL } from "node:url"; + + const require = createRequire(process.cwd() + "/package.json"); + const gtEntry = pathToFileURL(require.resolve("gt-react-native")); + const androidBridge = "data:text/javascript," + encodeURIComponent(\` + const preferences = new Map(); + export const pending = []; + export const Platform = { OS: "android" }; + export const TurboModuleRegistry = { + getEnforcing: () => ({ + getNativeLocales: () => ["en-US"], + nativeStoreGet: (key) => preferences.get(key) ?? null, + nativeStoreSet: (key, value) => { + pending.push(() => preferences.set(key, value)); + }, + }), + }; + \`); + const hooks = registerHooks({ + resolve(specifier, context, nextResolve) { + return specifier === "react-native" + ? { url: androidBridge, shortCircuit: true } + : nextResolve(specifier, context); + }, + }); + const { initializeGT } = await import(new URL("./setup/initializeGT.js", gtEntry)); + const { NativeConditionStore } = await import( + new URL("./condition-store/NativeConditionStore.js", gtEntry) + ); + const { pending } = await import(androidBridge); + hooks.deregister(); + + initializeGT({ + defaultLocale: "en", + locales: ["en", "zh"], + loadTranslations: async (locale) => require("./src/i18n/translations/" + locale + ".json"), + }); + const coreEntry = createRequire(gtEntry).resolve("@generaltranslation/react-core/pure"); + const { getReactI18nCache } = await import(pathToFileURL(coreEntry)); + const cache = getReactI18nCache(); + await cache.loadTranslations("zh"); + + new NativeConditionStore({ locale: "en" }); + for (const apply of pending.splice(0)) apply(); + const locale = new NativeConditionStore({ locale: "zh" }).getLocale(); + console.log(cache.lookupTranslation(locale, "General", { $format: "ICU" }) ?? "General"); + `, + ], + { cwd: NodeURL.fileURLToPath(new URL("../../", import.meta.url)), encoding: "utf8" }, + ); + expect(output.trim()).toBe("\u901a\u7528"); +}); diff --git a/patches/gt-react-native@11.4.18.patch b/patches/gt-react-native@11.4.18.patch new file mode 100644 index 0000000000000..03480dff19359 --- /dev/null +++ b/patches/gt-react-native@11.4.18.patch @@ -0,0 +1,129 @@ +diff --git a/dist/commonjs/condition-store/NativeConditionStore.js b/dist/commonjs/condition-store/NativeConditionStore.js +index 83349e43d9cad0c02a5d076a56c66d7d26943206..ac31f5e92bdd3b9f1e3346e6800887bc85d934d3 100644 +--- a/dist/commonjs/condition-store/NativeConditionStore.js ++++ b/dist/commonjs/condition-store/NativeConditionStore.js +@@ -11,20 +11,21 @@ let _generaltranslation_react_core_pure = require("@generaltranslation/react-cor + */ + var NativeConditionStore = class { + customReload; ++ locale; + constructor(config) { + this.customReload = config._reload ?? (() => void 0); +- this.updateLocale(config.locale ?? require_utils_getLocale.getLocale()); ++ this.locale = require_utils_resolveLocale.resolveLocale(config.locale ?? require_utils_getLocale.getLocale()); ++ require_utils_nativeStore.nativeStoreSet(getLocaleStoreKey(), this.locale); + const region = require_utils_getInitialNativeConditions.getInitialRegion({ region: config.region }); + if (region !== void 0) this.updateRegion(region); + this.updateEnableI18n(require_utils_getInitialNativeConditions.getInitialEnableI18n({ enableI18n: config.enableI18n })); + } + getLocale = () => { +- return require_utils_getLocale.getLocale(); ++ return this.locale; + }; + setLocale = (locale) => { +- const nextLocale = require_utils_resolveLocale.resolveLocale(locale); +- require_utils_nativeStore.nativeStoreSet(getLocaleStoreKey(), nextLocale); +- this.reload({ locale: nextLocale }); ++ this.updateLocale(locale); ++ this.reload({ locale: this.locale }); + }; + getRegion = () => { + return require_utils_nativeStore.nativeStoreGet(getRegionStoreKey()) || void 0; +@@ -41,7 +42,8 @@ var NativeConditionStore = class { + this.reload({ enableI18n }); + }; + updateLocale = (locale) => { +- require_utils_nativeStore.nativeStoreSet(getLocaleStoreKey(), require_utils_resolveLocale.resolveLocale(locale)); ++ this.locale = require_utils_resolveLocale.resolveLocale(locale); ++ require_utils_nativeStore.nativeStoreSet(getLocaleStoreKey(), this.locale); + }; + updateRegion = (region) => { + require_utils_nativeStore.nativeStoreSet(getRegionStoreKey(), region ?? ""); +diff --git a/dist/module/condition-store/NativeConditionStore.js b/dist/module/condition-store/NativeConditionStore.js +index aeadfee50fb03ee827b9326486eb39ef46b0921c..3d08229ee6acd065c868a14a8647343e37286121 100644 +--- a/dist/module/condition-store/NativeConditionStore.js ++++ b/dist/module/condition-store/NativeConditionStore.js +@@ -9,20 +9,21 @@ import { getI18nConfig } from "@generaltranslation/react-core/pure"; + */ + var NativeConditionStore = class { + customReload; ++ locale; + constructor(config) { + this.customReload = config._reload ?? (() => void 0); +- this.updateLocale(config.locale ?? getLocale()); ++ this.locale = resolveLocale(config.locale ?? getLocale()); ++ nativeStoreSet(getLocaleStoreKey(), this.locale); + const region = getInitialRegion({ region: config.region }); + if (region !== void 0) this.updateRegion(region); + this.updateEnableI18n(getInitialEnableI18n({ enableI18n: config.enableI18n })); + } + getLocale = () => { +- return getLocale(); ++ return this.locale; + }; + setLocale = (locale) => { +- const nextLocale = resolveLocale(locale); +- nativeStoreSet(getLocaleStoreKey(), nextLocale); +- this.reload({ locale: nextLocale }); ++ this.updateLocale(locale); ++ this.reload({ locale: this.locale }); + }; + getRegion = () => { + return nativeStoreGet(getRegionStoreKey()) || void 0; +@@ -39,7 +40,8 @@ var NativeConditionStore = class { + this.reload({ enableI18n }); + }; + updateLocale = (locale) => { +- nativeStoreSet(getLocaleStoreKey(), resolveLocale(locale)); ++ this.locale = resolveLocale(locale); ++ nativeStoreSet(getLocaleStoreKey(), this.locale); + }; + updateRegion = (region) => { + nativeStoreSet(getRegionStoreKey(), region ?? ""); +diff --git a/src/condition-store/NativeConditionStore.ts b/src/condition-store/NativeConditionStore.ts +index 3f300ed703db4d35e2118bbfe01430f370201f9e..18c3af21acaf3e6b4c7de2b8341c6847f8de1b73 100644 +--- a/src/condition-store/NativeConditionStore.ts ++++ b/src/condition-store/NativeConditionStore.ts +@@ -29,11 +29,14 @@ export type ReloadType = (state: NativeConditionStoreState) => void; + */ + export class NativeConditionStore implements WritableConditionStoreInterface { + private customReload: ReloadType; ++ private locale: string; + + constructor(config: NativeConditionStoreParams) { + this.customReload = config._reload ?? (() => undefined); + +- this.updateLocale(config.locale ?? getLocale()); ++ // Android's void TurboModule setter writes asynchronously. ++ this.locale = resolveLocale(config.locale ?? getLocale()); ++ nativeStoreSet(getLocaleStoreKey(), this.locale); + const region = getInitialRegion({ + region: config.region, + }); +@@ -48,13 +51,12 @@ export class NativeConditionStore implements WritableConditionStoreInterface { + } + + getLocale = (): string => { +- return getLocale(); ++ return this.locale; + }; + + setLocale = (locale: LocaleCandidates): void => { +- const nextLocale = resolveLocale(locale); +- nativeStoreSet(getLocaleStoreKey(), nextLocale); +- this.reload({ locale: nextLocale }); ++ this.updateLocale(locale); ++ this.reload({ locale: this.locale }); + }; + + getRegion = (): string | undefined => { +@@ -76,7 +78,8 @@ export class NativeConditionStore implements WritableConditionStoreInterface { + }; + + updateLocale = (locale: LocaleCandidates): void => { +- nativeStoreSet(getLocaleStoreKey(), resolveLocale(locale)); ++ this.locale = resolveLocale(locale); ++ nativeStoreSet(getLocaleStoreKey(), this.locale); + }; + + updateRegion = (region: string | undefined): void => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7dd5d6b6b8116..194c3f3f998ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -385,6 +385,7 @@ patchedDependencies: expo-sharing@58.0.22: 321a86e1471e34c53f1f2937fbb4304ea3f7b7a78ad9e4d35febc2b9e73e9688 expo-video@58.0.13: e80ec3ef8c4af50a607beea1c0917e71ba679844efdb702b45d17a5f03cf466c expo-widgets@58.0.27: 0e26817ca487a5156bcc9499f7db2e99a7d102f4a53b6b738f00552958774c86 + gt-react-native@11.4.18: 9e9babb38642464db18e12d1a9f3531acda06056cfee82ee0261ba8bdc1aefaa mdast-util-math@3.0.0: afe6b2c89e1eaddfd3c90cf2723f12c9a17d513e65beff51653781486013251c mdast-util-to-hast@13.2.1: 57ea46c73aea3c876ab8d351fe0482ddd081dcb4a0610576e399dbe5eb59d2b1 micromark-extension-gfm-table@2.1.1: 9ad23a530e45d9f83cba1da8654fe16d5af8b59d5c73d5c7a7c91fd25b9be1d8 @@ -749,7 +750,7 @@ importers: version: 58.0.27(patch_hash=0e26817ca487a5156bcc9499f7db2e99a7d102f4a53b6b738f00552958774c86)(@babel/core@7.29.7(supports-color@8.1.1))(expo@58.0.23)(react-dom@19.3.0(react@19.3.0))(react-native-worklets@0.13.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0) gt-react-native: specifier: 11.4.18 - version: 11.4.18(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0) + version: 11.4.18(patch_hash=9e9babb38642464db18e12d1a9f3531acda06056cfee82ee0261ba8bdc1aefaa)(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0) pele: specifier: 'catalog:' version: 1.8.0 @@ -20093,7 +20094,7 @@ snapshots: '@generaltranslation/format': 0.1.9 generaltranslation: 9.5.9 - gt-react-native@11.4.18(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0): + gt-react-native@11.4.18(patch_hash=9e9babb38642464db18e12d1a9f3531acda06056cfee82ee0261ba8bdc1aefaa)(react-native@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.1(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0): dependencies: '@formatjs/intl-datetimeformat': 6.18.2 '@formatjs/intl-displaynames': 6.8.13 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 04f881d6f124d..4a20c56443063 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -284,6 +284,7 @@ patchedDependencies: react-native-svg@15.16.1: patches/react-native-svg@15.16.1.patch # Android: double-tap zoom no longer cancels itself, and taps near a link open it. react-native-pdf-jsi@6.1.0: patches/react-native-pdf-jsi@6.1.0.patch + gt-react-native@11.4.18: patches/gt-react-native@11.4.18.patch # Unmet peers fail resolution, so a pin outside a dependency's peer range is # caught when the lockfile changes instead of scrolling past as a warning. From 6123f1e37a789eae3530fef6908bf73667c61fb8 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 06:59:14 +0000 Subject: [PATCH 2/3] test(mobile): assert the resolved locale directly Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/i18n/native-locale.test.ts | 16 +++------------- pnpm-workspace.yaml | 2 ++ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/mobile/src/i18n/native-locale.test.ts b/apps/mobile/src/i18n/native-locale.test.ts index c09c42f61f8d8..781eae9e898fb 100644 --- a/apps/mobile/src/i18n/native-locale.test.ts +++ b/apps/mobile/src/i18n/native-locale.test.ts @@ -43,23 +43,13 @@ it("uses the new Android locale before native storage finishes writing it", () = const { pending } = await import(androidBridge); hooks.deregister(); - initializeGT({ - defaultLocale: "en", - locales: ["en", "zh"], - loadTranslations: async (locale) => require("./src/i18n/translations/" + locale + ".json"), - }); - const coreEntry = createRequire(gtEntry).resolve("@generaltranslation/react-core/pure"); - const { getReactI18nCache } = await import(pathToFileURL(coreEntry)); - const cache = getReactI18nCache(); - await cache.loadTranslations("zh"); - + initializeGT({ defaultLocale: "en", locales: ["en", "zh"] }); new NativeConditionStore({ locale: "en" }); for (const apply of pending.splice(0)) apply(); - const locale = new NativeConditionStore({ locale: "zh" }).getLocale(); - console.log(cache.lookupTranslation(locale, "General", { $format: "ICU" }) ?? "General"); + console.log(new NativeConditionStore({ locale: "zh" }).getLocale()); `, ], { cwd: NodeURL.fileURLToPath(new URL("../../", import.meta.url)), encoding: "utf8" }, ); - expect(output.trim()).toBe("\u901a\u7528"); + expect(output.trim()).toBe("zh"); }); diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4a20c56443063..a1e6113680377 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -284,6 +284,8 @@ patchedDependencies: react-native-svg@15.16.1: patches/react-native-svg@15.16.1.patch # Android: double-tap zoom no longer cancels itself, and taps near a link open it. react-native-pdf-jsi@6.1.0: patches/react-native-pdf-jsi@6.1.0.patch + # Android: a language change applies at once instead of reading back the old locale + # before the async native write lands. gt-react-native@11.4.18: patches/gt-react-native@11.4.18.patch # Unmet peers fail resolution, so a pin outside a dependency's peer range is From 471c5b855c4a1c4f1743f375b99258eab8d341ef Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 05:53:22 +0000 Subject: [PATCH 3/3] build(mobile): pin patched gt-react-native in overrides Lockfile-free release installs could otherwise resolve past the patched version. Co-Authored-By: Claude Opus 5.5 --- pnpm-lock.yaml | 1 + pnpm-workspace.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d24294f90ae3b..3f25d4807efe6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -296,6 +296,7 @@ overrides: react-native-pdf-jsi: 6.1.0 react-native-webview: 14.0.1 react-native-svg: 15.16.1 + gt-react-native: 11.4.18 app-builder-lib: 26.16.1 electron-updater: 6.8.9 expo-modules-core: 58.0.30 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index fd94dffa9ca3d..d90784356120f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -128,6 +128,7 @@ overrides: react-native-pdf-jsi: 6.1.0 react-native-webview: 14.0.1 react-native-svg: 15.16.1 + gt-react-native: 11.4.18 app-builder-lib: 26.16.1 electron-updater: 6.8.9 expo-modules-core: 58.0.30