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