Skip to content

Commit

Permalink
console time
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed May 28, 2019
1 parent 3531318 commit 5654af1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lighthouse-core/lib/i18n/swap-locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function swapLocale(lhr, requestedLocale) {

const locale = i18n.lookupLocale(requestedLocale);
const {icuMessagePaths} = lhr.i18n;
const missingIcuMessageIds = /** @type {string[]} */([]);

Object.entries(icuMessagePaths).forEach(([icuMessageId, messageInstancesInLHR]) => {
for (const instance of messageInstancesInLHR) {
Expand All @@ -73,14 +74,18 @@ function swapLocale(lhr, requestedLocale) {
_set(lhr, path, formattedStr);
} catch (err) {
if (err.message === 'No ICU message string to format') {
console.error('No message found for ', {locale, icuMessageId});
missingIcuMessageIds.push(icuMessageId);
} else {
throw err;
}
}
}
});

if (missingIcuMessageIds.length) {
console.error(`No message in locale (${locale}) found for:\n`, missingIcuMessageIds);
}

lhr.i18n.rendererFormattedStrings = i18n.getRendererFormattedStrings(locale);
// Tweak the config locale
lhr.configSettings.locale = locale;
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-core/test/lib/i18n/swap-locale-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const swapLocale = require('../../../lib/i18n/swap-locale.js');
const lhr = require('../../results/sample_v2.json');

/* eslint-env jest */
beforeEach(() => {
// silence console.error spam about messages not found
// eslint-disable-next-line no-console
console.error = jest.fn();
});

describe('swap-locale', () => {
it('can change golden LHR english strings into spanish', () => {
Expand Down

0 comments on commit 5654af1

Please sign in to comment.