https://github.com/jamesplease/i18n-list-generator.js
Generate localized lists
https://github.com/jamesplease/i18n-list-generator.js
Last synced: 3 months ago
JSON representation
Generate localized lists
- Host: GitHub
- URL: https://github.com/jamesplease/i18n-list-generator.js
- Owner: jamesplease
- License: mit
- Created: 2016-08-31T21:24:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-31T23:39:56.000Z (almost 9 years ago)
- Last Synced: 2025-03-20T14:09:32.981Z (3 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# i18n-list-generator.js
Generate localized lists
[](https://travis-ci.org/jmeas/i18n-list-generator.js)
[](https://david-dm.org/jmeas/i18n-list-generator.js)
[](https://david-dm.org/jmeas/i18n-list-generator.js#info=devDependencies)### Motivation
Generating dynamic lists is something that often needs to be handled in your
application logic. This is because common i18n formats don't supply a syntax
for translating dynamic lists.For instance, the ICU Message Format, a popular syntax, does not support dynamic
lists.In a LTR world, generating dynamic lists is straightforward: `myList.join(', ')`.
Things get more complex in RTL languages. Some languages, like Arabic, use a
reverse comma and place the space "before" (when read left-to-right) the comma.Hebrew is also RTL, but uses the English version of the comma.
This library abstracts that logic away.
### Getting Started
The recommended way to install this library is through
[npm](https://nodejs.org/en/download/).```
npm i i18n-list-generator.js
```Then, import the library in your application.
```js
import generateList from 'i18n-list-generator';generateList([1, 2, 3], 'en');
```### API
##### `generateList( arr, languageCode )`
`arr` is the list of items. Any array-like object works as long as it implements
the `join` and `reverse` methods.`languageCode` is any ISO 639-1 language code.
### Example Usage
```js
const myArr = [1, 2, 3];generateList([1, 2, 3], 'ar')
// => '3 ،2 ،1'generateList([1, 2, 3], 'he')
// => '3 ,2 ,1'generateList([1, 2, 3], 'en')
// => '1, 2, 3'
```