Skip to content

Commit

Permalink
1.2.0: Updated i18nline
Browse files Browse the repository at this point in the history
  • Loading branch information
Download committed Nov 7, 2016
1 parent 65ad49b commit f33087b
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
65 changes: 46 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
██║ ██║ ██║███████╗██║ ██║╚██████╗ ██║ ██║ ██║ ╚████║███████╗██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝
KEEP YOUR TRANSLATIONS IN LINE - WITH PREACT!
keep your translations in line - with preact!
```

preact-i18nline brings [I18nline](https://github.com/download/i18nline)
Expand Down Expand Up @@ -133,12 +133,12 @@ within a translated element.
## Installation

```sh
npm install -S i18n-js i18nline preact-i18nline
npm install -S i18nline preact-i18nline
```

## Configuration

In your `package.json`, create an object named `"i18nline"` and
In your `package.json`, create an object named `"i18n"` and
specify your project's global configuration settings there. Or,
if you prefer, you can create a `.i18nrc` options file in the root
of your project.
Expand Down Expand Up @@ -206,37 +206,63 @@ you use ember-cli, sprockets, grunt concat, etc., it's relatively
painless to add a little glue code that runs preprocess on each
source file.

### 4. add the preact-i18nline runtime extensions to i18n-js
## Add the preact-i18nline runtime extensions to i18n

Assuming you have a cjs-style app, do something like this:
Both i18nline and preact-i18nline add some extensions to i18n.js to
help with the runtime processing of the translations. You can require
I18n via preact-i18nline to get a `I18n` object that has all extensions
applied already:

```js
var I18n = require("./path/to/cjs'd/i18n");
require("i18nline/dist/lib/extensions/i18n_js")(I18n);
require("preact-i18nline/dist/extensions/i18n_js")(I18n);
var I18n = require("preact-i18nline/i18n");
```

If you're using AMD/`<script>`/something else, see the [i18nline-js README](https://github.com/jenseng/i18nline-js#installation)
for hints; these extensions can be set up exactly the same way as
i18nline-js's.
Alternatively, you can apply the extensions manually:

```js
var I18n = // get it from somewhere, script tag, whatever
require('i18nline/lib/extensions/i18n_js')(I18n);
require('preact-i18nline/dist/extensions/i18n_js')(I18n);
```

## Working with translations

Since preact-i18nline is just an i18nline plugin, you can use the
i18nline bin / grunt task to extract translations from your codebase;
it will pick up normal `I18n.t` usage, as well as your new
`translate="yes"` components.
Since preact-i18nline is just an i18nline plugin, you can use the i18nline
CLI to extract translations from your codebase; it will pick up normal
`I18n.t` usage, as well as your new `translate="yes"` components. The
easiest way to do this is to add a `"scripts"` section to your package.json
and call i18nline from there:

*package.json*
```json
{
"i18n": {
"plugins": {
"preact-i18nline"
}
},
"scripts": {
"translations": "i18nline export"
}
}
```

Then you can simply invoke it via NPM as usual:

```sh
$ npm run translations
```

Once you've gotten all your translations back from the translators,
simply stick them the giant blob 'o json on `I18n.translations`; it
expects the translations to be of the format:
simply stick them on `I18n.translations`; it expects the translations
to be of the format:

```js
I18n.translations = {
"en": {
"some_key": "Hello World",
"another_key": "What's up?"
}
},
"es": {
"some_key": "Hola mundo",
"another_key": "¿Qué tal?"
Expand All @@ -247,7 +273,8 @@ I18n.translations = {

## Configuration

In addition to the [i18nline configuration](https://github.com/download/i18nline#configuration),
In addition to the
[i18nline configuration](https://github.com/download/i18nline#configuration),
preact-i18nline adds some options specific to JSX processing:

### autoTranslateTags
Expand Down
1 change: 1 addition & 0 deletions dist/extensions/i18n_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var ComponentInterpolator = require("../ComponentInterpolator");

var extend = function extend(I18n) {
I18n.ComponentInterpolator = ComponentInterpolator;
return I18n;
};

module.exports = extend;
1 change: 1 addition & 0 deletions extensions/i18n_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var ComponentInterpolator = require("../ComponentInterpolator");

var extend = function(I18n) {
I18n.ComponentInterpolator = ComponentInterpolator;
return I18n;
};

module.exports = extend;
4 changes: 4 additions & 0 deletions i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var I18n = require('i18nline/lib/i18n');
var extend = require('./dist/extensions/i18n_js');

module.exports = extend(I18n);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
"homepage": "http://github.com/download/preact-i18nline",
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.18.0",
"babel-core": "^6.18.2",
"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"eslint": "^3.9.1",
"eslint-plugin-react": "^6.4.1",
"eslint-plugin-react": "^6.6.0",
"mocha": "^3.1.2",
"preact-render-to-string": "^3.2.1",
"ulog": "^1.0.0"
Expand All @@ -54,7 +54,7 @@
},
"dependencies": {
"extend": "^3.0.0",
"i18nline": "^1.2.0",
"i18nline": "^1.2.1",
"invariant": "2.2.1",
"preact": "^6.4.0",
"recast": "^0.10.0",
Expand Down

0 comments on commit f33087b

Please sign in to comment.