Skip to content

Commit

Permalink
README.md: Add usage and demo sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Abijeet committed Nov 29, 2024
1 parent 385356f commit 25758c3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ banana-i18n is a javascript internationalization library that uses "banana" form

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Node.js](#nodejs)
- [JavaScript](#javascript)
- [Demo](#demo)
- [Developer Documentation](#developer-documentation)
- [Banana File format](#banana-file-format)
- [Loading the messages](#loading-the-messages)
Expand Down Expand Up @@ -49,6 +53,46 @@ banana-i18n is a javascript internationalization library that uses "banana" form
```
npm i banana-i18n
```
## Usage

### Node.js

```js
const Banana = require('banana-i18n');

// Initialize Banana-i18n with the default locale and messages
const banana = new Banana('en', {
messages: {
'greet-user': 'Hello, $1!',
'items-count': '$1 item(s) found.',
}
});

// Translating a simple message
console.log(banana.i18n('greet-user', 'Alice')); // Output: Hello, Alice!

// Translating with variables
console.log(banana.i18n('items-count', 5)); // Output: 5 item(s) found.

// Changing the language dynamically
banana.setLocale('fr');
banana.load({
'greet-user': 'Bonjour, $1!',
'items-count': '$1 article(s) trouvé(s).',
});

console.log(banana.i18n('greet-user', 'Alice')); // Output: Bonjour, Alice!
```

### JavaScript

For usage in JavaScript, please check the files under the `demo` folder after building the distribution files by running `npm run build`.

## Demo

See the library in action: https://wikimedia.github.io/banana-i18n/demo/

Related code can be found under the `demo` folder.

## Developer Documentation
### Banana File format
Expand Down

0 comments on commit 25758c3

Please sign in to comment.