diff --git a/.babelrc b/.babelrc
new file mode 100644
index 0000000..0932411
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,4 @@
+{
+ "presets": ["es2015", "react"],
+ "plugins": ["transform-react-jsx"]
+}
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..8861aaf
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,2 @@
+/examples
+/dist
diff --git a/.eslintrc.yml b/.eslintrc.yml
new file mode 100644
index 0000000..923a5e8
--- /dev/null
+++ b/.eslintrc.yml
@@ -0,0 +1,229 @@
+env:
+ es6: true
+ node: true
+ jasmine: true
+ jest: true
+extends: 'eslint:recommended'
+parserOptions:
+ ecmaFeatures:
+ experimentalObjectRestSpread: true
+ jsx: true
+ sourceType: module
+plugins:
+ - react
+rules:
+ accessor-pairs: error
+ array-bracket-spacing:
+ - error
+ - never
+ array-callback-return: error
+ arrow-body-style: error
+ arrow-parens: error
+ arrow-spacing: error
+ block-scoped-var: error
+ block-spacing:
+ - error
+ - always
+ brace-style: 'off'
+ callback-return: error
+ camelcase:
+ - error
+ - properties: never
+ comma-spacing:
+ - error
+ - after: true
+ before: false
+ comma-style:
+ - error
+ - last
+ complexity: error
+ computed-property-spacing:
+ - error
+ - never
+ consistent-return: 'off'
+ consistent-this: error
+ curly: 'off'
+ default-case: error
+ dot-location:
+ - error
+ - property
+ dot-notation: error
+ eol-last: error
+ eqeqeq: error
+ func-names: 'off'
+ func-style: 'off'
+ generator-star-spacing: error
+ global-require: 'off'
+ guard-for-in: 'off'
+ handle-callback-err: error
+ id-blacklist: error
+ id-length: 'off'
+ id-match: error
+ indent: 'off'
+ init-declarations: 'off'
+ jsx-quotes:
+ - error
+ - prefer-single
+ key-spacing: 'off'
+ keyword-spacing:
+ - error
+ - after: true
+ before: true
+ linebreak-style:
+ - error
+ - unix
+ lines-around-comment: error
+ max-depth: error
+ max-len: 'off'
+ max-lines: 'off'
+ max-nested-callbacks: error
+ max-params: 'off'
+ max-statements: 'off'
+ max-statements-per-line: error
+ new-parens: error
+ newline-after-var: 'off'
+ newline-before-return: 'off'
+ newline-per-chained-call: error
+ no-alert: error
+ no-array-constructor: error
+ no-bitwise: error
+ no-caller: error
+ no-catch-shadow: error
+ no-confusing-arrow: error
+ no-continue: 'off'
+ no-div-regex: error
+ no-duplicate-imports: error
+ no-else-return: 'off'
+ no-empty-function: error
+ no-eq-null: error
+ no-eval: error
+ no-extend-native: error
+ no-extra-bind: error
+ no-extra-label: error
+ no-extra-parens: 'off'
+ no-floating-decimal: error
+ no-implicit-globals: error
+ no-implied-eval: error
+ no-inline-comments: error
+ no-inner-declarations:
+ - error
+ - functions
+ no-invalid-this: 'off'
+ no-iterator: error
+ no-label-var: error
+ no-labels: error
+ no-lone-blocks: error
+ no-lonely-if: error
+ no-loop-func: error
+ no-magic-numbers: 'off'
+ no-mixed-operators: error
+ no-mixed-requires: error
+ no-multi-spaces: 'off'
+ no-multi-str: error
+ no-multiple-empty-lines: error
+ no-native-reassign: error
+ no-negated-condition: error
+ no-nested-ternary: error
+ no-new: error
+ no-new-func: error
+ no-new-object: error
+ no-new-require: error
+ no-new-wrappers: error
+ no-octal-escape: error
+ no-param-reassign: 'off'
+ no-path-concat: 'off'
+ no-plusplus: 'off'
+ no-process-env: error
+ no-process-exit: error
+ no-proto: error
+ no-prototype-builtins: 'off'
+ no-restricted-globals: error
+ no-restricted-imports: error
+ no-restricted-modules: error
+ no-restricted-syntax: error
+ no-return-assign: error
+ no-script-url: error
+ no-self-compare: error
+ no-sequences: error
+ no-shadow: 'off'
+ no-shadow-restricted-names: error
+ no-spaced-func: error
+ no-sync: error
+ no-ternary: 'off'
+ no-throw-literal: error
+ no-trailing-spaces: error
+ no-undef-init: error
+ no-undefined: error
+ no-underscore-dangle: error
+ no-unmodified-loop-condition: error
+ no-unneeded-ternary: error
+ no-unsafe-finally: error
+ no-unused-expressions: error
+ no-use-before-define: 'off'
+ no-useless-call: error
+ no-useless-computed-key: error
+ no-useless-concat: error
+ no-useless-constructor: error
+ no-useless-escape: error
+ no-useless-rename: error
+ no-var: 'off'
+ no-void: error
+ no-warning-comments: error
+ no-whitespace-before-property: error
+ no-with: error
+ object-curly-newline: error
+ object-curly-spacing: 'off'
+ object-property-newline: error
+ object-shorthand: 'off'
+ one-var: 'off'
+ one-var-declaration-per-line: 'off'
+ operator-assignment:
+ - error
+ - always
+ operator-linebreak: error
+ padded-blocks: 'off'
+ prefer-arrow-callback: 'off'
+ prefer-const: error
+ prefer-reflect: 'off'
+ prefer-rest-params: 'off'
+ prefer-spread: 'off'
+ prefer-template: 'off'
+ quote-props: 'off'
+ quotes: 'off'
+ radix: error
+ "react/jsx-uses-react": 1
+ require-jsdoc: 'off'
+ require-yield: error
+ rest-spread-spacing: error
+ semi: error
+ semi-spacing:
+ - error
+ - after: true
+ before: false
+ sort-imports: error
+ sort-vars: 'off'
+ space-before-blocks: 'off'
+ space-before-function-paren: 'off'
+ space-in-parens:
+ - error
+ - never
+ space-infix-ops: error
+ space-unary-ops: error
+ spaced-comment:
+ - error
+ - always
+ strict: error
+ template-curly-spacing:
+ - error
+ - never
+ unicode-bom:
+ - error
+ - never
+ valid-jsdoc: error
+ vars-on-top: 'off'
+ wrap-iife: error
+ wrap-regex: error
+ yield-star-spacing: error
+ yoda:
+ - error
+ - never
diff --git a/.nvmrc b/.nvmrc
new file mode 100644
index 0000000..c15d876
--- /dev/null
+++ b/.nvmrc
@@ -0,0 +1 @@
+v6.2.1
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c6d1550
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+before_script: 'npm install'
+language: node_js
+node_js:
+ - "6"
diff --git a/ComponentInterpolator.js b/ComponentInterpolator.js
index 5889d25..d6ec36e 100644
--- a/ComponentInterpolator.js
+++ b/ComponentInterpolator.js
@@ -28,7 +28,7 @@ var injectNewDescendants = function(element, newDescendants, props, ensureInject
newDescendants.injectedCount++;
}
- props.children = children;
+ props.children = children.length ? children : null;
if (ensureInjected) {
invariant(newDescendants.injectedCount === 1, 'wrappers must have a single "$1" text descendant');
}
diff --git a/README.md b/README.md
index 7b517fb..34ee559 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,7 @@
# react-i18nliner
+[](http://travis-ci.org/jenseng/react-i18nliner)
+
react-i18nliner brings [I18nliner](https://github.com/jenseng/i18nliner-js)
to React via the [html `translate` attribute](http://www.w3.org/International/questions/qa-translate-flag). I18n doesn't get any easier than this.
diff --git a/__tests__/ComponentInterpolator.test.js b/__tests__/ComponentInterpolator.test.js
index 79476b4..89d7fdf 100644
--- a/__tests__/ComponentInterpolator.test.js
+++ b/__tests__/ComponentInterpolator.test.js
@@ -1,9 +1,10 @@
var subjector = require('../test_utils/subjector');
var Subject = subjector(__dirname + '/../ComponentInterpolator');
var React = require('react');
+var ReactDOM = require('react-dom');
var removeNoise = function(string) {
- return string.replace(/|<\/span>/g, '')
+ return string.replace(//g, '')
.replace(/ data-reactid=".*?"/g, '');
};
@@ -14,7 +15,7 @@ describe('ComponentInterpolator', function() {
wrappers: {}
}, ["$1"]);
expect(subject.isMounted()).toEqual(true);
- expect(subject.getDOMNode().textContent).toEqual('Hello World');
+ expect(ReactDOM.findDOMNode(subject).textContent).toEqual('Hello World');
});
it('escapes html in the string', function() {
@@ -22,7 +23,7 @@ describe('ComponentInterpolator', function() {
string: 'My favorite tag is ',
wrappers: {}
}, ["$1"]);
- expect(subject.getDOMNode().textContent).toEqual('My favorite tag is ');
+ expect(ReactDOM.findDOMNode(subject).textContent).toEqual('My favorite tag is ');
});
it('interpolates wrapper components', function() {
@@ -34,7 +35,7 @@ describe('ComponentInterpolator', function() {
'***': $1
}
}, [
, "$1"]);
- expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual(
+ expect(removeNoise(ReactDOM.findDOMNode(subject).innerHTML)).toEqual(
'
Ohai, Jane, click here right now please '
);
});
@@ -47,7 +48,7 @@ describe('ComponentInterpolator', function() {
user_id: 0,
count:
}, ["$1"]);
- expect(removeNoise(subject.getDOMNode().innerHTML)).toEqual(
+ expect(removeNoise(ReactDOM.findDOMNode(subject).innerHTML)).toEqual(
'Hi Jane (0), create new accounts'
);
});
diff --git a/browserify-transform.js b/browserify-transform.js
index 6878599..21e56bf 100644
--- a/browserify-transform.js
+++ b/browserify-transform.js
@@ -4,7 +4,7 @@ var config = I18nliner.config;
var preprocess = require("./preprocess");
var hasTranslatableText = require("./hasTranslatableText")(config);
-module.exports = function(file) {
+module.exports = function() {
return through(function (buf, enc, next) {
var source = buf.toString('utf8');
if (hasTranslatableText(source))
diff --git a/dist/.gitignore b/dist/.gitignore
deleted file mode 100644
index 99245c7..0000000
--- a/dist/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/react*
-/.module-cache
diff --git a/dist/ComponentInterpolator.js b/dist/ComponentInterpolator.js
index df59988..d658d2e 100644
--- a/dist/ComponentInterpolator.js
+++ b/dist/ComponentInterpolator.js
@@ -1,18 +1,23 @@
+'use strict';
+
var React = require('react');
var invariant = require('invariant');
-var $__0= React.PropTypes,string=$__0.string,object=$__0.object;
+var _React$PropTypes = React.PropTypes;
+var string = _React$PropTypes.string;
+var object = _React$PropTypes.object;
+
var WRAPPER_PATTERN = /(\*+)/;
var PLACEHOLDER_PATTERN = /(%\{.*?\})/;
-var toArray = function(children) {
+var toArray = function toArray(children) {
if (children instanceof Array) return children.slice();
if (!children) return [];
return [children];
};
// Replace a "$1" text descendant in this tree with the newDescendants
-var injectNewDescendants = function(element, newDescendants, props, ensureInjected) {
+var injectNewDescendants = function injectNewDescendants(element, newDescendants, props, ensureInjected) {
newDescendants.injectedCount = newDescendants.injectedCount || 0;
props = props || {};
@@ -28,15 +33,16 @@ var injectNewDescendants = function(element, newDescendants, props, ensureInject
newDescendants.injectedCount++;
}
- props.children = children;
+ props.children = children.length ? children : null;
if (ensureInjected) {
invariant(newDescendants.injectedCount === 1, 'wrappers must have a single "$1" text descendant');
}
return React.cloneElement(element, props);
};
-var getInjectIndex = function(children, containerName) {
- var child, index = -1;
+var getInjectIndex = function getInjectIndex(children, containerName) {
+ var child,
+ index = -1;
for (var i = 0; i < children.length; i++) {
child = children[i];
if (typeof child !== "string") continue;
@@ -47,13 +53,15 @@ var getInjectIndex = function(children, containerName) {
return index;
};
-var ComponentInterpolator = React.createClass({displayName: "ComponentInterpolator",
+var ComponentInterpolator = React.createClass({
+ displayName: 'ComponentInterpolator',
+
propTypes: {
string: string.isRequired,
wrappers: object
},
- inferChildren:function() {
+ inferChildren: function inferChildren() {
var tokens = (this.props.string || '').split(WRAPPER_PATTERN);
this.keyCounter = 0;
var inferredChildren = this.interpolateAllComponents(tokens);
@@ -65,8 +73,7 @@ var ComponentInterpolator = React.createClass({displayName: "ComponentInterpolat
currentChildren.splice.apply(currentChildren, [index, 1].concat(inferredChildren));
return currentChildren;
},
-
- interpolateAllComponents:function(tokens, eof) {
+ interpolateAllComponents: function interpolateAllComponents(tokens, eof) {
var token, child;
var children = [];
var wrappers = this.props.wrappers || {};
@@ -74,27 +81,17 @@ var ComponentInterpolator = React.createClass({displayName: "ComponentInterpolat
token = tokens.shift();
if (token === eof) break;
if (token.match(WRAPPER_PATTERN)) {
- invariant(
- child = wrappers[token],
- (" expected '" + token + "' wrapper, none found")
- );
-
- child = injectNewDescendants(
- child,
- this.interpolateAllComponents(tokens, token),
- { key: this.keyCounter++ },
- true
- );
+ invariant(child = wrappers[token], ' expected \'' + token + '\' wrapper, none found');
+
+ child = injectNewDescendants(child, this.interpolateAllComponents(tokens, token), { key: this.keyCounter++ }, true);
children.push(child);
- }
- else {
+ } else {
children.push.apply(children, this.interpolatePlaceholders(token));
}
}
return children;
},
-
- interpolatePlaceholders:function(string) {
+ interpolatePlaceholders: function interpolatePlaceholders(string) {
var token, child;
var tokens = string.split(PLACEHOLDER_PATTERN);
var children = [];
@@ -102,12 +99,9 @@ var ComponentInterpolator = React.createClass({displayName: "ComponentInterpolat
token = tokens.shift();
if (token.match(PLACEHOLDER_PATTERN)) {
token = token.slice(2, -1);
- invariant(
- this.props.hasOwnProperty(token),
- (" expected '" + token + "' placeholder value, none found")
- );
+ invariant(this.props.hasOwnProperty(token), ' expected \'' + token + '\' placeholder value, none found');
child = this.props[token];
- child = child && child.type ? React.cloneElement(child, {key: this.keyCounter++}) : child;
+ child = child && child.type ? React.cloneElement(child, { key: this.keyCounter++ }) : child;
children.push(child);
} else {
children.push(token);
@@ -115,11 +109,9 @@ var ComponentInterpolator = React.createClass({displayName: "ComponentInterpolat
}
return children;
},
-
- render:function() {
+ render: function render() {
return React.createElement('span', {}, this.inferChildren());
}
});
-module.exports = ComponentInterpolator;
-
+module.exports = ComponentInterpolator;
\ No newline at end of file
diff --git a/dist/extensions/i18n_js.js b/dist/extensions/i18n_js.js
index e229872..2dd92cd 100644
--- a/dist/extensions/i18n_js.js
+++ b/dist/extensions/i18n_js.js
@@ -1,7 +1,9 @@
+"use strict";
+
var ComponentInterpolator = require("../ComponentInterpolator");
-var extend = function(I18n) {
+var extend = function extend(I18n) {
I18n.ComponentInterpolator = ComponentInterpolator;
};
-module.exports = extend;
+module.exports = extend;
\ No newline at end of file
diff --git a/dist/invariant.js b/dist/invariant.js
deleted file mode 100644
index aed3a49..0000000
--- a/dist/invariant.js
+++ /dev/null
@@ -1 +0,0 @@
-throw new Error("nonexistent module required: invariant");
\ No newline at end of file
diff --git a/extensions/i18n_js_build.js b/extensions/i18n_js_build.js
index e4e58b9..569f9ee 100644
--- a/extensions/i18n_js_build.js
+++ b/extensions/i18n_js_build.js
@@ -1,2 +1,3 @@
+/* global I18n */
import extend from './i18n_js';
extend(I18n);
diff --git a/main.js b/main.js
index cdcddb2..904b861 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,3 @@
-var fs = require("fs");
var preprocess = require("./preprocess");
var recast = require("recast");
diff --git a/package.json b/package.json
index b19c860..703a82f 100644
--- a/package.json
+++ b/package.json
@@ -1,26 +1,32 @@
{
"name": "react-i18nliner",
- "version": "0.0.13",
+ "version": "0.1.0",
"description": "i18n made simple",
"main": "main.js",
"scripts": {
- "test": "node_modules/.bin/jsxhint *.js */*.js && node_modules/.bin/jest",
- "dist": "jsx --harmony --follow-requires . dist extensions/i18n_js"
+ "test": "node_modules/.bin/eslint . && node_modules/.bin/jest",
+ "dist": "babel -d dist ComponentInterpolator.js extensions/i18n_js.js"
},
"author": "Jon Jensen",
- "license": "ISC",
+ "license": "MIT",
"devDependencies": {
- "jest-cli": "^0.2.2",
- "jsxhint": "^0.10.0",
- "react": "0.13.x",
- "react-tools": "0.13.x"
+ "babel-cli": "^6.10.1",
+ "babel-jest": "^12.1.0",
+ "babel-plugin-transform-react-jsx": "^6.8.0",
+ "babel-polyfill": "^6.9.1",
+ "babel-preset-es2015": "^6.9.0",
+ "babel-preset-react": "^6.5.0",
+ "eslint": "^2.12.0",
+ "eslint-plugin-react": "^5.1.1",
+ "jest-cli": "^12.1.1",
+ "react": "^15.0.0",
+ "react-addons-test-utils": "^15.1.0",
+ "react-dom": "^15.1.0"
},
"peerDependencies": {
"react": "0.13.x || 0.14.x || ^15.0.0"
},
"jest": {
- "scriptPreprocessor": "test_utils/preprocessor.js",
- "setupTestFrameworkScriptFile": "test_utils/jasmine.js",
"unmockedModulePathPatterns": [
"node_modules",
"test_utils"
diff --git a/test_utils/preprocessor.js b/test_utils/preprocessor.js
deleted file mode 100644
index d380a11..0000000
--- a/test_utils/preprocessor.js
+++ /dev/null
@@ -1,6 +0,0 @@
-var ReactTools = require('react-tools');
-module.exports = {
- process: function(src) {
- return ReactTools.transform(src, {harmony: true});
- }
-};
diff --git a/test_utils/subjector.js b/test_utils/subjector.js
index 2308a87..b6f9875 100644
--- a/test_utils/subjector.js
+++ b/test_utils/subjector.js
@@ -1,8 +1,8 @@
module.exports = function(path) {
jest.dontMock(path);
- var React = require('react/addons');
- var { addons: { TestUtils } } = React;
+ var React = require('react');
+ var TestUtils = require('react-addons-test-utils');
var Component = require(path);
return function(props, children) {