mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-15 17:14:25 +02:00
lists the translation status
This commit is contained in:
parent
065f6c4edc
commit
7e16f11442
1 changed files with 42 additions and 37 deletions
|
@ -80,46 +80,12 @@ async function translateDialog(dialog, locale) {
|
||||||
return newDialog;
|
return newDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
// New function to list all locales
|
// New function to get translation status for a locale
|
||||||
function listLocales() {
|
function getTranslationStatus(locale, levelFiles, verbose = false) {
|
||||||
const levelsDir = path.join(__dirname, '../src/levels');
|
|
||||||
const levelFiles = getAllLevelFiles(levelsDir);
|
|
||||||
const allLocales = new Set();
|
|
||||||
|
|
||||||
for (const file of levelFiles) {
|
|
||||||
const levelPath = file;
|
|
||||||
// Clear cache to get fresh data from file
|
|
||||||
delete require.cache[require.resolve(levelPath)];
|
|
||||||
const levelData = require(levelPath);
|
|
||||||
|
|
||||||
if (levelData && levelData.level) {
|
|
||||||
const level = levelData.level;
|
|
||||||
if (level.name) {
|
|
||||||
Object.keys(level.name).forEach(locale => allLocales.add(locale));
|
|
||||||
}
|
|
||||||
if (level.hint) {
|
|
||||||
Object.keys(level.hint).forEach(locale => allLocales.add(locale));
|
|
||||||
}
|
|
||||||
if (level.startDialog) {
|
|
||||||
Object.keys(level.startDialog).forEach(locale => allLocales.add(locale));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Known locales found in level definitions:');
|
|
||||||
allLocales.forEach(locale => console.log(`- ${locale}`));
|
|
||||||
}
|
|
||||||
|
|
||||||
// New function to check translation status
|
|
||||||
function checkStatus(locale) {
|
|
||||||
const levelsDir = path.join(__dirname, '../src/levels');
|
|
||||||
const levelFiles = getAllLevelFiles(levelsDir);
|
|
||||||
let present = 0;
|
let present = 0;
|
||||||
let missing = 0;
|
let missing = 0;
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
console.log(`Checking translation status for locale: ${locale}`);
|
|
||||||
|
|
||||||
for (const file of levelFiles) {
|
for (const file of levelFiles) {
|
||||||
const levelPath = file;
|
const levelPath = file;
|
||||||
delete require.cache[require.resolve(levelPath)];
|
delete require.cache[require.resolve(levelPath)];
|
||||||
|
@ -134,13 +100,52 @@ function checkStatus(locale) {
|
||||||
if (level[field][locale]) {
|
if (level[field][locale]) {
|
||||||
present++;
|
present++;
|
||||||
} else {
|
} else {
|
||||||
console.log(` - Missing '${field}' in ${path.basename(file)}`);
|
if (verbose) {
|
||||||
|
console.log(` - Missing '${field}' in ${path.basename(file)}`);
|
||||||
|
}
|
||||||
missing++;
|
missing++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return { present, missing, total };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updated function to list all locales with their status
|
||||||
|
function listLocales() {
|
||||||
|
const levelsDir = path.join(__dirname, '../src/levels');
|
||||||
|
const levelFiles = getAllLevelFiles(levelsDir);
|
||||||
|
const allLocales = new Set();
|
||||||
|
|
||||||
|
for (const file of levelFiles) {
|
||||||
|
const levelPath = file;
|
||||||
|
delete require.cache[require.resolve(levelPath)];
|
||||||
|
const levelData = require(levelPath);
|
||||||
|
|
||||||
|
if (levelData && levelData.level) {
|
||||||
|
const level = levelData.level;
|
||||||
|
if (level.name) Object.keys(level.name).forEach(locale => allLocales.add(locale));
|
||||||
|
if (level.hint) Object.keys(level.hint).forEach(locale => allLocales.add(locale));
|
||||||
|
if (level.startDialog) Object.keys(level.startDialog).forEach(locale => allLocales.add(locale));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Known locales and their translation status:');
|
||||||
|
allLocales.forEach(locale => {
|
||||||
|
const { present, total } = getTranslationStatus(locale, levelFiles);
|
||||||
|
const percentage = total > 0 ? ((present / total) * 100).toFixed(2) : "0.00";
|
||||||
|
console.log(`- ${locale}: ${present}/${total} (${percentage}%)`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updated function to check translation status
|
||||||
|
function checkStatus(locale) {
|
||||||
|
const levelsDir = path.join(__dirname, '../src/levels');
|
||||||
|
const levelFiles = getAllLevelFiles(levelsDir);
|
||||||
|
|
||||||
|
console.log(`Checking translation status for locale: ${locale}`);
|
||||||
|
const { present, missing, total } = getTranslationStatus(locale, levelFiles, true);
|
||||||
|
|
||||||
console.log(`
|
console.log(`
|
||||||
--- Status for ${locale} ---`);
|
--- Status for ${locale} ---`);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue