mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-26 22:39:07 +01:00
[client] Only offer locales listed in _index.json (#8091)
This commit is contained in:
@@ -40,14 +40,29 @@ function detectBrowserLanguage(available: string[]): string | null {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty persisted language code is the Go-side signal for first run.
|
// Only locales listed in _index.json are shipped. A bundle on disk without an
|
||||||
|
// _index.json row (e.g. a new Crowdin language not released yet) must not be
|
||||||
|
// auto-detected or loaded, matching the Go side, which rejects saving it.
|
||||||
|
async function shippedLanguages(): Promise<string[]> {
|
||||||
|
const onDisk = Object.keys(resources);
|
||||||
|
try {
|
||||||
|
const listed = new Set<string>((await I18n.Languages()).map((l) => l.code));
|
||||||
|
return onDisk.filter((code) => listed.has(code));
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("load shipped languages failed, using all bundled locales", e);
|
||||||
|
return onDisk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An empty persisted language code is the Go-side signal for first run. A
|
||||||
|
// persisted code that is no longer shipped is treated the same way.
|
||||||
export async function initI18n(): Promise<void> {
|
export async function initI18n(): Promise<void> {
|
||||||
const available = Object.keys(resources);
|
const available = await shippedLanguages();
|
||||||
let language = "en";
|
let language = "en";
|
||||||
let firstRun = false;
|
let firstRun = false;
|
||||||
try {
|
try {
|
||||||
const prefs = await Preferences.Get();
|
const prefs = await Preferences.Get();
|
||||||
if (prefs?.language) {
|
if (prefs?.language && available.includes(prefs.language)) {
|
||||||
language = prefs.language;
|
language = prefs.language;
|
||||||
} else {
|
} else {
|
||||||
firstRun = true;
|
firstRun = true;
|
||||||
@@ -68,7 +83,7 @@ export async function initI18n(): Promise<void> {
|
|||||||
fallbackLng: "en",
|
fallbackLng: "en",
|
||||||
defaultNS: "common",
|
defaultNS: "common",
|
||||||
ns: ["common"],
|
ns: ["common"],
|
||||||
resources,
|
resources: Object.fromEntries(available.map((code) => [code, resources[code]])),
|
||||||
interpolation: {
|
interpolation: {
|
||||||
prefix: "{",
|
prefix: "{",
|
||||||
suffix: "}",
|
suffix: "}",
|
||||||
|
|||||||
Reference in New Issue
Block a user