signavio-i18n
Advanced tools
Comparing version 1.3.5 to 1.4.0
@@ -0,1 +1,2 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _find from 'lodash/find'; | ||
@@ -50,5 +51,4 @@ import _last from 'lodash/last'; | ||
function getTranslatorComment(node) { | ||
var comments = []; | ||
(node.leadingComments || []).forEach(function (commentNode) { | ||
function getExtractedComment(node) { | ||
var comments = [];(node.leadingComments || []).forEach(function (commentNode) { | ||
var match = commentNode.value.match(/^\s*translators:\s*(.*?)\s*$/im); | ||
@@ -81,15 +81,16 @@ if (match) { | ||
return { visitor: { | ||
return { | ||
visitor: { | ||
VariableDeclaration: function VariableDeclaration(_ref) { | ||
var node = _ref.node; | ||
var translatorComment = getTranslatorComment(node); | ||
if (!translatorComment) { | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
return; | ||
} | ||
node.declarations.forEach(function (declarator) { | ||
var comment = getTranslatorComment(declarator); | ||
var comment = getExtractedComment(declarator); | ||
if (!comment) { | ||
var key = declarator.init.start + '|' + declarator.init.end; | ||
relocatedComments[key] = translatorComment; | ||
relocatedComments[key] = extractedComment; | ||
} | ||
@@ -171,12 +172,15 @@ }); | ||
var translatorComment = getTranslatorComment(node); | ||
if (!translatorComment) { | ||
translatorComment = getTranslatorComment(parent); | ||
if (!translatorComment) { | ||
translatorComment = relocatedComments[node.start + '|' + node.end]; | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
extractedComment = getExtractedComment(parent); | ||
if (!extractedComment) { | ||
extractedComment = relocatedComments[node.start + '|' + node.end]; | ||
} | ||
} | ||
if (translatorComment) { | ||
translate.comments.translator = translatorComment; | ||
if (extractedComment && translate.comments) { | ||
translate.comments = _extends({}, translate.comments, { | ||
extracted: extractedComment | ||
}); | ||
} | ||
@@ -210,3 +214,4 @@ | ||
} | ||
} }; | ||
} | ||
}; | ||
} |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _find2 = require('lodash/find'); | ||
@@ -71,5 +75,4 @@ | ||
function getTranslatorComment(node) { | ||
var comments = []; | ||
(node.leadingComments || []).forEach(function (commentNode) { | ||
function getExtractedComment(node) { | ||
var comments = [];(node.leadingComments || []).forEach(function (commentNode) { | ||
var match = commentNode.value.match(/^\s*translators:\s*(.*?)\s*$/im); | ||
@@ -102,15 +105,16 @@ if (match) { | ||
return { visitor: { | ||
return { | ||
visitor: { | ||
VariableDeclaration: function VariableDeclaration(_ref) { | ||
var node = _ref.node; | ||
var translatorComment = getTranslatorComment(node); | ||
if (!translatorComment) { | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
return; | ||
} | ||
node.declarations.forEach(function (declarator) { | ||
var comment = getTranslatorComment(declarator); | ||
var comment = getExtractedComment(declarator); | ||
if (!comment) { | ||
var key = declarator.init.start + '|' + declarator.init.end; | ||
relocatedComments[key] = translatorComment; | ||
relocatedComments[key] = extractedComment; | ||
} | ||
@@ -192,12 +196,15 @@ }); | ||
var translatorComment = getTranslatorComment(node); | ||
if (!translatorComment) { | ||
translatorComment = getTranslatorComment(parent); | ||
if (!translatorComment) { | ||
translatorComment = relocatedComments[node.start + '|' + node.end]; | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
extractedComment = getExtractedComment(parent); | ||
if (!extractedComment) { | ||
extractedComment = relocatedComments[node.start + '|' + node.end]; | ||
} | ||
} | ||
if (translatorComment) { | ||
translate.comments.translator = translatorComment; | ||
if (extractedComment && translate.comments) { | ||
translate.comments = (0, _extends3.default)({}, translate.comments, { | ||
extracted: extractedComment | ||
}); | ||
} | ||
@@ -231,3 +238,4 @@ | ||
} | ||
} }; | ||
} | ||
}; | ||
} |
{ | ||
"name": "signavio-i18n", | ||
"version": "1.3.5", | ||
"version": "1.4.0", | ||
"description": "Minimalist gettext style i18n for JavaScript", | ||
@@ -16,9 +16,7 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"pretranspile": "yarn run clean", | ||
"transpile": "yarn transpile:es5 && yarn transpile:es6", | ||
"transpile:es5": "yarn transpile:js:es5", | ||
"transpile:js:es5": "cross-env NODE_ENV=production BABEL_ENV=es5 babel src --out-dir lib --copy-files", | ||
"transpile:es6": "yarn transpile:js:es6", | ||
"transpile:js:es6": "cross-env NODE_ENV=production BABEL_ENV=es6 babel src --out-dir lib-es6 --copy-files", | ||
"clean": "rimraf -rf lib lib-es6", | ||
"prebuild": "yarn run clean", | ||
"build": "yarn build:es5 && yarn build:es6", | ||
"build:es5": "cross-env NODE_ENV=production BABEL_ENV=es5 babel src --out-dir lib", | ||
"build:es6": "cross-env NODE_ENV=production BABEL_ENV=es6 babel src --out-dir lib-es6", | ||
"clean": "rimraf lib lib-es6", | ||
"coverage": "cross-env NODE_ENV=coverage nyc --reporter=lcov --reporter=text yarn test", | ||
@@ -28,5 +26,6 @@ "dryrun": "node ./bin/i18n-extract.js test/fixtures/**/*.js", | ||
"test": "cross-env NODE_ENV=es5 mocha-webpack", | ||
"pretest": "yarn run transpile", | ||
"prepublish": "yarn run transpile", | ||
"predryrun": "yarn run transpile" | ||
"pretest": "yarn build", | ||
"prepublishOnly": "yarn build", | ||
"predryrun": "yarn build", | ||
"flow": "flow check" | ||
}, | ||
@@ -54,2 +53,3 @@ "author": "Jan-Felix Schwarz", | ||
"devDependencies": { | ||
"ajv": "^6.1.1", | ||
"babel-cli": "^6.2.0", | ||
@@ -72,2 +72,3 @@ "babel-loader": "^6.3.2", | ||
"chai-files": "^1.4.0", | ||
"cheerio": "^1.0.0-rc.2", | ||
"cross-env": "^4.0.0", | ||
@@ -81,2 +82,3 @@ "enzyme": "^3.2.0", | ||
"eslint-plugin-mocha": "^4.7.0", | ||
"flow-bin": "^0.65.0", | ||
"istanbul-instrumenter-loader": "^2.0.0", | ||
@@ -83,0 +85,0 @@ "jsdom": "^9.12.0", |
@@ -1,14 +0,15 @@ | ||
[![Build Status](https://workflow-ci.signavio.com:8888/buildStatus/icon?job=I18N-PR)](https://workflow-ci.signavio.com:8888/job/I18N-PR/) | ||
[![CircleCI](https://circleci.com/gh/signavio/i18n/tree/master.svg?style=svg)](https://circleci.com/gh/signavio/i18n/tree/master) | ||
[![version][version-badge]][package] | ||
# signavio-i18n | ||
Minimalist gettext style i18n for JavaScript | ||
## Features | ||
- [Supports React components as interpolations](#interpolations) | ||
- [Pluralization support](#pluralization) (ngettext style) | ||
- [markdown support](#markdown) | ||
- Compatible with [webpack po-loader](https://github.com/perchlayer/po-loader) | ||
- Comes with scripts for extracting translation strings from JavaScript (Babel) sources and updating .pot and .po files | ||
* [Supports React components as interpolations](#interpolations) | ||
* [Pluralization support](#pluralization) (ngettext style) | ||
* [markdown support](#markdown) | ||
* Compatible with [webpack po-loader](https://github.com/perchlayer/po-loader) | ||
* Comes with scripts for extracting translation strings from JavaScript (Babel) sources and updating .pot and .po files | ||
@@ -21,3 +22,2 @@ ## Installation | ||
## Setup | ||
@@ -30,4 +30,6 @@ | ||
"scripts": { | ||
"i18n-init": "cd src/locales && msginit --no-translator --input messages.pot --locale", | ||
"i18n": "i18n-extract \"src/**/*.js\" src/locales/messages.pot && i18n-merge src/locales/messages.pot src/locales/*.po" | ||
"i18n-init": | ||
"cd src/locales && msginit --no-translator --input messages.pot --locale", | ||
"i18n": | ||
"i18n-extract \"src/**/*.js\" src/locales/messages.pot && i18n-merge src/locales/messages.pot src/locales/*.po" | ||
} | ||
@@ -64,3 +66,2 @@ } | ||
## Usage | ||
@@ -71,3 +72,3 @@ | ||
```javascript | ||
import i18n, { init, setLocale } from 'signavio-i18n'; | ||
import i18n, { init, setLocale } from 'signavio-i18n' | ||
@@ -77,3 +78,3 @@ function getLangLoader(locale) { | ||
return require(`bundle?lazy!json!po!./locales/${locale}.po`) | ||
}; | ||
} | ||
@@ -120,3 +121,3 @@ const config = { | ||
i18n('Contact __supportLink__', { | ||
supportLink: <a href='mailto:support@signavio.com'>Support</a>, | ||
supportLink: <a href="mailto:support@signavio.com">Support</a>, | ||
}) | ||
@@ -123,0 +124,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
376772
65
0
2954
158
44