question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Providing i18n translations for (custom) audits

See original GitHub issue

Inject Translations for custom audits

There is currently no information in the docs on how to add I18N translations for locales for a custom audit.

I have a custom audit like the one below and want to provide a translation for a given locale (let’s say ‘fr’). How to proceed? How to inject or reference a json file with my custom translations for several locales?

'use strict';
const Audit = require('lighthouse').Audit;
const i18n = require('lighthouse/lighthouse-core/lib/i18n/i18n.js');

const UIStrings = {
  title: 'A crazy audit',
  failureTitle: 'Audit failed massively',
  description: 'This is a test. This is not real. ',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);

class MyCustomAudit extends Audit {
  static get meta() {
    return {
      id: 'my-custom-audit',
      title: str_(UIStrings.title),
      failureTitle: str_(UIStrings.failureTitle),
      description: str_(UIStrings.description),
    };
  }

  static audit(artifacts) {
    [...]
  }
}

module.exports = MyCustomAudit;

There also sees to be no way to provide another JSON files as extension to the existing locale files in lighthouse-core to overwrite an existing translation or to provide a missing translation during runtime without touching core files.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fbatschicommented, Jul 12, 2019

The reason for us to override core translations is that some of the translations are too technical for our audience of the reports, so we want to change them completely (during runtime), in other cases we simply wanted to add a sentence or two.

For the time being we have built the functionality with a handful of new lines of code to i18n.js as well as including the y18n package and preserve the changes with patch-package to enable both requested features for us.

If translations for custom audits become a core feature though, this would be appreciated.

1reaction
paulirishcommented, May 26, 2020

Update: We introduced a i18n.registerLocaleData() method in https://github.com/GoogleChrome/lighthouse/pull/9638 We didn’t intend for it to be used outside of the Lighthouse internals, but it certainly could be.

We still don’t offer a first-class i18n story for custom audits.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Translations | ThingsBoard Professional Edition
ThingsBoard Custom Translations feature allows you to upload alternative to existing language translations and extend the translation to specific GUI ...
Read more >
Website Localization Audit Offer
Definitive guide to localization (38 pages of value!) Translation checklist; Preparing your website for localization questionnaire; Manufacturing guide to ...
Read more >
Internationalization Support for Additional Languages
ServiceNow provides support for localizing the application to be translated to languages which are not available with the localization ...
Read more >
Add a custom Localization Framework setting to enable ...
Navigate to All > Localization Framework > Settings. · In the Setting list, select New. · Enter a name for the setting. ·...
Read more >
Web UI Translations | Nuxeo Documentation
Learn how translations are managed technically in Nuxeo Web UI. ... which provides the i18n method to dynamically load labels according to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found