Skip to content

Commit

Permalink
RELEASE: v1.0.2 fixing some problemes
Browse files Browse the repository at this point in the history
  • Loading branch information
ouladck committed Jan 29, 2019
1 parent da84365 commit 9fdd942
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 35 deletions.
27 changes: 7 additions & 20 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ Create a dictionary variable, then initialize the plugin
"Hello world!": "Bonjour monde",
...
},
ja: {
jp: {
"Hello world!": "こんにちは世界",
...
}
};

const l10n = $('.gettext').l10n({
lang: 'ja',
lang: 'jp',
dictList: words
});
```
Expand All @@ -83,29 +83,17 @@ you can also use it via javascript code
## Options

```javascript
$(selector).l10n{
$(selector).l10n({
lang: 'en',
dynamicLang: false,
dictList: words
}
});
```

* The `selector` can be any CSS selector `.class`, `#id`, `[attribute]`, But not recommended to use CSS `elements` or `:pseudo-classes`

* lang: Code for the language to be translated to.<br>
default: `en`

* dynamicLang: if this option is set to `true` it will get `localStorage` `lang` item value `localStorage.getitem('lang')`
, If not found, it will use html lang attribute value `<html lang="en">`<br>,
and if set `true` it will override `lang` option so you don't need set it value example:
```javascript
$(selector).l10n{
dynamicLang: true,
dictList: words
}
```
default: false

> lang will be used in the first run or when localStorage is empty.
* dictList: The set of dictionaries of words and sentence to be used in the plugin.

## Methods
Expand All @@ -127,13 +115,12 @@ This function gets your desired text and translates it, if it's translation exis
### setLanguage

This function is only needed when `dynamicLang` option set to `true` so that you can change your language or via you JS script.
This function is needed so that you can change your language via you JS script.

#### Paramters

* lang: A string with you desired language code.
* reload (optional): To decide if you wish this function to reload the page or not.

```javascript
l10n.setLanguage('ar', false);
l10n.setLanguage('ar');
```
3 changes: 1 addition & 2 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
(function ($) {
const l10n = $('.l10n').l10n({
dynamicLang: true,
dictList: words
});

$('#via-js').html(l10n.getText('Your plugin is not working'));

$('button').click(function() {
l10n.setLanguage($(this).data('lang'), $(this).data('reload'));
l10n.setLanguage($(this).data('lang'));
});

}(jQuery));
6 changes: 3 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ <h1 class="l10n">Demo</h1>
<cite class="l10n">Plato</cite>
</div>

<button data-lang="ar" data-reload="true" class="l10n">Arabic</button>
<button data-lang="en" data-reload="true" class="l10n">English</button>
<button data-lang="fr" data-reload="true" class="l10n">French</button>
<button data-lang="ar" class="l10n">Arabic</button>
<button data-lang="en" class="l10n">English</button>
<button data-lang="fr" class="l10n">French</button>

<footer>
<p id="via-js">Your plugin is not working</p>
Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.l10n.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9fdd942

Please sign in to comment.