Migrate to lingui

Switch to "lingui" for better DX.
Tried to persist existing languages as much as possible.

Removed "vite-plugin-node-polyfills" because it's incompatible with "lingui"
This commit is contained in:
schroda
2026-01-10 19:45:02 +01:00
parent c1ac58f4d6
commit 65a9a905be
287 changed files with 120766 additions and 37748 deletions

View File

@@ -17,10 +17,10 @@ import {
import { WeblateLanguageStatistic } from './Weblate.types.ts';
import { TRANSLATED_PERCENT_THRESHOLD } from './Weblate.constants.ts';
const FILE_PATH = 'src/i18n/index.ts';
const FILE_PATH = 'src/i18n/locales.json';
const outputFilePath = path.join(import.meta.dirname, `../../../${FILE_PATH}`);
const resourcesDirPath = path.join(import.meta.dirname, '../../../public/locales');
const resourcesDirPath = path.join(import.meta.dirname, '../../../src/i18n/locales');
const extractLanguageCode = (resourceFileNames: string): string =>
path.basename(resourceFileNames, path.extname(resourceFileNames));
@@ -52,19 +52,14 @@ const generateResources = async () => {
.filter((resourceFileName) => meetsTranslatedPercentThreshold(resourceFileName, weblateLanguageStats))
.map(extractLanguageCode);
const outputFileContent = fs.readFileSync(outputFilePath, 'utf-8');
const localesConfig = JSON.parse(fs.readFileSync(outputFilePath, 'utf-8'));
const updatedFileContent = outputFileContent.replace(
/(export const i18nResources = \[)[\s\S]*?(])/g,
`$1'${resourceNames.join("', '")}'$2`,
);
localesConfig.locales = resourceNames;
fs.writeFileSync(outputFilePath, updatedFileContent);
fs.writeFileSync(outputFilePath, `${JSON.stringify(localesConfig, null, 2)}\n`);
execSync('yarn tsc', { stdio: 'inherit' });
execSync(`yarn eslint --fix ${FILE_PATH}`, { stdio: 'inherit' });
const hasFileChanged = execSync('git status --porcelain').toString().includes(FILE_PATH);
if (!hasFileChanged) {
return;