Skip to content

Commit 3615ebe

Browse files
committed
Fix offering locales that are not shipped when there is no remote base
Choosing a language other than English or Chinese makes the frontend fetch `./locales/<locale>.json`, which React Native never ships: only `bundled_devtools_locales` (`en-US` and `zh`, set upstream in `config/gni/i18n.gni`) are packaged, and the rest are meant to come from Chrome's `remoteBase` CDN, which React Native never passes. The dev server logs `Error: ENOENT: no such file or directory, stat '…/core/i18n/locales/it.json'` on every launch, and the frontend falls back to English only once the failed request comes back. Users get there without looking for it: with the default setting, a system language that DevTools supports shows the "DevTools is now available in …" infobar on first launch, and both of its buttons pick a locale React Native can't load. The Settings language dropdown lists every one of about 80 locales too. When there is no remote base, build the supported-locale list from the bundled locales only. The language dropdown then offers English and Chinese, the infobar appears only for Chinese, and a stored unbundled locale (or "Browser UI language" on, say, an Italian system) resolves to `en-US` without a request. With a remote base, every locale is offered as before. Fixes react/react-native#52461
1 parent 3a2e387 commit 3615ebe

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎front_end/core/i18n/i18n.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,16 @@ describe('fetchAndRegisterLocaleData', () => {
205205
`Actually called with ${fetchStub.args[0][0]}`);
206206
});
207207
});
208+
209+
describe('supported locales without a remote base', () => {
210+
it('offers only the bundled locales', () => {
211+
const locales = i18n.i18n.getAllSupportedDevToolsLocales();
212+
assert.includeMembers(locales, ['en-US', 'zh']);
213+
assert.notInclude(locales, 'it');
214+
});
215+
216+
it('resolves an unbundled locale to en-US', () => {
217+
assert.strictEqual(i18n.i18n.lookupClosestSupportedDevToolsLocale('it-IT'), 'en-US');
218+
assert.strictEqual(i18n.i18n.lookupClosestSupportedDevToolsLocale('zh-CN'), 'zh');
219+
});
220+
});

‎front_end/core/i18n/i18nImpl.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import {
1616
REMOTE_FETCH_PATTERN,
1717
} from './locales.js';
1818

19-
const i18nInstance = new I18n.I18n.I18n(LOCALES, DEFAULT_LOCALE);
19+
// [RN] React Native ships only the bundled locales and has no remoteBase to fetch
20+
// the rest from, so offer and resolve to the bundled locales only.
21+
const i18nInstance = new I18n.I18n.I18n(
22+
Root.Runtime.getRemoteBase()?.version ? LOCALES : BUNDLED_LOCALES_GENERATED, DEFAULT_LOCALE);
2023

2124
// All the locales that are part of the DevTools bundle and should not be fetched
2225
// remotely.

0 commit comments

Comments
 (0)