This commit is contained in:
Raj Nandan Sharma
2026-03-12 14:03:19 +05:30
parent 04b1d0716b
commit 681b116e09
2 changed files with 20 additions and 5 deletions
+3
View File
@@ -164,6 +164,9 @@ COPY --chown=node:node --from=builder /app/src/lib/server/db/seedMonitorData.ts
COPY --chown=node:node --from=builder /app/src/lib/server/db/seedPagesData.ts ./src/lib/server/db/seedPagesData.ts
COPY --chown=node:node --from=builder /app/src/lib/server/templates/general ./src/lib/server/templates/general
# Locale JSON files (read at runtime by server-side i18n)
COPY --chown=node:node --from=builder /app/src/lib/locales ./src/lib/locales
# Build output (SvelteKit client/server + esbuild main.js) — changes most often
COPY --chown=node:node --from=builder /app/build ./build
+17 -5
View File
@@ -1,12 +1,24 @@
/**
* Server-side i18n helper for translating strings outside of Svelte components.
* Reads locale JSON files eagerly via Vite's import.meta.glob.
* Reads locale JSON files from disk using Node.js fs (compatible with both
* Vite dev server and esbuild production bundle).
*/
const localeModules = import.meta.glob("/src/lib/locales/*.json", {
eager: true,
import: "default",
}) as Record<string, { name: string; mappings: Record<string, string> }>;
import { readdirSync, readFileSync } from "fs";
import { join } from "path";
const localeModules: Record<string, { name: string; mappings: Record<string, string> }> = {};
const localesDir = join(process.cwd(), "src", "lib", "locales");
try {
const files = readdirSync(localesDir).filter((f) => f.endsWith(".json"));
for (const file of files) {
const key = `/src/lib/locales/${file}`;
localeModules[key] = JSON.parse(readFileSync(join(localesDir, file), "utf-8"));
}
} catch {
console.warn("Could not load locale files from", localesDir);
}
const localeCache = new Map<string, Record<string, string>>();