https://github.com/andreruffert/i18n-literally
🍦 A simple way to introduce internationalization to your JS
https://github.com/andreruffert/i18n-literally
cli i18n internationalization javascript js l10n localization template-literals translation
Last synced: about 2 months ago
JSON representation
🍦 A simple way to introduce internationalization to your JS
- Host: GitHub
- URL: https://github.com/andreruffert/i18n-literally
- Owner: andreruffert
- Created: 2019-01-30T18:03:31.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T00:21:21.000Z (2 months ago)
- Last Synced: 2025-03-29T01:02:53.645Z (2 months ago)
- Topics: cli, i18n, internationalization, javascript, js, l10n, localization, template-literals, translation
- Language: JavaScript
- Homepage: https://npm.im/i18n-literally
- Size: 271 KB
- Stars: 80
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# i18n-literally
> A simple way to introduce internationalization to your JS.
[](https://github.com/andreruffert/i18n-literally/actions?workflow=CI)
[](https://www.npmjs.com/package/i18n-literally)
[](https://www.npmjs.com/package/i18n-literally)## Install
```
$ npm install i18n-literally
```## Usage
```js
import i18n from 'i18n-literally';
import db from './i18n.db.json';// Set the database
i18n.db = db;// 1. Write in the default language
i18n`Hello ${'World'}!`
// => Hello World!// 2. Add/update your translations for a language
"$ npx i18n-literally index.js es"// 3. Get translations based on locale
i18n.locale = 'es';
i18n`Hello ${'World'}!`
// => Hola World!
```Write your entire application in the default language, and support multiple versions of the language by simply changing the `i18n.locale`. To Add/update translations simply run the [cli](#cli).
## API
### i18n\`template\`
Returns a string based on the locale (default "en").
### i18n.locale
Type: `string`
Default: `en`### i18n.db
Type: `object`
Default: `{}`## CLI
The cli helps you to easily maintain your translations in a simple web app.
All translations are stored in a [i18n.db.json](i18n.db.json) file.```console
$ npx i18n-literally --helpUsage:
$ literally [db]Arguments:
Command defaults to "edit" (edit, check-missing-translations)
The entry file of your app
Locale to add/update translations for
[db] Database file defaults to "./i18n.db.json"Options:
--root Project's root directory (default: $PWD)
--rootAlias Alias used by imports for project's root
--help Show information
--version Show current versionExamples:
$ literally edit ./index.js es
$ literally edit ./src/index.js en --root=src --rootAlias=~
```_The cli web app to add/update translations_.
## Related
Inspired by this [post](https://codeburst.io/easy-i18n-in-10-lines-of-javascript-poc-eb9e5444d71e) from [Andrea Giammarchi](https://github.com/WebReflection).
## License
MIT © [André Ruffert](https://andreruffert.com)