-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Changes from 1 commit
a8ff2a0
81b0dc4
e12f714
30bb475
059bc0f
54c4833
bdd29b4
fdf96e8
5255aee
627f7be
3531318
5654af1
a225504
853bfd2
e3f2d3f
5efe7eb
cf0d3b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe these get returned as |
||
} | ||
|
||
lhr.i18n.rendererFormattedStrings = i18n.getRendererFormattedStrings(locale); | ||
// Tweak the config locale | ||
lhr.configSettings.locale = locale; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Sorry, something went wrong. |
||
it('can change golden LHR english strings into spanish', () => { | ||
|
There was a problem hiding this comment.
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? 🤷♂