GoogleChrome / GoogleChrome/lighthouse

Providing i18n translations for (custom) audits

Open
#9,296 7 comments 0 reactions 0 assignees View on GitHub
feature P3
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 20h
Merged PRs (30d)
19

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.