-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[No QA] Add test for matching Translations keys #4090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f31e802
9e0fe2a
6ad65b7
26626ec
b1e7dc2
5551926
158dfb3
72a3280
f9baac6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,9 @@ | ||||||
const _ = require('underscore'); | ||||||
const translate = require('../../src/libs/translate'); | ||||||
const translations = require('../../src/languages/translations'); | ||||||
const CONFIG = require('../../src/CONFIG'); | ||||||
const translations = require('../../src/languages/translations'); | ||||||
|
||||||
const originalTranslations = _.clone(translations); | ||||||
translations.default = { | ||||||
en: { | ||||||
testKey1: 'English', | ||||||
|
@@ -52,3 +54,42 @@ describe('translate', () => { | |||||
expect(translate.translate('en', ['testKeyGroup', 'testFunction'], {testVariable})).toBe(expectedValue); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('Translation Keys', () => { | ||||||
function traverseKeyPath(source, path, keyPaths) { | ||||||
const pathArray = keyPaths || []; | ||||||
const keyPath = path ? `${path}.` : ''; | ||||||
_.each(_.keys(source), (key) => { | ||||||
if (_.isObject(source[key]) && !_.isFunction(source[key])) { | ||||||
traverseKeyPath(source[key], keyPath + key, pathArray); | ||||||
} else { | ||||||
pathArray.push(keyPath + key); | ||||||
} | ||||||
}); | ||||||
return pathArray; | ||||||
} | ||||||
const excludeLanguages = ['en', 'es-ES']; | ||||||
const languages = _.without(_.keys(originalTranslations.default), ...excludeLanguages); | ||||||
const parentLanguage = originalTranslations.default.en; | ||||||
const parentLanguageKeys = traverseKeyPath(parentLanguage); | ||||||
|
||||||
_.every(languages, (ln) => { | ||||||
parasharrajat marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const languageKeys = traverseKeyPath(originalTranslations.default[ln]); | ||||||
|
||||||
it(`Does ${ln} locale has all the keys`, () => { | ||||||
const hasAllKeys = _.difference(parentLanguageKeys, languageKeys); | ||||||
if (hasAllKeys.length) { | ||||||
console.debug(`🏹 [ ${hasAllKeys.join(', ')} ] are missing from ${ln}.js`); | ||||||
} | ||||||
expect(hasAllKeys.length).toBe(0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, I was thinking, maybe we could do this and get a better error message?
Suggested change
I think this will show in the test result exactly which keys are missing, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not show the keys that are not correct. It just shows Expected and produced output. So all the correct and wrong keys would be shown as a big string which is like 50 lines long.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmmm, can we change the code to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It currently only gives the missing keys. Again There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The console log is not good enough as it is super hard to find the right message. In any case I don't think you understood what I meant, because I just tried and it works. Here's the test code:
And this is the output:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh Yeah. This way I got it now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iwiznia Check this out https://github.com/Expensify/App/actions/runs/1079637864. I added annotations. |
||||||
}); | ||||||
|
||||||
it(`Does ${ln} locale has unused keys`, () => { | ||||||
const hasAllKeys = _.difference(languageKeys, parentLanguageKeys); | ||||||
if (hasAllKeys.length) { | ||||||
console.debug(`🏹 [ ${hasAllKeys.join(', ')} ] are unused keys in ${ln}.js`); | ||||||
} | ||||||
expect(hasAllKeys.length).toBe(0); | ||||||
}); | ||||||
}); | ||||||
}); |
Uh oh!
There was an error while loading. Please reload this page.