-
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
WIP: i18n support for plugins #9799
Conversation
Add TODO.
lighthouse-core/lib/i18n/i18n.js
Outdated
const locale = tempPath.replace(/\.json$/, ''); | ||
const relativePrefix = path.relative(LH_ROOT, rootPath).replace(/\\/g, '/'); | ||
if (LOCALES[locale]) { | ||
const localeToMerge = require(`${fullLocalePath}/${tempPath}`); |
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.
can you separate this inner bit into its own function?
appendStringsToLocale
?
const rawPluginJson = require(pluginPath); | ||
const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName); | ||
|
||
if (rawPluginJson['localePath']) { | ||
const pluginParentPath = | ||
pluginPath.replace(new RegExp(`/${pluginName}/.*`,'g'), ''); |
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.
there's gotta be a better way to do this.. ;) probably with path
module?
lighthouse-core/config/config.js
Outdated
const rawPluginJson = require(pluginPath); | ||
const pluginJson = ConfigPlugin.parsePlugin(rawPluginJson, pluginName); | ||
|
||
if (rawPluginJson['localePath']) { |
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.
naming bikeshed time?!!?!
first inclination is to call it localesPath
(since theres a lot of files in there)
but i wonder if there's a more industry standard term for a directory full of i18n strings. @exterkamp ?
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.
switched to localesPath
for now
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.
Now localeStrings
due to updated config
should be said: The overall approach -- a plugin providing a relative path where LH can find a bunch of .json files with LHL messages -- SGTM. 👍 |
on second thought... :) @connorjclark points out something... in that model, LH has to readdir and blindly read everything everything off disk. Perhaps a more explicit contract would be: /** @type {LH.Config.Plugin} */
module.exports = {
audits: [{
path: 'lighthouse-plugin-example/audits/thing.js',
}],
localeStrings: {
'en-US': require('./locales/en-US.json'),
'es-419': require('./locales/es-419.json'),
},
//... with this model, LH can validate the locale codes very directly. and not rely on filename as locale code. |
+1 to above. it'd be nice to just have the config provide a path to the locale folder, but that would involve us telling browserify to explicitly bundle everything in those folder for syndicated plugins + expecting the files to be a certain filename ( We can still merge just the one locale when resolving the config. That's orthogonal to the above. |
…cales. Only augment user's locale.
We are i18n'ing the report in DevTools soon (https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2382176), so we should get this plugin translated. We recently moved stack packs and its strings into its own npm package, and look into our own Of course, plugins being able to provide their own locales is a worthy feature, but I think for now we don't need to go there. |
@connorjclark Yeah, sorry to have been sitting on this for so long. We actually have an existing pipeline, with translations that just need to be packaged, I should be able to cut a new release including those this week. |
That's fine, we'll need to do this then. We can't prioritize this at the moment, so it's likely this plugin will initially be the only untranslated category within CDT. |
To expand:
|
Replacing with #11602 |
This is just a start but wanted to get initial thoughts.
This allows for a plugin to define a directory containing their locale files, we assume that all files follow the format
${locale}.json
.I've introduced
aliases.js
which should be able to be used for both core and plugin locales, however I may be missing something in the purpose oflocales.js
.Bug: #9641