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

clients(devtools): expose registerLocaleData to worker #9645

Merged
merged 7 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions clients/devtools-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const lighthouse = require('../lighthouse-core/index.js');
const RawProtocol = require('../lighthouse-core/gather/connections/raw.js');
const log = require('lighthouse-logger');
const {registerLocaleData, lookupLocale} = require('../lighthouse-core/lib/i18n/i18n.js');

/** @typedef {import('../lighthouse-core/gather/connections/connection.js')} Connection */

Expand Down Expand Up @@ -53,6 +54,8 @@ if (typeof module !== 'undefined' && module.exports) {
module.exports = {
runLighthouseInWorker,
listenForStatus,
registerLocaleData,
lookupLocale
};
}

Expand All @@ -63,4 +66,8 @@ if (typeof self !== 'undefined') {
self.runLighthouseInWorker = runLighthouseInWorker;
// @ts-ignore
self.listenForStatus = listenForStatus;
// @ts-ignore
self.registerLocaleData = registerLocaleData;
// @ts-ignore
self.lookupLocale = lookupLocale;
Copy link
Member

Choose a reason for hiding this comment

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

}
1 change: 0 additions & 1 deletion lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ lighthouse.traceCategories = require('./gather/driver.js').traceCategories;
lighthouse.Audit = require('./audits/audit.js');
lighthouse.Gatherer = require('./gather/gatherers/gatherer.js');
lighthouse.NetworkRecords = require('./computed/network-records.js');
lighthouse.registerLocaleData = require('./lib/i18n/i18n.js').registerLocaleData;

module.exports = lighthouse;
6 changes: 3 additions & 3 deletions lighthouse-core/lib/i18n/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ const locales = {
'tr': require('./locales/tr.json'),
'uk': require('./locales/uk.json'),
'vi': require('./locales/vi.json'),
'zh': require('./locales/zh.json'), // zh-CN identical, so it falls back into zh
'zh-HK': require('./locales/zh-HK.json'),
'zh-TW': require('./locales/zh-TW.json'),
'zh': require('./locales/zh.json'), // aka ZH-Hans, sometimes seen as zh-CN, zh-Hans-CN, Simplified Chinese
'zh-HK': require('./locales/zh-HK.json'), // aka zh-Hant-HK. Note: yue-Hant-HK is not supported.
'zh-TW': require('./locales/zh-TW.json'), // aka zh-Hant, zh-Hant-TW, Traditional Chinese
};

module.exports = locales;
13 changes: 11 additions & 2 deletions lighthouse-core/test/lib/i18n/i18n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ describe('i18n', () => {
});

describe('#registerLocaleData', () => {
// Store original locale data so we can restore at the end
const moduleLocales = require('../../../lib/i18n/locales.js');
const clonedLocales = JSON.parse(JSON.stringify(moduleLocales));

it('installs new locale strings', () => {
const localeData = {
'lighthouse-core/test/lib/i18n/i18n-test.js | testString': {
Expand Down Expand Up @@ -142,18 +146,23 @@ describe('i18n', () => {
// Now we declare and register the new string...
const localeData = {
'lighthouse-core/audits/is-on-https.js | title': {
'message': 'es-419 uses https!',
'message': 'new string for es-419 uses https!',
},
};
i18n.registerLocaleData('es-419', localeData);

// And confirm that's what is returned
const newTitle = i18n.getFormatted(str_(UIStrings.title), 'es-419');
expect(newTitle).toEqual('es-419 uses https!');
expect(newTitle).toEqual('new string for es-419 uses https!');

// Meanwhile another string that wasn't set in registerLocaleData just falls back to english
const newFailureTitle = i18n.getFormatted(str_(UIStrings.failureTitle), 'es-419');
expect(newFailureTitle).toEqual('Does not use HTTPS');

// Restore overwritten strings to avoid messing with other tests
moduleLocales['es-419'] = clonedLocales['es-419'];
const title = i18n.getFormatted(str_(UIStrings.title), 'es-419');
expect(title).toEqual('Usa HTTPS');
});
});

Expand Down