Skip to content

Commit

Permalink
1.0.0: i18nline
Browse files Browse the repository at this point in the history
 * Applied jenseng#18
 * Upgraded dependencies
 * Use ulog for logging
 * Add some auto-config to use `src` and/or `lib` as directories if none were specified
 * Print some helpful info at startup
 * Print some more and more detailed progress info
 * Added a help screen to the CLI tool
 * Updated README.md, License info
  • Loading branch information
Download committed Nov 2, 2016
1 parent 915889a commit 799f264
Show file tree
Hide file tree
Showing 38 changed files with 631 additions and 190 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
before_script: 'npm install -g grunt-cli'
language: node_js
node_js:
- "node"
- "4"
- "0.10"
- "iojs"
91 changes: 55 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
# I18nliner.js
# i18nline
### Keep your translations in line

[<img src="https://secure.travis-ci.org/jenseng/i18nliner-js.png"
/>](http://travis-ci.org/jenseng/i18nliner-js)
[![npm](https://img.shields.io/npm/v/ulog.svg)](https://npmjs.com/package/ulog)
[![license](https://img.shields.io/npm/l/ulog.svg)](https://creativecommons.org/licenses/by/4.0/)
[![travis](https://img.shields.io/travis/Download/ulog.svg)](https://travis-ci.org/Download/ulog)
[![greenkeeper](https://img.shields.io/david/Download/ulog.svg)](https://greenkeeper.io/)
![mind BLOWN](https://img.shields.io/badge/mind-BLOWN-ff69b4.svg)

I18nliner is I18n made simple.

```
██╗ ███╗ ██╗██╗ ██╗███╗ ██╗███████╗
██║ ████╗ ██║██║ ██║████╗ ██║██╔════╝
██║ 18 ██╔██╗ ██║██║ ██║██╔██╗ ██║█████╗
██║ ██║╚██╗██║██║ ██║██║╚██╗██║██╔══╝
██║ ██║ ╚████║███████╗██║██║ ╚████║███████╗
╚═╝ ╚═╝ ╚═══╝╚══════╝╚═╝╚═╝ ╚═══╝╚══════╝
KEEP YOUR TRANSLATIONS IN LINE
```

No .js/yml translation files. Easy inline defaults. Optional keys. Easy
pluralization. Wrappers for HTML-free translations.

I18nliner extends [i18n-js](https://github.com/fnando/i18n-js), so you can
I18nline extends [i18n-js](https://github.com/fnando/i18n-js), so you can
add it to an already-internationalized app that uses it.

## TL;DR

I18nliner lets you do stuff like this:
i18nline lets you do stuff like this:

```javascript
I18n.t("Ohai %{user}, my default translation is right here in the code. \
Expand All @@ -28,7 +41,14 @@ I18n.t("*Translators* won't see any markup!",
```

Best of all, you don't need to maintain translation files anymore;
I18nliner will do it for you.
i18nline will do it for you.

## What is this?

This project is a fork of Jon Jensen's [i18nline-js](https://github.com/jenseng/i18nline-js)
that applies some long open PR, adds some logging (powered by [ulog](https://npmjs.com/package/ulog)),
a help screen for the CLI and some auto-config. I'm hoping any changes I make in this fork will
eventually be merged back into the main project but for now I need these changes.

## Installation

Expand All @@ -40,28 +60,24 @@ several options for installing/including the runtime extensions:

### regular old script

Download the [runtime extensions](https://github.com/jenseng/i18nliner-js/blob/master/build/i18n_js_extension.js)
Download the [runtime extensions](https://github.com/download/i18nline/blob/master/build/i18n_js_extension.js)
and include them on the page after i18n.js (via `<script>`, asset pipeline, etc).

### npm

```bash
npm install i18nliner --save
```sh
npm install -S i18n-js i18nline
```

You'll need to shoehorn i18n.js into your app, which (as of this writing)
is not CJS-compatible :-/, e.g.

```javascript
// assuming you shoehorn this in
var I18n = require("./path/to/cjs'd/i18n");
var I18n = require('i18n-js');
// add the runtime extensions
require("i18nliner/dist/lib/extensions/i18n_js")["default"](I18n);
require('i18nline/dist/lib/extensions/i18n_js')['default'](I18n);
```

### amd

Download the [runtime extensions](https://github.com/jenseng/i18nliner-js/blob/master/build/i18n_js_extension.js)
Download the [runtime extensions](https://github.com/download/i18nline/blob/master/build/i18n_js_extension.js)
and use the requirejs shim config to add them (and i18n.js) to your app, e.g.

```javascript
Expand Down Expand Up @@ -100,7 +116,7 @@ the usual stuff (placeholders, etc.).
Sure, but *you* don't need to write them. Just run:

```bash
i18nliner export
i18nline export
```

This extracts all default translations from your codebase and outputs them
Expand All @@ -109,14 +125,14 @@ to `config/locales/generated/en.json`
### It's okay to lose your keys

Why waste time coming up with keys that are less descriptive than the default
translation? I18nliner makes keys optional, so you can just do this:
translation? i18nline makes keys optional, so you can just do this:

```javascript
I18n.t("My Account")
```

I18nliner will create a unique key based on the translation (e.g.
`'my_account'`), so you don't have to. See `I18nliner.inferred_key_format` for
i18nline will create a unique key based on the translation (e.g.
`'my_account'`), so you don't have to. See `i18nline.inferred_key_format` for
more information.

This can actually be a **good thing**, because when the `en` changes, the key
Expand Down Expand Up @@ -171,7 +187,7 @@ it).

So what do you do?

I18nliner lets you specify wrappers, so you can keep HTML out the translations,
i18nline lets you specify wrappers, so you can keep HTML out the translations,
while still just having a single string needing translation:

```javascript
Expand All @@ -189,7 +205,7 @@ any string as a delimiter by using a object rather than an array.

#### HTML Safety

I18nliner ensures translations, interpolated values, and wrappers all play
i18nline ensures translations, interpolated values, and wrappers all play
nicely (and safely) when it comes to HTML escaping. Wrappers are assumed
to be HTML-safe, so everything else that is unsafe will get
automatically escaped. If you are using i18n.js, you can hint that an
Expand All @@ -206,7 +222,7 @@ escaped.
### Inline Pluralization Support

Pluralization can be tricky, but i18n.js gives you some flexibility.
I18nliner brings this inline with a default translation object, e.g.
i18nline brings this inline with a default translation object, e.g.

```javascript
I18n.t({one: "There is one light!", other: "There are %{count} lights!"},
Expand All @@ -231,25 +247,25 @@ I18n.t({one: "1 person", other: "%{count} people"},

## Command Line Utility

### i18nliner check
### i18nline check

Ensures that there are no problems with your translate calls (e.g. missing
interpolation values, reusing a key for a different translation, etc.). **Go
add this to your Jenkins/Travis tasks.**

### i18nliner export
### i18nline export

Does an `i18nliner check`, and then extracts all default translations from your
Does an `i18nline check`, and then extracts all default translations from your
codebase, merges them with any other translation files, and outputs them to
`locales/generated/translations.json` (or `.js`).

### i18nliner diff
### i18nline diff

Does an `i18nliner export` and creates a diff from a previous one (path or git
Does an `i18nline export` and creates a diff from a previous one (path or git
commit hash). This is useful if you only want to see what has changed since a
previous release of your app.

### i18nliner import
### i18nline import

Imports a translated .json/.js file. Ensures that all placeholders and
wrappers are present.
Expand All @@ -267,21 +283,24 @@ If you only want to check a particular file/directory/pattern, you can set the
`--only` option when you run the command, e.g.

```bash
i18nliner check --only=/app/**/user*
i18nline check --only=/app/**/user*
```

## Compatibility

I18nliner is backwards compatible with i18n.js, so you can add it to an
i18nline is backwards compatible with i18n.js, so you can add it to an
established (and already internationalized) app. Your existing
translation calls, keys and translation files will still just work without modification.

## Related Projects

* [i18nliner (ruby)](https://github.com/jenseng/i18nliner)
* [i18nliner-handlebars](https://github.com/fivetanley/i18nliner-handlebars)
* [react-i18nliner](https://github.com/jenseng/react-i18nliner)
* [i18nline (ruby)](https://github.com/jenseng/i18nline)
* [i18nline-js](https://github.com/jenseng/i18nline-js)
* [i18nline-handlebars](https://github.com/fivetanley/i18nline-handlebars)
* [react-i18nline](https://github.com/jenseng/react-i18nline)
* [preact-i18nline](https://github.com/download/preact-i18nline)

## License

Copyright (c) 2015 Jon Jensen, released under the MIT license
Copyright (c) 2016 Stijn de Witt && Jon Jensen,
released under the MIT license
7 changes: 7 additions & 0 deletions bin/i18nline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env node

var minimist = require('minimist');
var argv = minimist(process.argv.slice(2));
var i18nline = require('../dist/lib/main').default;

i18nline.Commands.run(argv._[0], argv);
5 changes: 0 additions & 5 deletions bin/i18nliner

This file was deleted.

30 changes: 21 additions & 9 deletions build/i18n_js_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ module.exports = require('./lib/');
'fr': {
'∆': 'delta',
'∞': 'infiniment',
'♥': 'Amour',
'♥': 'amour',
'&': 'et',
'|': 'ou',
'<': 'moins que',
Expand All @@ -752,6 +752,18 @@ module.exports = require('./lib/');
'¤': 'monnaie'
},

'nl': {
'∆': 'delta',
'∞': 'oneindig',
'♥': 'liefde',
'&': 'en',
'|': 'of',
'<': 'kleiner dan',
'>': 'groter dan',
'∑': 'som van',
'¤': 'valuta'
},

'pt': {
'∆': 'delta',
'∞': 'infinito',
Expand Down Expand Up @@ -808,7 +820,7 @@ module.exports = require('./lib/');
"use strict";
var pluralize = require("./pluralize")["default"] || require("./pluralize");
var Utils = require("./utils")["default"] || require("./utils");
var I18nliner = require("./i18nliner")["default"] || require("./i18nliner");
var I18nline = require("./i18nline")["default"] || require("./i18nline");
var getSlug = require("speakingurl")["default"] || require("speakingurl");
var crc32 = require("crc32")["default"] || require("crc32");

Expand Down Expand Up @@ -857,7 +869,7 @@ var CallHelpers = {

keyifyUnderscored: function(string) {
var key = getSlug(string, {separator: '_', lang: false}).replace(/[-_]+/g, '_');
return key.substring(0, I18nliner.underscoredKeyLength);
return key.substring(0, I18nline.underscoredKeyLength);
},

keyifyUnderscoredCrc32: function(string) {
Expand All @@ -866,7 +878,7 @@ var CallHelpers = {
},

keyify: function(string) {
switch (I18nliner.inferredKeyFormat) {
switch (I18nline.inferredKeyFormat) {
case 'underscored':
return this.keyifyUnderscored(string);
case 'underscored_crc32':
Expand Down Expand Up @@ -958,7 +970,7 @@ var CallHelpers = {
};

exports["default"] = CallHelpers;
},{"./i18nliner":8,"./pluralize":9,"./utils":10,"crc32":1,"speakingurl":3}],6:[function(require,module,exports){
},{"./i18nline":8,"./pluralize":9,"./utils":10,"crc32":1,"speakingurl":3}],6:[function(require,module,exports){
"use strict";
var CallHelpers = require("../call_helpers")["default"] || require("../call_helpers");
var Utils = require("../utils")["default"] || require("../utils");
Expand Down Expand Up @@ -1013,7 +1025,7 @@ var extend = function(I18n) {
I18n.CallHelpers = CallHelpers;
I18n.Utils = Utils;

I18n.translateWithoutI18nliner = I18n.translate;
I18n.translateWithoutI18nline = I18n.translate;
I18n.translate = function() {
var args = CallHelpers.inferArguments([].slice.call(arguments));
var key = args[0];
Expand All @@ -1023,7 +1035,7 @@ var extend = function(I18n) {
if (defaultValue)
options.defaultValue = CallHelpers.normalizeDefault(defaultValue, options);

return this.translateWithoutI18nliner(key, options);
return this.translateWithoutI18nline(key, options);
};
I18n.t = I18n.translate;
};
Expand All @@ -1038,7 +1050,7 @@ extend(I18n);
"use strict";
var fs = require("fs")["default"] || require("fs");

var I18nliner = {
var I18nline = {
ignore: function() {
var ignores = [];
if (fs.existsSync(".i18nignore")) {
Expand All @@ -1062,7 +1074,7 @@ var I18nliner = {
underscoredKeyLength: 50,
basePath: "."
};
exports["default"] = I18nliner;
exports["default"] = I18nline;
},{"fs":2}],9:[function(require,module,exports){
"use strict";
// ported pluralizations from active_support/inflections.rb
Expand Down
8 changes: 4 additions & 4 deletions dist/lib/call_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var _utils = require('./utils');

var _utils2 = _interopRequireDefault(_utils);

var _i18nliner = require('./i18nliner');
var _i18nline = require('./i18nline');

var _i18nliner2 = _interopRequireDefault(_i18nliner);
var _i18nline2 = _interopRequireDefault(_i18nline);

var _speakingurl = require('speakingurl');

Expand Down Expand Up @@ -69,7 +69,7 @@ var CallHelpers = {

keyifyUnderscored: function keyifyUnderscored(string) {
var key = (0, _speakingurl2.default)(string, { separator: '_', lang: false }).replace(/[-_]+/g, '_');
return key.substring(0, _i18nliner2.default.config.underscoredKeyLength);
return key.substring(0, _i18nline2.default.config.underscoredKeyLength);
},

keyifyUnderscoredCrc32: function keyifyUnderscoredCrc32(string) {
Expand All @@ -78,7 +78,7 @@ var CallHelpers = {
},

keyify: function keyify(string) {
switch (_i18nliner2.default.config.inferredKeyFormat) {
switch (_i18nline2.default.config.inferredKeyFormat) {
case 'underscored':
return this.keyifyUnderscored(string);
case 'underscored_crc32':
Expand Down
Loading

0 comments on commit 799f264

Please sign in to comment.