frigate/web/i18next.config.ts
Josh Hawkins 7b6d0c5e42
Some checks are pending
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
i18n workflow improvements and tweaks (#22586)
* mobile button spacing

* prevent console warning about div being descendant of p

* ensure consistent spacing

* add missing i18n keys

* i18n fixes

- add missing translations
- fix dot notation keys

* use plain string

* add missing key

* add i18next-cli commands for extraction and status

also add false positives removal for several keys

* add i18n key check step to PR workflow

* formatting
2026-03-23 08:48:02 -05:00

52 lines
1.6 KiB
TypeScript

import { defineConfig, type Plugin } from "i18next-cli";
/**
* Plugin to remove false positive keys generated by dynamic namespace patterns
* like useTranslation([i18nLibrary]) and t("key", { ns: configNamespace }).
* These keys already exist in their correct runtime namespaces.
*/
function ignoreDynamicNamespaceKeys(): Plugin {
// Keys that the extractor misattributes to the wrong namespace
// because it can't resolve dynamic ns values at build time.
const falsePositiveKeys = new Set([
// From useTranslation([i18nLibrary]) in ClassificationCard.tsx
// Already in views/classificationModel and views/faceLibrary
"details.unknown",
"details.none",
// From t("key", { ns: configNamespace }) in DetectorHardwareField.tsx
// Already in config/global
"detectors.type.label",
// From t(`${prefix}`) template literals producing empty/partial keys
"",
"_one",
"_other",
]);
return {
name: "ignore-dynamic-namespace-keys",
onEnd: async (keys) => {
for (const key of keys.keys()) {
// Each map key is "ns:actualKey" format
const separatorIndex = key.indexOf(":");
const actualKey =
separatorIndex >= 0 ? key.slice(separatorIndex + 1) : key;
if (falsePositiveKeys.has(actualKey)) {
keys.delete(key);
}
}
},
};
}
export default defineConfig({
locales: ["en"],
extract: {
input: ["src/**/*.{ts,tsx}"],
output: "public/locales/{{language}}/{{namespace}}.json",
defaultNS: "common",
removeUnusedKeys: false,
sort: false,
},
plugins: [ignoreDynamicNamespaceKeys()],
});