Files
gods-eye-view/build/vite.js
T
Meir Michanie bde1e430ef feat(i18n): locale core + English catalogs + parity gates
Add the i18n foundation: src/i18n/locale.js (locale resolution with a
configurable GEV_DEFAULT_LOCALE / GEV_SECONDARY_LOCALE pair, guarded
preference storage, one-shot ?lang= override, <html lang>/<html dir>
metadata) and src/i18n/index.js (catalog registry, t(), Intl formatters,
applyDocumentTranslations, persistLocaleAndReload).

English is the only shipped locale in this PR: the four en catalogs
(shell/cockpit/layers/setup) are the reference and the always-shipped
fallback, the built-in pair degenerates to en-only, and English output
is byte-identical to the strings these replace.

Parity gates land with the core (catalog key/placeholder/plural-shape
parity, markup coverage of every data-i18n* attribute, repair-pass
anchors pinning en byte-identity); additional locales ship as stacked
follow-up PRs through the recipe in docs/TRANSLATORS.md.

Rebased onto current main: the client defines live in build/vite.js /
server/standalone/vite.config.js as before.
2026-10-01 12:26:30 +02:00

64 lines
2.5 KiB
JavaScript

import { applicationHtmlPlugin } from './application-html.js';
import cesium from 'vite-plugin-cesium';
/** Build browser assets with explicit inputs; never load environment or providers. */
export function createBrowserViteConfig({
plugins = [],
publicDir,
googleApiKey,
cesiumToken,
defaultLocale = '',
secondaryLocale = '',
host = 'localhost',
port = 4173,
command,
} = {}) {
return {
plugins: [cesium(), applicationHtmlPlugin(), ...plugins],
...(publicDir === undefined ? {} : { publicDir }),
// A production build must not clean the dependency cache a running dev
// server is still serving optimized module URLs from.
...(command === 'build' ? { cacheDir: 'node_modules/.vite-build' } : {}),
optimizeDeps: {
// First reached through the SDR worker or a dynamic import. Pre-bundle
// them at startup so first use cannot invalidate already-transformed
// URLs with Vite's "Outdated Optimize Dep" 504 response.
include: [
'@jtarrio/signals/demod/demodulator.js',
'@jtarrio/signals/demod/modes.js',
'@jtarrio/webrtlsdr/rtlsdr.js',
'egm96-universal',
],
},
server: {
host: host || 'localhost',
port: parseInt(port, 10) || 4173,
allowedHosts:
host === '0.0.0.0' || host === '::'
? true
: ['localhost', '127.0.0.1', '.local'],
fs: {
deny: ['.env', '.env.*', '*.{crt,pem}', '**/.git/**', '**/ENVIRONMENT'],
},
// These headers protect the document containing Provider Settings.
headers: {
'X-Frame-Options': 'DENY',
'Content-Security-Policy': "frame-ancestors 'none'",
},
},
define: {
'import.meta.env.GOOGLE_MAPS_API_KEY': JSON.stringify(googleApiKey),
'import.meta.env.CESIUM_ION_TOKEN': JSON.stringify(cesiumToken),
// Locale pair (i18n): the client's default + secondary UI locale. These
// are NOT secrets and are read by src/i18n/locale.js, which validates
// them against the shipped catalogs and falls back to the built-in
// en-only pair (while English is the only shipped catalog) for
// empty/invalid/unshipped values. Explicit define entries are required
// because Vite only auto-exposes VITE_-prefixed vars on import.meta.env.
'import.meta.env.GEV_DEFAULT_LOCALE': JSON.stringify(defaultLocale),
'import.meta.env.GEV_SECONDARY_LOCALE': JSON.stringify(secondaryLocale),
},
build: { chunkSizeWarningLimit: 1500 },
};
}