[go: nahoru, domu]

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: introduce script to swap in new locale to LHR #8755

Merged
merged 17 commits into from
Jun 25, 2019
Merged
Prev Previous commit
Next Next commit
console time
  • Loading branch information
paulirish committed May 28, 2019
commit 5654af17936a29dffebab65323ee21d0f869f251
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') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels like it will get out of date and we won't notice :)

any way you can think of to make this a little more foolproof? export the string in i18n maybe? a flag on the error? 🤷‍♂

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe these get returned as warnings if we split the logging into a script?

}

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();
Copy link
Collaborator

Choose a reason for hiding this comment

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

hopefully won't need this one :)

});

describe('swap-locale', () => {

This comment was marked as resolved.

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