mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Split translation key testing
All keys in a translation file should be in the base file (en.json). When there are keys in the base file that are not in a translation, the translation file test is skipped.
This commit is contained in:
parent
406ae4e8c3
commit
d004c0ccd1
@ -3,9 +3,6 @@ var path = require("path");
|
|||||||
var chai = require("chai");
|
var chai = require("chai");
|
||||||
var expect = chai.expect;
|
var expect = chai.expect;
|
||||||
|
|
||||||
// Disabled for now, because of too many errors
|
|
||||||
// Remove .skip from it to enable
|
|
||||||
|
|
||||||
describe("Translations have the same keys as en.js", function() {
|
describe("Translations have the same keys as en.js", function() {
|
||||||
var translations = require("../../../translations/translations.js");
|
var translations = require("../../../translations/translations.js");
|
||||||
var base = JSON.parse(stripComments(fs.readFileSync("translations/en.json", "utf8")));
|
var base = JSON.parse(stripComments(fs.readFileSync("translations/en.json", "utf8")));
|
||||||
@ -13,20 +10,28 @@ describe("Translations have the same keys as en.js", function() {
|
|||||||
|
|
||||||
Object.keys(translations).forEach(function(tr) {
|
Object.keys(translations).forEach(function(tr) {
|
||||||
var fileName = translations[tr];
|
var fileName = translations[tr];
|
||||||
it(fileName + " should match", function() {
|
|
||||||
var fileContent = stripComments(fs.readFileSync(fileName, "utf8"));
|
var fileContent = stripComments(fs.readFileSync(fileName, "utf8"));
|
||||||
var fileTranslations = JSON.parse(fileContent);
|
var fileTranslations = JSON.parse(fileContent);
|
||||||
var fileKeys = Object.keys(fileTranslations).sort();
|
var fileKeys = Object.keys(fileTranslations).sort();
|
||||||
|
|
||||||
|
it(fileName + " keys should be in base", function() {
|
||||||
|
fileKeys.forEach(function(key) {
|
||||||
|
expect( baseKeys.indexOf(key) ).to.be.at.least(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it(fileName + " should contain all base keys", function() {
|
||||||
|
var test = this;
|
||||||
|
baseKeys.forEach(function(key) {
|
||||||
// TODO: when all translations are fixed, use
|
// TODO: when all translations are fixed, use
|
||||||
// expect(fileKeys).to.deep.equal(baseKeys);
|
// expect(fileKeys).to.deep.equal(baseKeys);
|
||||||
|
// instead of the try-catch-block
|
||||||
|
|
||||||
// Then delete this block:
|
|
||||||
try {
|
try {
|
||||||
expect(fileKeys).to.deep.equal(baseKeys);
|
expect(fileKeys).to.deep.equal(baseKeys);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e instanceof chai.AssertionError) {
|
if (e instanceof chai.AssertionError) {
|
||||||
this.skip();
|
test.skip();
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -34,6 +39,7 @@ describe("Translations have the same keys as en.js", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Copied from js/translator.js
|
// Copied from js/translator.js
|
||||||
function stripComments(str, opts) {
|
function stripComments(str, opts) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user