Skip to content

Commit

Permalink
Add docs in README
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoDanin committed Oct 11, 2018
1 parent cd2ed33 commit 4d95edb
Showing 1 changed file with 93 additions and 2 deletions.
95 changes: 93 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,93 @@
# NodeJS-i18n
[WIP] Minimalistic internationalization using gettext style for NodeJS
# NodeJS i18n [![Build Status](https://travis-ci.org/TiagoDanin/NodeJS-i18n.svg?branch=master)](https://travis-ci.org/TiagoDanin/NodeJS-i18n)

Minimalistic internationalization using gettext style for NodeJS.

## Features

- Gettext style
- Easy of use
- Create .po via CLI
- Select lang per user

## How to Use

### Example
```javascript
const { Resources, Translation } = require('nodejs-i18n')

const r = new Resources()
r.load('pt', 'pt.po')

var user = new Translation('pt')
var world = user._`world` // Mundo
user._`Hello ${world}` // Olá mundo
```

#### Options :: Resources({})
- **lang** - String
> Lang id.</br>
> Default value: `en`
#### Options :: Resources({}).load(lang, file)
Load translation

- **lang** - String
> Lang id.</br>
- **file** - String
> File path
#### Options :: Resources({}).remove()
Remove translation.

- **lang** - String
> Lang id.</br>
#### Options :: Translation(lang)
Select translation.

- **lang** - String
> Lang id.</br>
#### Options :: Translation(lang).\_(string)
String translation.

- **String** - String

### CLI

Create .po file with `nodejs-i18n`. Example: add in package.json

```json
"scripts": {
"i18n": "find . | grep .js | sort | nodejs-i18n > en.po"
}
```

and run `$ npm run i18n`

## Installation

This is a [Node.js](https://nodejs.org/) module available through the
[npm registry](https://www.npmjs.com/). It can be installed using the
[`npm`](https://docs.npmjs.com/getting-started/installing-npm-packages-locally)
or
[`yarn`](https://yarnpkg.com/en/)
command line tools.

```sh
npm install nodejs-i18n --save
```

## Dependencies

- [gettext-parser](https://ghub.io/gettext-parser): Parse and compile gettext po and mo files to/from json, nothing more, nothing less
- [tempy](https://ghub.io/tempy): Get a random temporary file or directory path

## Dev Dependencies

- [mocha](https://ghub.io/mocha): simple, flexible, fun test framework

## License

MIT

0 comments on commit 4d95edb

Please sign in to comment.