Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivantsov/webext-i18n
Package for simplifying work with i18n in WebExtensions
https://github.com/ivantsov/webext-i18n
chrome firefox i18n internalization localization webextension
Last synced: about 1 month ago
JSON representation
Package for simplifying work with i18n in WebExtensions
- Host: GitHub
- URL: https://github.com/ivantsov/webext-i18n
- Owner: ivantsov
- Created: 2016-08-27T15:21:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-02T22:13:50.000Z (about 8 years ago)
- Last Synced: 2024-11-08T02:49:42.827Z (2 months ago)
- Topics: chrome, firefox, i18n, internalization, localization, webextension
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# webext-i18n
[![Build Status](https://travis-ci.org/ivantsov/webext-i18n.svg?branch=master)](https://travis-ci.org/ivantsov/webext-i18n)
[![codecov](https://codecov.io/gh/ivantsov/webext-i18n/branch/master/graph/badge.svg)](https://codecov.io/gh/ivantsov/webext-i18n)
[![npm version](https://badge.fury.io/js/webext-i18n.svg)](https://badge.fury.io/js/webext-i18n)This package simplifies work with i18n in WebExtensions.
### Install
`npm install webext-i18n --save-dev`
### Usage
For instance, you have the following structure:
```
src
└── locales
├── en.js
└── de.js
```And `en.js` may contain something like that:
```js
{
popup: {
title: 'Super title',
description: 'Super description',
buttons: {
login: 'Login',
remove: 'Remove account'
}
},
contentScript: {
action: 'Super action name',
text: 'Lorem ipsum',
items: [
'First item',
'Second item'
]
}
}
```Yeah, **nested** translation **entities without** specifying **`message` field**! And yes, it's not an appropriate format for WebExtensions, so you need to run the code below to generate a proper locales files:
```js
const i18n = require('webext-i18n');i18n({
inputDir: './src/locales',
outputDir: './dist/locales'
}).then(res => console.log('Generating locales is finished.');
```It will create `dist/locales` directory with `en.json` and `de.json` files inside. And `en.json` looks like that:
```json
{
"popup_title": {
"message": "Super title"
},
"popup_description": {
"message": "Super description"
},
"popup_buttons_login": {
"message": "Login"
},
"popup_buttons_remove": {
"message": "Remove account"
},
"contentScript_action": {
"message": "Super action name"
},
"contentScript_text": {
"message": "Lorem ipsum"
},
"contentScript_items_0": {
"message": "First item"
},
"contentScript_items_1": {
"message": "Second item"
}
}
```### API
The package contains only one method (the default export).
#### Options
- `inputDir` - directory with locales.
- `outputDir` - directory where generated files should be placed.
Returns a `Promise` that will be resolved when all locales are generated.