Files
Florian Zumpe 5c4d20bd1d
Sonarqube Scanner / Prepare environment (push) Successful in 19s
Sonarqube Scanner / Build and test (push) Successful in 43s
Sonarqube Scanner / SonarQube analysis (push) Failing after 2m28s
Sonarqube Scanner / Deploy to Server (push) Successful in 16s
fix sonar findings and translation structure
2026-10-01 16:31:46 +02:00

27 lines
919 B
JavaScript

import fs from 'node:fs/promises';
import path from 'node:path';
import vm from 'node:vm';
import { localizeHtml } from '../scripts/localize-html.js';
const root = path.resolve(import.meta.dirname, '..');
export async function loadI18n(context) {
for (const name of ['texts-de', 'texts-en', 'i18n']) {
const filename = path.join(root, `public/js/${name}.js`);
vm.runInNewContext(await fs.readFile(filename, 'utf8'), context, { filename });
}
return context.Wegwichtel.I18n;
}
export async function localizedHtml(source) {
const i18n = await loadI18n({});
const result = localizeHtml(source, key => i18n.t(key));
return result.replace(/\sdata-i18n(?:-[\w-]+)?="[^"]*"/g, '');
}
export async function readAppFile(relativePath) {
const source = await fs.readFile(path.join(root, relativePath), 'utf8');
if (relativePath === 'public/index.html') return localizedHtml(source);
return source;
}