Skip to content
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

i18n: fix multi-directory collision checking #12698

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 5 additions & 13 deletions lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,9 @@ const collisionStrings = [];
* Collects all LHL messsages defined in UIString from Javascript files in dir,
* and converts them into CTC.
* @param {string} dir absolute path
* @return {Record<string, CtcMessage>}
* @param {Record<string, CtcMessage>} strings
*/
function collectAllStringsInDir(dir) {
/** @type {Record<string, CtcMessage>} */
const strings = {};

function collectAllStringsInDir(dir, strings) {
const globPattern = path.join(path.relative(LH_ROOT, dir), '/**/*.js');
const files = glob.sync(globPattern, {
cwd: LH_ROOT,
Expand Down Expand Up @@ -588,9 +585,7 @@ function collectAllStringsInDir(dir) {
if (seenStrings.has(ctc.message)) {
ctc.meaning = ctc.description;
const seenId = seenStrings.get(ctc.message);
// TODO: `strings[seenId]` check shouldn't be necessary here ...
// see https://github.com/GoogleChrome/lighthouse/pull/12441/files#r630521367
if (seenId && strings[seenId]) {
if (seenId) {
if (!strings[seenId].meaning) {
strings[seenId].meaning = strings[seenId].description;
collisions++;
Expand All @@ -607,8 +602,6 @@ function collectAllStringsInDir(dir) {
seenStrings.set(ctc.message, messageKey);
}
}

return strings;
}

/**
Expand All @@ -634,13 +627,12 @@ if (require.main === module) {

for (const folderWithStrings of foldersWithStrings) {
console.log(`\n====\nCollecting strings from ${folderWithStrings}\n====`);
const moreStrings = collectAllStringsInDir(folderWithStrings);
Object.assign(strings, moreStrings);
collectAllStringsInDir(folderWithStrings, strings);
}

if (collisions > 0) {
console.log(`MEANING COLLISION: ${collisions} string(s) have the same content.`);
assert.equal(collisions, 30, `The number of duplicate strings have changed, update this assertion if that is expected, or reword strings. Collisions: ${collisionStrings.join('\n')}`);
assert.equal(collisions, 32, `The number of duplicate strings have changed, update this assertion if that is expected, or reword strings. Collisions: ${collisionStrings.join('\n')}`);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is +2 for the collision between "lighthouse-treemap/app/src/util.js | tableColumnName" and "lighthouse-core/lib/i18n/i18n.js | columnName" we didn't add in #12441

}

writeStringsToCtcFiles('en-US', strings);
Expand Down