Skip to content

Commit

Permalink
stop empty plcaeholders from being added to every message. Stricter c…
Browse files Browse the repository at this point in the history
…heck to prevent regression.
  • Loading branch information
exterkamp committed Jul 22, 2019
1 parent be426b8 commit 125cb1d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/i18n/collect-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ function collectAllStringsInDir(dir, strings = {}) {
description,
};

if (converted.placeholders.constructor === Object) {
// Stop empty placeholders from being added to every message
if (Object.entries(converted.placeholders).length > 0) {
icuDefn.placeholders = converted.placeholders;
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/test/scripts/i18n/collect-strings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ describe('Convert Message to Placeholder', () => {
it('passthroughs a basic message unchanged', () => {
const message = 'Hello World.';
const res = collect.convertMessageToPlaceholders(message, undefined);
expect(res).toEqual({message, placeholders: {}});
expect(res).toEqual({message, placeholders: undefined});
});

it('passthroughs an ICU plural unchanged', () => {
const message = '{var, select, male{Hello Mr. Programmer.} ' +
'female{Hello Ms. Programmer} other{Hello Programmer.}}';
const res = collect.convertMessageToPlaceholders(message, undefined);
expect(res).toEqual({message, placeholders: {}});
expect(res).toEqual({message, placeholders: undefined});
});

// TODO(exterkamp): more strict parsing for this case
Expand Down

0 comments on commit 125cb1d

Please sign in to comment.