Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 56 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-you-dont-need-lodash-underscore": "^6.13.0",
"js-yaml": "^3.14.1",
"js-yaml": "^4.1.0",
"markdownlint-cli": "^0.39.0",
"meteor-sdk": "0.0.21",
"mocha": "^10.4.0",
Expand Down
28 changes: 18 additions & 10 deletions tests/i18n/test_i18n_resources.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from "pathe";
/*
* This script will check i18n resources keys
* 1. read all available keys from YAML
Expand All @@ -19,7 +20,7 @@ const IGNOREKEYS = {
const fs = require("fs");
const yaml = require("js-yaml");

const en_yaml = `${__dirname}/../../both/i18n/en.i18n.yml`;
const en_yaml = path.join(__dirname, "../../both/i18n/en.i18n.yml");
let anyErrorExitCodeToShell = 0;
let globalErrorCount = 0;
let globalWarningCount = 0;
Expand Down Expand Up @@ -65,16 +66,15 @@ function collectFilesRecursive(dir, extension) {
});
return results;
}

// Recursively iterate a JS object build full pathes of keys
function buildFullPathes(obj, stack, separator = ".") {
// Recursively iterate a JS object build full paths of keys
function buildFullPaths(obj, stack, separator = ".") {
for (const property in obj) {
if (Object.prototype.hasOwnProperty.call(obj, property)) {
if (typeof obj[property] == "object") {
if (stack) {
buildFullPathes(obj[property], stack + separator + property);
buildFullPaths(obj[property], stack + separator + property);
} else {
buildFullPathes(obj[property], property);
buildFullPaths(obj[property], property);
}
} else {
dictKeysFromYaml[stack + separator + property] = 0; // Remember leaf!
Expand All @@ -83,10 +83,18 @@ function buildFullPathes(obj, stack, separator = ".") {
}
}

/**
* Checks the usage of i18n keys in code files and compares them with YAML
* files.
*
* @param {string} extension - The file extension to search for.
* @param {RegExp} keyPattern - The regular expression pattern to match i18n
* keys.
*/
function checkCodeUsage(extension, keyPattern) {
dictKeysFromCode = {};
let localErrorCount = 0;
const files_js = collectFilesRecursive(`${__dirname}/../..`, extension);
const files_js = collectFilesRecursive(path.join(__dirname, ".."), extension);

// Find all i18n __ keys used in this file, according to regexp key pattern
// provided
Expand Down Expand Up @@ -127,15 +135,15 @@ function checkCodeUsage(extension, keyPattern) {
// Read and parse YAML file to JS object
let yaml_doc = undefined;
try {
yaml_doc = yaml.safeLoad(fs.readFileSync(en_yaml, "utf8"));
yaml_doc = yaml.load(fs.readFileSync(en_yaml, "utf8"));
} catch (e) {
console.log(e);
anyErrorExitCodeToShell = 10;
}
// Recursively walk the YAML JS object, build key pathes like:
// Recursively walk the YAML JS object, build key paths like:
// 'Admin.Users.State.column'
if (yaml_doc) {
buildFullPathes(yaml_doc, ""); // ==> results in dictKeysFromYaml
buildFullPaths(yaml_doc, ""); // ==> results in dictKeysFromYaml
} else {
console.log("Error: could not parse YAML");
anyErrorExitCodeToShell = 20;
Expand Down