Skip to content

Commit

Permalink
Add script for validating texts yaml, comparing it to the English ver…
Browse files Browse the repository at this point in the history
…sion; add missing keys to some languages. (hedyorg#485)
  • Loading branch information
fpereiro authored Jun 14, 2021
1 parent d48fe42 commit e3fc0eb
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 1,246 deletions.
1,300 changes: 55 additions & 1,245 deletions build-tools/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion build-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"pajv": "^1.2.0"
"pajv": "^1.2.0",
"yaml": "1.10.2"
}
}
42 changes: 42 additions & 0 deletions build-tools/validate-texts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fs = require ('fs');
const yaml = require ('yaml');

const ajv = new (require ('ajv'));

const path = require ('path').join (process.argv [2], '../coursedata/texts') + '/';

const file = fs.readFileSync(path + 'en.yaml', 'utf8');

const texts = yaml.parse (file);

const properties = {};
Object.keys (texts).map (function (topKey) {
const props = {};
Object.keys (texts [topKey]).map (function (subKey) {
props [subKey] = {type: 'string'};
});
properties [topKey] = {type: 'object', additionalProperties: false, properties: props, required: Object.keys (props)};
});

const schema = {type: 'object', additionalProperties: false, properties: properties, required: Object.keys (properties)};

const files = fs.readdirSync(path);

files.map (function (file) {
if (! file.match (/.yaml$/)) return;

let parsed;

try {
parsed = yaml.parse (fs.readFileSync (path + file, 'utf8'));
}
catch (error) {
console.log ('Invalid yaml ' + file);
process.exit (1);
}
if (! ajv.validate (schema, parsed)) {
console.log ('Invalid file ' + file, JSON.stringify (ajv.errors));
process.exit (1);
}
console.log (path + file, 'OK');
});
2 changes: 2 additions & 0 deletions build-tools/validate-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ $scriptdir/node_modules/.bin/pajv validate \
--errors=text \
-s "levels.schema.json" \
-d "*.yaml"

node $scriptdir/validate-texts.js $scriptdir
1 change: 1 addition & 0 deletions coursedata/texts/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ui:
adventure: "Aventura"
switch_to_levels: "Ir a niveles"
switch_to_adventures: "Ir a aventuras"
switch_to_another_adventure: "Elegir otra aventura"
commands_title: "Comandos"
ClientErrorMessages:
Transpile_warning: "Atención!"
Expand Down
1 change: 1 addition & 0 deletions coursedata/texts/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ui:
adventure: "Aventure"
switch_to_levels: "Aller aux niveaux"
switch_to_adventures: "Aller aux aventures"
switch_to_another_adventure: "Choose a different adventure"
commands_title: "Commandos"
ClientErrorMessages:
Transpile_warning: "Attention!"
Expand Down
1 change: 1 addition & 0 deletions coursedata/texts/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ui:
adventure: "Adventure"
switch_to_levels: "Vai ai livelli"
switch_to_adventures: "Vai alle avventure"
switch_to_another_adventure: "Choose a different adventure"
commands_title: "Commandos"
ClientErrorMessages:
Transpile_warning: "Attenzione!"
Expand Down
1 change: 1 addition & 0 deletions coursedata/texts/pt_br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ui:
adventure: "Aventura"
switch_to_levels: "Ir a níveis"
switch_to_adventures: "Ir a aventuras"
switch_to_another_adventure: "Choose a different adventure"
commands_title: "Comandos"
ClientErrorMessages:
Transpile_warning: "Aviso!"
Expand Down
4 changes: 4 additions & 0 deletions coursedata/texts/sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ ui:
assignment_header: "kazi ya ziada"
show_explanation: "Onyesha maelezo"
hide_explanation: "Ficha maelezo"
adventure: "Adventure"
switch_to_levels: "Leave adventure mode"
switch_to_adventures: "Go to adventures"
switch_to_another_adventure: "Choose a different adventure"
commands_title: "Commands"
ClientErrorMessages:
Transpile_warning: "Onyo!"
Expand Down
5 changes: 5 additions & 0 deletions coursedata/texts/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ ui:
assignment_header: "任务"
show_explanation: "显示解释"
hide_explanation: "隐藏解释"
adventure: "Adventure"
switch_to_levels: "Leave adventure mode"
switch_to_adventures: "Go to adventures"
switch_to_another_adventure: "Choose a different adventure"
commands_title: "Commands"
ClientErrorMessages:
Transpile_warning: "警告!"
Transpile_error: "服务器无法将这个Hedy程序翻译成Python程序."
Expand Down

0 comments on commit e3fc0eb

Please sign in to comment.