NodeJS i18n
Minimalistic internationalization using gettext style for NodeJS
Features
- Gettext Style
- Easy Imprementation
- Create .po via CLI
- Select Lang per User
Installation
Module available through the npm registry. It can be installed using the npm
or yarn
command line tool.
# Yarn (Recomend) yarn global add nodejs-i18n# NPM npm install nodejs-i18n --global
Usage
# Create file find . | grep .js | sort | nodejs-i18n > en.po # Create file (all strings) [beta] find . | grep .js | sort | nodejs-i18n --all > en.po # Create file (get identifier value) [beta] find . | grep .js | sort | nodejs-i18n --value > en.po
Example
const Resources Translation = const resources = resources const user = 'pt' //i18n: My Hello World with NodeJs i18nconst world = user_`world` // Mundouser_`Hello ` // Olá mundo
Documentation
Options
Options :: Resources({})
- lang - String
Lang id.
Default value:en
Options :: Resources({}).load(lang, file)
Load translation
- lang - String
Lang id.
- file - String
File path
Options :: Resources({}).remove()
Remove translation.
- lang - String
Lang id.
Options :: Translation(lang)
Select translation.
- lang - String
Lang id.
Options :: Translation(lang)._(string)
String translation.
- String - String
CLI
Create en.po files with nodejs-i18n
. Add in your package.json
"scripts":
and run $ npm run i18n
or $ yarn i18n
Tests
To run the test suite, first install the dependencies, then run test
:
# Using Yarn yarn test
Dependencies
esprima: ECMAScript parsing infrastructure for multipurpose analysis
Author: Ariya HidayatLicense: BSD-2-Clause
Version: ^4.0.1
gettext-parser: Parse and compile gettext po and mo files to/from json, nothing more, nothing less
Author: Andris ReinmanLicense: MIT
Version: ^4.0.3
tempy: Get a random temporary file or directory path
Author: Sindre SorhusLicense: MIT
Version: 0.5.0
Dev Dependency
Related
gettext-parser: Parse and compile gettext po and mo files to/from json, nothing more, nothing less
Author: Andris ReinmanLicense: MIT
Contributors
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. List of all contributors.