Hermetiska integrationstester + auto-hushall i onboarding (size, i18n, locations)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const cache: Record<string, Record<string, string>> = {};
|
||||
|
||||
/**
|
||||
* Minimal server-side i18n lookup into the mobile app's common.json files.
|
||||
* Falls back to the requested key if the translation is missing.
|
||||
*/
|
||||
export function t(key: string, languageTag: string): string {
|
||||
const lang = (languageTag.split("-")[0] ?? languageTag).toLowerCase();
|
||||
let dict = cache[lang];
|
||||
if (!dict) {
|
||||
try {
|
||||
const file = path.resolve(
|
||||
__dirname,
|
||||
"../../../../apps/mobile/src/locales",
|
||||
lang,
|
||||
"common.json",
|
||||
);
|
||||
dict = JSON.parse(readFileSync(file, "utf8")) as Record<string, string>;
|
||||
} catch {
|
||||
dict = {};
|
||||
}
|
||||
cache[lang] = dict;
|
||||
}
|
||||
return dict[key] ?? key;
|
||||
}
|
||||
Reference in New Issue
Block a user