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

core(i18n): export rendererFormattedStrings #5713

Merged
merged 3 commits into from
Jul 25, 2018
Merged

Conversation

patrickhulce
Copy link
Collaborator

brings i18n strings to the renderer! this tackles most of what we need for performance category. strategy is what was outlined in #5655, strings are located at lhr.i18n.rendererFormattedStrings which the renderer uses to replace its own UIStrings in util.js

the ${n} audits is definitely going to be a problem we're going to have to figure out, but for performance it only shows up for the "passed audits" section and none of the others which isn't the worst thing to live without at first if we need to

@@ -89,9 +89,10 @@ class CategoryRenderer {
// Add list of warnings or singular warning
const warningsEl = this.dom.createChildOf(titleEl, 'div', 'lh-warnings');
if (warnings.length === 1) {
warningsEl.textContent = `Warning: ${warnings.join('')}`;
// TODO(i18n): Maybe need to construct this differently
Copy link
Member

Choose a reason for hiding this comment

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

TODO(i18n): Maybe need to construct this differently

if warnings are full sentences this should be fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

alright, removed

@@ -35,6 +35,11 @@ class ReportRenderer {
renderReport(report, container) {
// If any mutations happen to the report within the renderers, we want the original object untouched
const clone = /** @type {LH.ReportResult} */ (JSON.parse(JSON.stringify(report)));
// Mutate the UIStrings if necessary (while saving originals)
Copy link
Member

Choose a reason for hiding this comment

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

should the technical debt comment below be moved up here? :)

It does kind of suck to rely on utils as a mutable singleton. We pass at least a DOM into all of our report rendering classes. Should we pass in strings? Or pass the lhr to everything, use lhr.i18n.rendererFormattedStrings.string everywhere, and here (since we're mutating the lhr anyways) could set lhr.i18n.rendererFormattedStrings to the default strings if not set.

Fine to punt to a future PR, but it would be nice to have a plan before we get too deep.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or pass the lhr to everything, use lhr.i18n.rendererFormattedStrings.string everywhere, and here (since we're mutating the lhr anyways) could set lhr.i18n.rendererFormattedStrings to the default strings if not set.

This sounds good to me, we have other LHR reaching needs like locale in config settings and such that would be nice. I accept your offer for a followup :)

Copy link
Member

Choose a reason for hiding this comment

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

add a TODO?

@@ -35,6 +35,11 @@ class ReportRenderer {
renderReport(report, container) {
// If any mutations happen to the report within the renderers, we want the original object untouched
const clone = /** @type {LH.ReportResult} */ (JSON.parse(JSON.stringify(report)));
// Mutate the UIStrings if necessary (while saving originals)
ReportRenderer.stashUIStrings();
Copy link
Member

Choose a reason for hiding this comment

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

if it's stashing just for this function, can it stored in a local variable instead of stashed in a static property?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

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.

otherwise LGTM!

@patrickhulce patrickhulce merged commit eda3a3e into master Jul 25, 2018
@patrickhulce patrickhulce deleted the i18n_renderer_strings branch July 25, 2018 00:20
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.

None yet

3 participants