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: stack-pack i18n #8154

Merged
merged 9 commits into from
Apr 16, 2019
Merged

i18n: stack-pack i18n #8154

merged 9 commits into from
Apr 16, 2019

Conversation

exterkamp
Copy link
Member

@exterkamp exterkamp commented Apr 10, 2019

Summary
Converts stack packs to use UIStrings for i18n.

@exterkamp exterkamp changed the title added UIStrings and exported to en-US. i18n: added UIStrings and exported to en-US Apr 10, 2019
@exterkamp exterkamp changed the title i18n: added UIStrings and exported to en-US i18n: stack-pack i18n Apr 10, 2019
@brendankenny
Copy link
Member

Summary

Related Issues/PRs

can you fill this in, please :)

@brendankenny
Copy link
Member

also, can we merge this into master after #7243 lands rather than continuing to grow that PR?

@exterkamp
Copy link
Member Author

Sure, just land that one and I'll change this to merge 2 master.

@exterkamp exterkamp changed the base branch from feat/stack-packs to master April 10, 2019 20:08
Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

seems good.

stack-packs/packs/wordpress.js Outdated Show resolved Hide resolved
stack-packs/packs/wordpress.js Outdated Show resolved Hide resolved
@@ -7,40 +7,62 @@

'use strict';

const i18n = require('../../lighthouse-core/lib/i18n/i18n.js');
Copy link
Member

Choose a reason for hiding this comment

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

to fix Travis, I think we won't be able to call out from stack-packs code to lighthouse, at least as long as we're treating stack-packs as a separate module.

I think we'll have to remove @lighthouse/stack-packs from package.json and in stack-packs.js switch const stackPacks = require('@lighthouse/stack-packs'); to const stackPacks = require('../../stack-packs/index.js');.

Maybe others have a different solution? Even as a separate module I'm not sure how we're going to have it call back into lighthouse when it's a lighthouse dep.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe others have a different solution? Even as a separate module I'm not sure how we're going to have it call back into lighthouse when it's a lighthouse dep.

What if we turned this into a function and LH passed in the i18n object?

We could still keep UIStrings at the top level so we can statically extract them but the runtime piece is addressed at least.

Copy link
Member

Choose a reason for hiding this comment

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

What if we turned this into a function and LH passed in the i18n object?

interesting idea. i just tried it and it does work.

diff --git a/lighthouse-core/lib/stack-packs.js b/lighthouse-core/lib/stack-packs.js
index b2a04fc4..591eb91b 100644
--- a/lighthouse-core/lib/stack-packs.js
+++ b/lighthouse-core/lib/stack-packs.js
@@ -6,8 +6,8 @@
 'use strict';
 
 const stackPacks = require('../../stack-packs/index.js');
+const i18n = require('./i18n/i18n.js');
 const log = require('lighthouse-logger');
-
 /**
  * Pairs consisting of a stack pack's ID and the set of stacks needed to be
  * detected in a page to display that pack's advice.
@@ -35,12 +35,13 @@ function getStackPacks(pageStacks) {
     }
 
     // Grab the full pack definition
-    const matchedPack = stackPacks.find(pack => pack.id === stackPackToIncl.packId);
-    if (!matchedPack) {
+    const matchedPackFn = stackPacks.find(pack => pack.id === stackPackToIncl.packId);
+    if (!matchedPackFn) {
       log.warn('StackPacks',
         `'${stackPackToIncl.packId}' stack pack was matched but is not found in stack-packs lib`);
       continue;
     }
+    const matchedPack = matchedPackFn(i18n);
 
     packs.push({
       id: matchedPack.id,
diff --git a/stack-packs/packs/wordpress.js b/stack-packs/packs/wordpress.js
index a15194ac..e5b204b6 100644
--- a/stack-packs/packs/wordpress.js
+++ b/stack-packs/packs/wordpress.js
@@ -7,8 +7,6 @@
 
 'use strict';
 
-const i18n = require('../../lighthouse-core/lib/i18n/i18n.js');
-
 
@@ -42,9 +40,11 @@ const UIStrings = {
   time_to_first_byte: 'Themes, plugins, and server specifications all contribute to server response time. Consider finding a more optimized theme, carefully selecting an optimization plugin, and/or upgrading your server.',
 };
 
-const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
 
-module.exports = {
+module.exports = function(i18n) {
+  const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
+
+return {
   id: 'wordpress',
   iconDataURL: wordpressIcon,
   title: 'WordPress',
@@ -65,4 +65,5 @@ module.exports = {
     'time-to-first-byte': str_(UIStrings.time_to_first_byte),
   },
 };
+};
 module.exports.UIStrings = UIStrings;

@exterkamp
Copy link
Member Author

I'm extracting these and sending for translation!

@exterkamp
Copy link
Member Author

Changed based on @brendankenny's ideas. I didn't commit the yarn.lock changes b/c i couldn't remember if that was just my local getting messed up with all this git merging or not.

@paulirish paulirish mentioned this pull request Apr 16, 2019
67 tasks
@paulirish
Copy link
Member

Looks good. @brendankenny ya?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

yep, LGTM!

@brendankenny brendankenny merged commit 00f4216 into master Apr 16, 2019
@brendankenny brendankenny deleted the i18n-stack-packs branch April 16, 2019 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants