1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-23 02:04:34 +02:00
video.js/build/translations.js

55 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2019-08-30 20:14:53 +02:00
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
2019-08-30 20:14:53 +02:00
const sh = require('shelljs');
const source = require('../lang/en.json');
const table = require('markdown-table');
const tableRegex = /(<!-- START langtable -->)(.|\n)*(<!-- END langtable -->)/;
2019-08-30 20:14:53 +02:00
let doc = fs.readFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), 'utf8');
const tableData = [['Language file', 'Missing translations']];
2019-08-30 20:14:53 +02:00
const filepaths = sh.find(path.join(__dirname, '..', 'lang', '**', '!(zh-Hans|zh-Hant)*.json'));
2019-08-30 20:14:53 +02:00
filepaths.forEach((filepath) => {
const filename = path.basename(filepath);
if (filename === 'en.json') {
return;
}
2019-08-30 20:14:53 +02:00
const target = require(filepath);
// Special case for English, the assumption being that since the keys are English only
// a few strings need to be altered for regional differences, e.g. en-GB.
if (filename.startsWith('en-')) {
console.log(`${filename} English - should be manually checked.`);
tableData.push([`${filename} (has ${Object.keys(target).length})`, 'Needs manual checking. Can safely use most default strings.']);
return;
}
2019-08-30 20:14:53 +02:00
const missing = [];
for (const string in source) {
if (!target[string]) {
console.log(`${filename} missing "${string}"`);
missing.push(string);
}
}
if (missing.length > 0) {
console.error(`${filename} is missing ${missing.length} translations.`);
tableData.push([`${filename} (missing ${missing.length})`, missing[0]]);
2019-08-30 20:14:53 +02:00
for (let i = 1; i < missing.length; i++) {
tableData.push(['', missing[i]]);
}
} else {
console.log(`${filename} is up to date.`);
tableData.push([`${filename} (Complete)`, '']);
}
});
2019-08-30 20:14:53 +02:00
doc = doc.replace(tableRegex, '$1\n' + table(tableData) + '\n$3');
fs.writeFileSync(path.join(__dirname, '..', 'docs', 'translations-needed.md'), doc, 'utf8');