Initial web

This commit is contained in:
Caesar2011
2026-05-17 19:55:53 +02:00
parent 6e3499812e
commit 20ed6ee9fb
58 changed files with 8541 additions and 0 deletions

29
web/lib/localeServer.ts Normal file
View File

@@ -0,0 +1,29 @@
import fs from 'fs';
import path from 'path';
import { parseCsv } from './localization';
import type { LocaleMap } from './localization';
declare global { var __serverLocaleCache: LocaleMap | undefined; }
/**
* Loads and merges EN + DE locale CSVs from the public directory.
* Cached for the lifetime of the server process.
* Server-only — never import from client components.
*/
export function getServerLocaleMap(): LocaleMap {
if (globalThis.__serverLocaleCache) return globalThis.__serverLocaleCache;
const pub = path.join(process.cwd(), 'public');
function load(filename: string): LocaleMap {
try {
return parseCsv(fs.readFileSync(path.join(pub, filename), 'utf8'));
} catch {
return new Map();
}
}
const merged: LocaleMap = new Map([...load('factorio_english_items.csv'), ...load('factorio_german_items.csv')]);
globalThis.__serverLocaleCache = merged;
return merged;
}