deep text checks
MODIFY
test/I18nChecker.ts
test/I18nChecker.ts
@@ -27,7 +27,9 @@ class I18nChecker {
console.log(deleted);
}
if (Object.keys(added).length === 0 && Object.keys(deleted).length === 0) {
- I18nChecker.compareContent(parsedContentEN, parsedContentOtherLanguage, file);
+ if (I18nChecker.compareContent(parsedContentEN, parsedContentOtherLanguage, file)) {
+ console.log('No error found for file ' + file);
+ }
}
} catch (err) {
console.log('File not found or with wrong format: ' + file);
@@ -41,20 +43,29 @@ class I18nChecker {
}
}
- private static compareContent(originalLanguage: JSON, comparedLanguage: JSON, file: string): void {
- let noIssue = true;
- for (const keyName of Object.keys(originalLanguage)) {
- if (typeof originalLanguage[keyName] !== 'string') {
- continue;
+ private static compareValueContent(keyName: string, originalValue: string, comparedValue: string, file: string): boolean {
+ if (originalValue.trim() === comparedValue.trim()) {
+ console.log(file + ': Content `' + keyName + '` probably not yet translated (current value is: `' + originalValue + '`)');
+ return false; // Value is same!
}
- if (originalLanguage[keyName].trim() === comparedLanguage[keyName].trim()) {
- console.log('Content `' + keyName + '` probably not yet translated into ' + file + ' (current value is: `' + originalLanguage[keyName] + '`)');
- noIssue = false;
+ return true; // Value is translated.
}
+
+ private static compareContent(originalLanguage: JSON, comparedLanguage: JSON, file: string): boolean {
+ let noIssue = true;
+ for (const keyName of Object.keys(originalLanguage)) {
+ switch (typeof originalLanguage[keyName]) {
+ case 'string':
+ noIssue = noIssue && I18nChecker.compareValueContent(keyName, originalLanguage[keyName], comparedLanguage[keyName], file);
+ break;
+ case 'object':
+ noIssue = I18nChecker.compareContent(Object.assign({}, originalLanguage[keyName]), Object.assign({}, comparedLanguage[keyName]), file) && noIssue;
+ break;
+ default:
+ console.error(keyName + ' is not a supported type!');
}
- if (noIssue) {
- console.log('No issue found for: ' + file);
}
+ return noIssue;
}
}

deep text checks