Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
 - Untie from `templating` package, now package can be used with
React.js, Vue.js, and other JS front-end frameworks
 - Add `.addl10n()` method, allowing dynamic l10n loading and exact
code splitting
 - Dependencies update
 - Compatibility with `meteor@1.6.1.1`
 - Overall codebase enhancements
  • Loading branch information
dr-dimitru committed Apr 21, 2018
1 parent 69643b6 commit eb218d3
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 135 deletions.
40 changes: 13 additions & 27 deletions .versions
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
babel-compiler@6.24.7
babel-runtime@1.1.1
babel-compiler@7.0.7
babel-runtime@1.2.0
base64@1.0.10
blaze@2.1.8
blaze-tools@1.0.10
caching-compiler@1.1.9
caching-html-compiler@1.0.6
check@1.2.5
deps@1.0.12
diff-sequence@1.0.7
ecmascript@0.9.0
check@1.3.0
dynamic-import@0.3.0
ecmascript@0.10.6
ecmascript-runtime@0.5.0
ecmascript-runtime-client@0.5.0
ecmascript-runtime-client@0.6.0
ecmascript-runtime-server@0.5.0
ejson@1.1.0
html-tools@1.0.11
htmljs@1.0.11
id-map@1.0.9
jquery@1.11.10
meteor@1.8.0
modules@0.11.0
modules-runtime@0.9.0
mongo-id@1.0.6
observe-sequence@1.0.16
http@1.4.1
meteor@1.8.2
modules@0.11.3
modules-runtime@0.9.1
ostrio:cstorage@2.2.1
ostrio:i18n@3.0.3
promise@0.10.0
random@1.0.10
ostrio:i18n@3.1.0
promise@0.10.1
reactive-var@1.0.11
spacebars@1.0.12
spacebars-compiler@1.1.0
templating@1.2.13
templating-tools@1.1.1
tracker@1.1.3
underscore@1.0.10
url@1.2.0
67 changes: 44 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Reactive i18n and l10n isomorphic driver
========
Object based, fast, lightweight (*306 lines with comments*) and reactive internationalization isomorphic driver for Meteor with support of placeholders.
Object based, fast, lightweight (*306 lines with comments*) and reactive internationalization isomorphic driver for Meteor with support of placeholders, and user's locale auto-detection.

Not tied to Blaze, can be used with Vue.js, React.js or any other JS solution.

Install:
========
Expand All @@ -10,12 +12,12 @@ meteor add ostrio:i18n

Import:
========
```jsx
```js
import I18N from 'meteor/ostrio:i18n';
```

### Object-based structure
```jsx
```js
/* Isomorphic (Both Server and Client) */
const i18nConfig = {
settings: { //--> Config object
Expand All @@ -37,7 +39,7 @@ const i18nConfig = {
nestedProp: "value"
},
dynamicProperty(){
return '<a href="/' + this.currentLocale.get() + '/info">info</a>';
return `<a href="/${this.currentLocale.get()}/info">info</a>`;
}
},
en:{ //--> Localization with key of country two-letter code
Expand All @@ -46,7 +48,7 @@ const i18nConfig = {
nestedProp: "value"
},
dynamicProperty(){
return '<a href="/' + this.currentLocale.get() + '/info">info</a>';
return `<a href="/${this.currentLocale.get()}/info">info</a>`;
}
}
...
Expand All @@ -58,7 +60,7 @@ const i18n = new I18N({i18n: i18nConfig});

Initialization
========
```jsx
```js
import I18N from 'meteor/ostrio:i18n';
const i18n = new I18N(config);
```
Expand All @@ -74,7 +76,7 @@ API
- `locale` {*String*} - [Optional] Two-letter locale string, used to force locale, if not set __current locale__ is used
- `key` {*String*} - l10n key like: `folder.file.object.key`
- `replacements..` {*String*|[*String*]|*Object*} - [Optional] Replacements for placeholders in l10n string
```jsx
```js
i18n.get('file.obj.key'); // Current locale, no replacements

i18n.get(locale, param); // Force locale, no replacements
Expand All @@ -93,7 +95,7 @@ i18n.get('en', 'file.obj.key', 'User Name'); // Hello {{username}} -> Hello User
- `locale` {*String*} - [Optional] Two-letter locale string, used to force locale, if not set __current locale__ is used
- `key` {*String*} - l10n key like: `folder.file.object.key`

```jsx
```js
i18n.has('file.obj.key'); // Current locale
i18n.has(locale, param); // Force locale
i18n.has('ca', 'file.obj.key'); //false
Expand All @@ -102,22 +104,32 @@ i18n.has('en', 'file.obj.key'); //true

##### `setLocale(locale)`
- `locale` {*String*} - Two-letter locale code
```jsx
```js
i18n.setLocale(locale);
```

##### `addl10n(l10n)`
- `l10n` {*Object*} - Object with language set
```js
i18n.addl10n({
en: { // <- Object's root is the language two-letter code
newKey: "New Value"
}
});
```

##### Get current localization at any environment
```jsx
```js
i18n.currentLocale.get(); // Reactive on Client
```

##### Get current default locale
```jsx
```js
i18n.defaultLocale;
```

##### Get configuration object
```jsx
```js
i18n.langugeSet();
/* Returns:
{
Expand Down Expand Up @@ -148,22 +160,24 @@ i18n.langugeSet();

##### Get specific key from configuration object
- `key` {*String*} - One of the keys: `current`, `all`, `other`, `locales`, `currentISO`, `currentName`, `currentPath`
```jsx
```js
i18n.getSetting('current'); // en
```

Client specific usage
================
##### Client's browser locale
```jsx
```js
i18n.userLocale; // en-US
```

Template helpers
================
`i18n` - accepts `locale`, `key` and `replacements`:
__Template helpers requires__ `templating` __package to be installed__.

`i18n` helper - accepts `locale`, `key` and `replacements`:
*You may change name of the helper via config object: `config.helperName`*
```html
```handlebars
<p>{{i18n 'sample.hello'}}</p>
<p>{{{i18n 'sample.html'}}}</p>
<p>{{i18n 'sample.fullName'}}</p>
Expand All @@ -176,38 +190,45 @@ Template helpers

`i18nSettings` - accepts configuration object key, one of `current`, `all`, `other`, `locales`
*You may change name of the helper via config object: `config.helperSettingsName`*
```html
```handlebars
{{#each i18nSettings 'all'}}
...
{{/each}}
```

##### Template language switcher example
```html
```handlebars
<template name="langSwitch">
{{#each i18nSettings 'all'}}
{{#if compare code '==' currentLocale}}
<span title="Current language">{{name}}</span>&nbsp;
{{else}}
<a href="#" data-code="{{code}}" class="switch-language">{{name}}</a>&nbsp;
<a href="#" data-switch-language="{{code}}">{{name}}</a>&nbsp;
{{/if}}
{{/each}}
</template>
```
```jsx
```js
Template.langSwitch.helpers({
currentLocale(){
return i18n.currentLocale.get()
}
});

Template.langSwitch.events({
'click .switch-language'(e, template) {
'click [data-switch-language]'(e) {
e.preventDefault();
i18n.setLocale(e.currentTarget.dataset.code);
i18n.setLocale(e.currentTarget.dataset.switchLanguage);
return false;
}
});
```

Template helpers `compare`, `==`, `Session` and many more comes from: [ostrio:templatehelpers](https://atmospherejs.com/ostrio/templatehelpers) package
Template helpers `compare`, `==`, `Session` and many more comes from: [`ostrio:templatehelpers`](https://atmospherejs.com/ostrio/templatehelpers) package.


Support this project:
========
This project wouldn't be possible without [ostr.io](https://ostr.io).

Using [ostr.io](https://ostr.io) you are not only [protecting domain names](https://ostr.io/info/domain-names-protection), [monitoring websites and servers](https://ostr.io/info/monitoring), using [Prerendering for better SEO](https://ostr.io/info/prerendering) of your JavaScript website, but support our Open Source activity, and great packages like this one could be available for free.
Loading

0 comments on commit eb218d3

Please sign in to comment.