Locales allow browser extensions to support multiple languages and enhancing the user experience. Extension.js handles locales defined in your manifest.json as the browser would, and ensures that they are emitted and included in the output directory, making them accessible during runtime.
Extension.js performs the following tasks for locale files in Extension.js:
manifest.json are emitted to the output directory._locales folder is provided.Extension.js offers robust support for locales, ensuring that all defined translations are correctly emitted and watched for changes. The following manifest fields are used for declaring locales:
| Manifest Field | File Type Expected | Reload |
|---|---|---|
default_locale |
.json | Live-reload |
_locales/*.json |
.json | Live-reload |
manifest.jsonHere's how to declare locales in your manifest.json:
You would then include JSON files for each locale inside the _locales folder:
messages.json FileHere's an example of a messages.json file used for translations:
The output path for locale files will follow the structure defined by the _locales folder. The resulting files will look like this:
_locales folder to organize translations for different languages.default_locale in the manifest.json to ensure proper localization support.