An open API service indexing awesome lists of open source software.

https://github.com/neetjn/r-localize

Localization plugin for Riot.js based off of Vue.js v-localize project.
https://github.com/neetjn/r-localize

google i10n i18n javascript locale localize node riot ts typescript webpack

Last synced: about 1 month ago
JSON representation

Localization plugin for Riot.js based off of Vue.js v-localize project.

Awesome Lists containing this project

README

        

# **r-localize**

[![build](https://travis-ci.org/neetjn/r-localize.svg?branch=master)](https://travis-ci.org/neetjn/r-localize/)
[![npm version](https://badge.fury.io/js/r-localize.svg)](https://badge.fury.io/js/r-localize)
[![npm](https://img.shields.io/npm/dm/r-localize.svg)](https://www.npmjs.com/package/r-localize)

[![NPM](https://nodei.co/npm/r-localize.png)](https://nodei.co/npm/r-localize/)

### About

**r-localize** is a localization plugin for Riot.js based off of Vue.js v-localize project.

### Support

| Chome | Edge | Firefox | Opera | Safari |
|--------|------|---------|----------|--------|
| 5.0+ ✔ | ✔ | 4.0+ ✔ | 11.50+ ✔ | 5.0+ ✔ |

This project was developed using Riot.js 3, support for previous versions is not available.

### Usage

To install via NPM, simply do the following:
```sh
npm install r-localize
```
For a quick start using jsdelivr:
```html

```
Using the plugin is then as simple as:

```js
import riot from 'riot'
import Localize from 'r-localize'

const options = {
debug: true,
default: 'en-US',
fallback: '-',
available: ['en-US', 'es-SP']
}

const localizations = {
'en-US': {
'header': 'international',
'menu': {
'help': 'Help'
}
},
'es-SP': {
'header': 'internacional',
'menu': {
'help': 'Ayuda'
}
}
}

localize = new Localize(riot, options, localizations)
```

Once your Riot app has been mounted, the language can be changed by calling `localize.locale(args*)` from your component.

```html


English
Spanish


locale(e) {
this.localize.locale(e.target.value)
}

```

You can specify your localizations like so:

```html


```

Alternatively, you can fetch your current localization by calling `locale` without any arguments.

```html

Current Locale: { localize.locale() }


```

For fetching a specific locale item programatically within a component method:

```js

Translated Item: { localize.translate('header', 'es-SP') }


```

### Configuration

The plugin takes 5 options,

> **`*available`**: List of available localizations.

```js
['en-US', 'es-SP', 'pr-BR', {
locale: 'ar-MS',
orientation: 'rtl'
}]
```

> **`*debug`**: Spit info, warnings and errors to console.

> **`*default`**: Default locale key to target.

> **`fallbackContent`**: Use the existing node's text content if enabled and requested localization is not found.

> **`*fallback`**: Default text to show if localization for current language not found.

> **`webStore`**: If the mixin is accessed within a web context and option `webStore` is enabled, mixin will store the locale in local storage for the next visit.

### Locale Options

Locale configuration currently supports the following options,

> **`orientation`**: Text direction of target element, useful for orientation of script languages.

> **`fontFamily`**: Font family to change to. Re: [https://www.w3schools.com/jsref/prop_style_fontfamily.asp]()

### Contributors

* **John Nolette** ([email protected])

Contributing guidelines can be found [here](https://github.com/neetjn/r-localize/blob/master/CONTRIBUTING.md).

---

Copyright (c) 2018 John Nolette Licensed under the MIT license.