signavio-i18n
Advanced tools
Comparing version 1.4.0 to 2.0.0
@@ -863,2 +863,21 @@ /******/ (function(modules) { // webpackBootstrap | ||
}); | ||
describe('message context', function () { | ||
var contextLocation = fixtureDir + '/messageContext'; | ||
afterEach(function () { | ||
removeIfExists(contextLocation + '/messages.pot'); | ||
}); | ||
it('should add the message context to the .pot file', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(contextLocation + '/messages.pot')).to.not.exist; | ||
callForDir(contextLocation); | ||
var messages = (0, _chaiFiles.file)(contextLocation + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('msgctxt "This is context for my message"'); | ||
}); | ||
}); | ||
}); | ||
@@ -865,0 +884,0 @@ |
exports.ids = [0]; | ||
exports.modules = { | ||
/***/ 31: | ||
/***/ 29: | ||
/***/ (function(module, exports) { | ||
@@ -6,0 +6,0 @@ |
exports.ids = [1]; | ||
exports.modules = { | ||
/***/ 30: | ||
/***/ 28: | ||
/***/ (function(module, exports) { | ||
@@ -6,0 +6,0 @@ |
@@ -167,3 +167,3 @@ /******/ (function(modules) { // webpackBootstrap | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
value: true | ||
}); | ||
@@ -177,3 +177,3 @@ exports.init = init; | ||
var _isFunction = __webpack_require__(22); | ||
var _isFunction = __webpack_require__(20); | ||
@@ -329,7 +329,7 @@ var _isFunction2 = _interopRequireDefault(_isFunction); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
value: true | ||
}); | ||
exports.default = getConfig; | ||
var _path = __webpack_require__(28); | ||
var _path = __webpack_require__(26); | ||
@@ -411,22 +411,18 @@ var _path2 = _interopRequireDefault(_path); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
value: true | ||
}); | ||
var _slicedToArray2 = __webpack_require__(17); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _extends2 = __webpack_require__(16); | ||
var _isString = __webpack_require__(23); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _isString = __webpack_require__(25); | ||
var _isString2 = _interopRequireDefault(_isString); | ||
var _isNumber = __webpack_require__(23); | ||
var _isNumber = __webpack_require__(21); | ||
var _isNumber2 = _interopRequireDefault(_isNumber); | ||
var _isPlainObject = __webpack_require__(24); | ||
var _isPlainObject = __webpack_require__(22); | ||
@@ -439,15 +435,15 @@ var _isPlainObject2 = _interopRequireDefault(_isPlainObject); | ||
var _pickBy = __webpack_require__(26); | ||
var _pickBy = __webpack_require__(24); | ||
var _pickBy2 = _interopRequireDefault(_pickBy); | ||
var _has = __webpack_require__(21); | ||
var _has = __webpack_require__(19); | ||
var _has2 = _interopRequireDefault(_has); | ||
var _escape = __webpack_require__(20); | ||
var _escape = __webpack_require__(18); | ||
var _escape2 = _interopRequireDefault(_escape); | ||
var _marked = __webpack_require__(27); | ||
var _marked = __webpack_require__(25); | ||
@@ -465,3 +461,3 @@ var _marked2 = _interopRequireDefault(_marked); | ||
var defaultOptions = { | ||
markdown: !1 | ||
markdown: false | ||
}; | ||
@@ -481,3 +477,3 @@ | ||
finalOptions = (0, _extends3.default)({}, defaultOptions, finalOptions, { | ||
finalOptions = _extends({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? finalOptions.context + '\x04' : '' | ||
@@ -487,3 +483,3 @@ }); | ||
var _slice = (singleton.messages[finalOptions.context + text] || [null, null, null]).slice(1), | ||
_slice2 = (0, _slicedToArray3.default)(_slice, 2), | ||
_slice2 = _slicedToArray(_slice, 2), | ||
translatedSingular = _slice2[0], | ||
@@ -612,3 +608,3 @@ translatedPlural = _slice2[1]; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
value: true | ||
}); | ||
@@ -634,3 +630,3 @@ exports.default = { | ||
var _server = __webpack_require__(29); | ||
var _server = __webpack_require__(27); | ||
@@ -700,3 +696,3 @@ var _server2 = _interopRequireDefault(_server); | ||
it('should support using Markdown in translation messages', function () { | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: 'success', markdown: !0 }); | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: 'success', markdown: true }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
@@ -708,3 +704,3 @@ var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
it('should correctly escape interpolations when used with Markdown', function () { | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: '<success>', markdown: !0 }); | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: '<success>', markdown: true }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
@@ -716,3 +712,3 @@ var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
it('should not replace "__markdown__" placeholders', function () { | ||
var t = (0, _src2.default)('This is __markdown__.', { markdown: !0 }); | ||
var t = (0, _src2.default)('This is __markdown__.', { markdown: true }); | ||
var renderedHtml = _server2.default.renderToStaticMarkup(_react2.default.createElement( | ||
@@ -727,3 +723,3 @@ 'div', | ||
it.skip('should not be possible to break Markdown from interpolations', function () { | ||
var t = (0, _src2.default)('**__foo__**', { foo: 'bar** baz **baa', markdown: !0 }); | ||
var t = (0, _src2.default)('**__foo__**', { foo: 'bar** baz **baa', markdown: true }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
@@ -885,3 +881,3 @@ var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
var _child_process = __webpack_require__(19); | ||
var _child_process = __webpack_require__(17); | ||
@@ -892,3 +888,3 @@ var _child_process2 = _interopRequireDefault(_child_process); | ||
var _chaiFiles = __webpack_require__(18); | ||
var _chaiFiles = __webpack_require__(16); | ||
@@ -1081,3 +1077,3 @@ var _chai = __webpack_require__(0); | ||
__webpack_require__.e/* require.ensure */(1).then((function(require) { | ||
data = __webpack_require__(30); | ||
data = __webpack_require__(28); | ||
var callbacks = cbs; | ||
@@ -1101,3 +1097,3 @@ cbs = null; | ||
__webpack_require__.e/* require.ensure */(0).then((function(require) { | ||
data = __webpack_require__(31); | ||
data = __webpack_require__(29); | ||
var callbacks = cbs; | ||
@@ -1138,3 +1134,3 @@ cbs = null; | ||
module.exports = require("babel-runtime/helpers/extends"); | ||
module.exports = require("chai-files"); | ||
@@ -1145,3 +1141,3 @@ /***/ }), | ||
module.exports = require("babel-runtime/helpers/slicedToArray"); | ||
module.exports = require("child_process"); | ||
@@ -1152,3 +1148,3 @@ /***/ }), | ||
module.exports = require("chai-files"); | ||
module.exports = require("lodash/escape"); | ||
@@ -1159,3 +1155,3 @@ /***/ }), | ||
module.exports = require("child_process"); | ||
module.exports = require("lodash/has"); | ||
@@ -1166,3 +1162,3 @@ /***/ }), | ||
module.exports = require("lodash/escape"); | ||
module.exports = require("lodash/isFunction"); | ||
@@ -1173,3 +1169,3 @@ /***/ }), | ||
module.exports = require("lodash/has"); | ||
module.exports = require("lodash/isNumber"); | ||
@@ -1180,3 +1176,3 @@ /***/ }), | ||
module.exports = require("lodash/isFunction"); | ||
module.exports = require("lodash/isPlainObject"); | ||
@@ -1187,3 +1183,3 @@ /***/ }), | ||
module.exports = require("lodash/isNumber"); | ||
module.exports = require("lodash/isString"); | ||
@@ -1194,3 +1190,3 @@ /***/ }), | ||
module.exports = require("lodash/isPlainObject"); | ||
module.exports = require("lodash/pickBy"); | ||
@@ -1201,3 +1197,3 @@ /***/ }), | ||
module.exports = require("lodash/isString"); | ||
module.exports = require("marked"); | ||
@@ -1208,3 +1204,3 @@ /***/ }), | ||
module.exports = require("lodash/pickBy"); | ||
module.exports = require("path"); | ||
@@ -1215,14 +1211,2 @@ /***/ }), | ||
module.exports = require("marked"); | ||
/***/ }), | ||
/* 28 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("path"); | ||
/***/ }), | ||
/* 29 */ | ||
/***/ (function(module, exports) { | ||
module.exports = require("react-dom/server"); | ||
@@ -1229,0 +1213,0 @@ |
import isFunction from 'lodash/isFunction'; | ||
import forEach from 'lodash/forEach'; | ||
import createTranslate from './translate'; | ||
var config = {}; | ||
var specifiedLocale = void 0; | ||
var getLangLoader = void 0; | ||
var specifiedLocale; | ||
var getLangLoader; | ||
var changeLocaleListeners = []; | ||
var singleton = { | ||
messages: {} | ||
/** | ||
* The translate function | ||
* @param text String - The base/singular form of the text to translate | ||
* @param pluralText String (optional) - The plural form of the text to translate | ||
* @param options Object (optional) - A mixed object of interpolations and options | ||
**/ | ||
}; | ||
/** | ||
* The translate function | ||
* @param text String - The base/singular form of the text to translate | ||
* @param pluralText String (optional) - The plural form of the text to translate | ||
* @param options Object (optional) - A mixed object of interpolations and options | ||
**/ | ||
var translate = createTranslate(singleton); | ||
export default translate; | ||
/** | ||
@@ -33,5 +29,5 @@ * Returns a promise that resolves as soon as the messages bundle has been loaded. Loads an | ||
**/ | ||
export function init(getLangLoaderFn) { | ||
var configObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
getLangLoader = getLangLoaderFn; | ||
@@ -41,3 +37,2 @@ config = configObj; | ||
} | ||
/** | ||
@@ -49,2 +44,3 @@ * Sets the locale to use. If init has been called before, returns a promise that resolves as soon | ||
*/ | ||
export function setLocale(newLocale) { | ||
@@ -59,15 +55,14 @@ specifiedLocale = newLocale; | ||
} | ||
/** | ||
* Returns the currently active locale | ||
**/ | ||
export function locale() { | ||
var langRaw = specifiedLocale || window && (window.navigator.userLanguage || window.navigator.language) || 'en_US'; | ||
var langParts = langRaw.replace('-', '_').split('_'); | ||
var language = langParts[0]; | ||
var country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''; | ||
var currentLocale = '' + language + country; | ||
var country = langParts.length > 1 ? "_".concat(langParts[1].toUpperCase()) : ''; | ||
var currentLocale = "".concat(language).concat(country); | ||
currentLocale = mapLocale(currentLocale); | ||
currentLocale = mapLocale(currentLocale); | ||
if (tryToGetLangLoader(currentLocale)) { | ||
@@ -78,2 +73,3 @@ return currentLocale; | ||
currentLocale = mapLocale(language); // fall back to the general language | ||
if (tryToGetLangLoader(currentLocale)) { | ||
@@ -85,14 +81,12 @@ return currentLocale; | ||
} | ||
export function onChangeLocale(listener) { | ||
changeLocaleListeners.push(listener); | ||
} | ||
export function offChangeLocale(listener) { | ||
changeLocaleListeners.splice(changeLocaleListeners.indexOf(listener), 1); | ||
} | ||
/** | ||
* Reset all state as if init and setLocale have never been called. Useful for testing. | ||
**/ | ||
export function reset() { | ||
@@ -102,3 +96,2 @@ config = undefined; | ||
getLangLoader = undefined; | ||
singleton.messages = {}; | ||
@@ -117,3 +110,4 @@ changeLocaleListeners = []; | ||
function tryToGetLangLoader(forLocale) { | ||
var waitForLangChunk = void 0; | ||
var waitForLangChunk; | ||
try { | ||
@@ -124,2 +118,3 @@ waitForLangChunk = getLangLoader(forLocale); | ||
} | ||
return waitForLangChunk; | ||
@@ -126,0 +121,0 @@ } |
@@ -1,16 +0,11 @@ | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _find from 'lodash/find'; | ||
import _last from 'lodash/last'; | ||
import _objectSpread from "@babel/runtime/helpers/objectSpread"; | ||
import _find from "lodash/find"; | ||
import _last from "lodash/last"; | ||
import gettextParser from 'gettext-parser'; | ||
import fs from 'fs'; | ||
var DEFAULT_FUNCTION_NAME = 'i18n'; | ||
var DEFAULT_FILE_NAME = 'messages.pot'; | ||
var DEFAULT_HEADERS = { | ||
'content-type': 'text/plain; charset=UTF-8' | ||
}; | ||
var DEFAULT_ADD_LOCATION = 'full'; | ||
@@ -35,3 +30,2 @@ | ||
var right = node.right; | ||
return node.type === 'BinaryExpression' && node.operator === '+' && (isStringLiteral(left) || isStringConcatExpr(left)) && (isStringLiteral(right) || isStringConcatExpr(right)); | ||
@@ -53,4 +47,6 @@ } | ||
function getExtractedComment(node) { | ||
var comments = [];(node.leadingComments || []).forEach(function (commentNode) { | ||
var comments = []; | ||
(node.leadingComments || []).forEach(function (commentNode) { | ||
var match = commentNode.value.match(/^\s*translators:\s*(.*?)\s*$/im); | ||
if (match) { | ||
@@ -65,3 +61,3 @@ comments.push(match[1]); | ||
if (!addLocation || addLocation === 'full') { | ||
return fn + ':' + node.loc.start.line; | ||
return "".concat(fn, ":").concat(node.loc.start.line); | ||
} | ||
@@ -71,4 +67,3 @@ | ||
var index = fn.lastIndexOf('/'); | ||
return fn.slice(index + 1) + ':' + node.loc.start.line; | ||
return "".concat(fn.slice(index + 1), ":").concat(node.loc.start.line); | ||
} | ||
@@ -80,6 +75,5 @@ | ||
export default function plugin() { | ||
var currentFileName = void 0; | ||
var data = void 0; | ||
var currentFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
return { | ||
@@ -89,11 +83,13 @@ visitor: { | ||
var node = _ref.node; | ||
var extractedComment = getExtractedComment(node); | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
return; | ||
} | ||
node.declarations.forEach(function (declarator) { | ||
var comment = getExtractedComment(declarator); | ||
if (!comment) { | ||
var key = declarator.init.start + '|' + declarator.init.end; | ||
var key = "".concat(declarator.init.start, "|").concat(declarator.init.end); | ||
relocatedComments[key] = extractedComment; | ||
@@ -108,16 +104,15 @@ } | ||
_config$opts$function = _config$opts.functionName, | ||
functionName = _config$opts$function === undefined ? DEFAULT_FUNCTION_NAME : _config$opts$function, | ||
functionName = _config$opts$function === void 0 ? DEFAULT_FUNCTION_NAME : _config$opts$function, | ||
_config$opts$fileName = _config$opts.fileName, | ||
fileName = _config$opts$fileName === undefined ? DEFAULT_FILE_NAME : _config$opts$fileName, | ||
fileName = _config$opts$fileName === void 0 ? DEFAULT_FILE_NAME : _config$opts$fileName, | ||
_config$opts$headers = _config$opts.headers, | ||
headers = _config$opts$headers === undefined ? DEFAULT_HEADERS : _config$opts$headers, | ||
headers = _config$opts$headers === void 0 ? DEFAULT_HEADERS : _config$opts$headers, | ||
_config$opts$addLocat = _config$opts.addLocation, | ||
addLocation = _config$opts$addLocat === undefined ? DEFAULT_ADD_LOCATION : _config$opts$addLocat, | ||
addLocation = _config$opts$addLocat === void 0 ? DEFAULT_ADD_LOCATION : _config$opts$addLocat, | ||
_config$opts$noLocati = _config$opts.noLocation, | ||
noLocation = _config$opts$noLocati === undefined ? !1 : _config$opts$noLocati; | ||
noLocation = _config$opts$noLocati === void 0 ? !1 : _config$opts$noLocati; | ||
var base = config.opts.baseDirectory; | ||
var base = config.opts.baseDirectory; | ||
if (base) { | ||
base = base.match(/^(.*?)\/*$/)[1] + '/'; | ||
base = "".concat(base.match(/^(.*?)\/*$/)[1], "/"); | ||
} | ||
@@ -130,5 +125,6 @@ | ||
headers: headers, | ||
translations: { context: {} } | ||
translations: { | ||
context: {} | ||
} | ||
}; | ||
headers['content-type'] = headers['content-type'] || DEFAULT_HEADERS['content-type']; | ||
@@ -144,4 +140,4 @@ } | ||
var translate = {}; | ||
var args = node.arguments; | ||
var args = node.arguments; | ||
if (args.length === 0) { | ||
@@ -162,2 +158,3 @@ return; | ||
value = getStringValue(args[1]); | ||
if (value) { | ||
@@ -169,3 +166,4 @@ translate.msgid_plural = value; | ||
var fn = config.file.log.filename; | ||
var fn = config.file.opts.filename; | ||
if (base && fn && fn.substr(0, base.length) === base) { | ||
@@ -182,6 +180,8 @@ fn = fn.substr(base.length); | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
extractedComment = getExtractedComment(parent); | ||
if (!extractedComment) { | ||
extractedComment = relocatedComments[node.start + '|' + node.end]; | ||
extractedComment = relocatedComments["".concat(node.start, "|").concat(node.end)]; | ||
} | ||
@@ -191,4 +191,3 @@ } | ||
if (extractedComment && translate.comments) { | ||
translate.comments = _extends({}, translate.comments, { | ||
translate.comments = _objectSpread({}, translate.comments, { | ||
extracted: extractedComment | ||
@@ -214,2 +213,3 @@ }); | ||
var msgctxt = translate.msgctxt; | ||
if (msgctxt) { | ||
@@ -221,3 +221,2 @@ data.translations[msgctxt] = data.translations[msgctxt] || {}; | ||
context[translate.msgid] = translate; | ||
var output = gettextParser.po.compile(data); | ||
@@ -224,0 +223,0 @@ fs.writeFileSync(fileName, output); |
import path from 'path'; | ||
import fs from 'fs'; | ||
var I18NRC_FILENAME = '.i18nrc'; | ||
var existsCache = {}; | ||
@@ -41,3 +39,2 @@ var configCache = {}; | ||
var filename = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.'; | ||
var loc = findConfig(filename); | ||
@@ -54,6 +51,7 @@ | ||
var content = fs.readFileSync(loc, 'utf8'); | ||
try { | ||
configCache[loc] = JSON.parse(content); | ||
} catch (err) { | ||
err.message = loc + ': Error while parsing JSON - ' + err.message; | ||
err.message = "".concat(loc, ": Error while parsing JSON - ").concat(err.message); | ||
throw err; | ||
@@ -60,0 +58,0 @@ } |
@@ -1,19 +0,16 @@ | ||
import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray'; | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties'; | ||
import _each from 'lodash/each'; | ||
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
import _objectSpread from "@babel/runtime/helpers/objectSpread"; | ||
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; | ||
import _each from "lodash/each"; | ||
import glob from 'glob'; | ||
import ProgressBar from 'progress'; | ||
import { transformFileSync } from 'babel-core'; | ||
import { transformFileSync } from '@babel/core'; | ||
import babelGettextExtractor from './babel-gettext-extractor'; | ||
import getConfig from './config'; | ||
if (process.argv.length < 3) { | ||
throw new Error('Invalid arguments, expected: \'node i18n/scripts/extract.js "source_file_pattern"\', got: ' + process.argv.join(' ')); | ||
throw new Error("Invalid arguments, expected: 'node i18n/scripts/extract.js \"source_file_pattern\"', got: ".concat(process.argv.join(' '))); | ||
} | ||
var files = glob.sync(process.argv[2]); | ||
var progressBar = new ProgressBar(' extracting [:bar] :percent :fileName', { | ||
@@ -26,16 +23,16 @@ total: files.length, | ||
// eslint-disable-next-line no-console | ||
progressBar.tick(1, { fileName: fileName }); | ||
progressBar.tick(1, { | ||
fileName: fileName | ||
}); | ||
var _getConfig = getConfig(fileName), | ||
_getConfig$babel = _getConfig.babel, | ||
babel = _getConfig$babel === undefined ? {} : _getConfig$babel, | ||
config = _objectWithoutProperties(_getConfig, ['babel']); | ||
babel = _getConfig$babel === void 0 ? {} : _getConfig$babel, | ||
config = _objectWithoutProperties(_getConfig, ["babel"]); | ||
var _babel$plugins = babel.plugins, | ||
plugins = _babel$plugins === undefined ? [] : _babel$plugins; | ||
transformFileSync(fileName, _extends({}, babel, { | ||
plugins: [].concat(_toConsumableArray(plugins), [[babelGettextExtractor, config]]) | ||
plugins = _babel$plugins === void 0 ? [] : _babel$plugins; | ||
transformFileSync(fileName, _objectSpread({}, babel, { | ||
plugins: _toConsumableArray(plugins).concat([[babelGettextExtractor, config]]) | ||
})); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import _each from 'lodash/each'; | ||
import _each from "lodash/each"; | ||
import path from 'path'; | ||
@@ -12,7 +12,6 @@ import { exec } from 'child_process'; | ||
_each(process.argv.slice(3), function (fileName) { | ||
exec('msgmerge -o ' + fileName + ' ' + fileName + ' ' + templatePath, function (error, stdout, stderr) { | ||
exec("msgmerge -o ".concat(fileName, " ").concat(fileName, " ").concat(templatePath), function (error, stdout, stderr) { | ||
// eslint-disable-next-line no-console | ||
if (error) {} | ||
// eslint-disable-next-line no-console | ||
}); | ||
}); |
@@ -1,3 +0,3 @@ | ||
import _slicedToArray from 'babel-runtime/helpers/slicedToArray'; | ||
import _extends from 'babel-runtime/helpers/extends'; | ||
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; | ||
import _objectSpread from "@babel/runtime/helpers/objectSpread"; | ||
import isString from 'lodash/isString'; | ||
@@ -12,9 +12,6 @@ import isNumber from 'lodash/isNumber'; | ||
import React from 'react'; | ||
var placeholderRegex = /__(\w+)__/g; | ||
var defaultOptions = { | ||
markdown: !1 | ||
}; | ||
export default (function (singleton) { | ||
@@ -32,4 +29,4 @@ return function translate(text, plural, options) { | ||
finalOptions = _extends({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? finalOptions.context + '\x04' : '' | ||
finalOptions = _objectSpread({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? "".concat(finalOptions.context, "\x04") : '' | ||
}); | ||
@@ -40,9 +37,7 @@ | ||
translatedSingular = _slice2[0], | ||
translatedPlural = _slice2[1]; | ||
translatedPlural = _slice2[1]; // find the raw translation message | ||
// find the raw translation message | ||
var translation; | ||
var translation = void 0; | ||
if (finalPlural && needsPlural(finalOptions)) { | ||
@@ -52,15 +47,13 @@ translation = translatedPlural && isString(translatedPlural) ? translatedPlural : finalPlural; | ||
translation = translatedSingular && isString(translatedSingular) ? translatedSingular : text; | ||
} | ||
} // apply markdown processing if necessary | ||
// apply markdown processing if necessary | ||
if (finalOptions.markdown) { | ||
translation = applyMarkdown(translation); | ||
} | ||
} // insert regular interpolations | ||
// insert regular interpolations | ||
translation = insertInterpolations(translation, finalOptions); | ||
// insert React component interpolations | ||
translation = insertInterpolations(translation, finalOptions); // insert React component interpolations | ||
var result = insertReactComponentInterpolations(translation, finalOptions); | ||
return result.length === 1 ? result[0] : result; | ||
@@ -82,5 +75,4 @@ }; | ||
// exclude them from the markdown notation. Use asterisk (*) instead.) | ||
var finalTranslation = marked(translation.replace(/_/g, '\\_')); | ||
var finalTranslation = marked(translation.replace(/_/g, '\\_')); // remove single, outer wrapping <p>-tag | ||
// remove single, outer wrapping <p>-tag | ||
if (isWrappedInPTag(finalTranslation)) { | ||
@@ -96,3 +88,7 @@ // last occurrence of <p> is at the start, first occurence of </p> is a the very end | ||
// eslint-disable-next-line react/no-danger | ||
return React.createElement('span', { dangerouslySetInnerHTML: { __html: html } }); | ||
return React.createElement("span", { | ||
dangerouslySetInnerHTML: { | ||
__html: html | ||
} | ||
}); | ||
} | ||
@@ -104,10 +100,7 @@ | ||
}); | ||
var finalTranslation = translation; | ||
forEach(regularInterpolations, function (val, key) { | ||
finalTranslation = finalTranslation.replace(new RegExp('__' + key + '__', 'g'), options.markdown ? escape(val) : val // only escape options when using markdown | ||
finalTranslation = finalTranslation.replace(new RegExp("__".concat(key, "__"), 'g'), options.markdown ? escape(val) : val // only escape options when using markdown | ||
); | ||
}); | ||
return finalTranslation; | ||
@@ -118,4 +111,4 @@ } | ||
var result = []; | ||
var match = void 0; | ||
var substr = void 0; | ||
var match; | ||
var substr; | ||
var start = 0; | ||
@@ -138,14 +131,16 @@ | ||
} | ||
start = placeholderRegex.lastIndex; | ||
} | ||
} // append part after last match | ||
// append part after last match | ||
if (start < translation.length) { | ||
substr = translation.substring(start); | ||
result.push(options.markdown ? htmlStringToReactComponent(substr) : substr); | ||
} | ||
} // re-concatenate all string elements | ||
// re-concatenate all string elements | ||
return result.reduce(function (acc, element) { | ||
var lastAccumulatedElement = acc[acc.length - 1]; | ||
if (isString(element) && isString(lastAccumulatedElement)) { | ||
@@ -157,4 +152,5 @@ // eslint-disable-next-line no-param-reassign | ||
} | ||
return acc; | ||
}, []); | ||
} |
@@ -1,3 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -12,36 +14,27 @@ value: !0 | ||
exports.reset = reset; | ||
exports.default = void 0; | ||
var _isFunction = require('lodash/isFunction'); | ||
var _isFunction = _interopRequireDefault(require("lodash/isFunction")); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
var _forEach = _interopRequireDefault(require("lodash/forEach")); | ||
var _forEach = require('lodash/forEach'); | ||
var _translate = _interopRequireDefault(require("./translate")); | ||
var _forEach2 = _interopRequireDefault(_forEach); | ||
var _translate = require('./translate'); | ||
var _translate2 = _interopRequireDefault(_translate); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var config = {}; | ||
var specifiedLocale = void 0; | ||
var getLangLoader = void 0; | ||
var specifiedLocale; | ||
var getLangLoader; | ||
var changeLocaleListeners = []; | ||
var singleton = { | ||
messages: {} | ||
/** | ||
* The translate function | ||
* @param text String - The base/singular form of the text to translate | ||
* @param pluralText String (optional) - The plural form of the text to translate | ||
* @param options Object (optional) - A mixed object of interpolations and options | ||
**/ | ||
}; | ||
var translate = (0, _translate.default)(singleton); | ||
var _default = translate; | ||
/** | ||
* The translate function | ||
* @param text String - The base/singular form of the text to translate | ||
* @param pluralText String (optional) - The plural form of the text to translate | ||
* @param options Object (optional) - A mixed object of interpolations and options | ||
**/ | ||
var translate = (0, _translate2.default)(singleton); | ||
exports.default = translate; | ||
/** | ||
* Returns a promise that resolves as soon as the messages bundle has been loaded. Loads an | ||
@@ -56,5 +49,6 @@ * an automatically detected locale if setLocale has not been called before. | ||
exports.default = _default; | ||
function init(getLangLoaderFn) { | ||
var configObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
getLangLoader = getLangLoaderFn; | ||
@@ -64,3 +58,2 @@ config = configObj; | ||
} | ||
/** | ||
@@ -72,2 +65,4 @@ * Sets the locale to use. If init has been called before, returns a promise that resolves as soon | ||
*/ | ||
function setLocale(newLocale) { | ||
@@ -82,15 +77,15 @@ specifiedLocale = newLocale; | ||
} | ||
/** | ||
* Returns the currently active locale | ||
**/ | ||
function locale() { | ||
var langRaw = specifiedLocale || window && (window.navigator.userLanguage || window.navigator.language) || 'en_US'; | ||
var langParts = langRaw.replace('-', '_').split('_'); | ||
var language = langParts[0]; | ||
var country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''; | ||
var currentLocale = '' + language + country; | ||
var country = langParts.length > 1 ? "_".concat(langParts[1].toUpperCase()) : ''; | ||
var currentLocale = "".concat(language).concat(country); | ||
currentLocale = mapLocale(currentLocale); | ||
currentLocale = mapLocale(currentLocale); | ||
if (tryToGetLangLoader(currentLocale)) { | ||
@@ -101,2 +96,3 @@ return currentLocale; | ||
currentLocale = mapLocale(language); // fall back to the general language | ||
if (tryToGetLangLoader(currentLocale)) { | ||
@@ -116,6 +112,7 @@ return currentLocale; | ||
} | ||
/** | ||
* Reset all state as if init and setLocale have never been called. Useful for testing. | ||
**/ | ||
function reset() { | ||
@@ -125,3 +122,2 @@ config = undefined; | ||
getLangLoader = undefined; | ||
singleton.messages = {}; | ||
@@ -140,3 +136,4 @@ changeLocaleListeners = []; | ||
function tryToGetLangLoader(forLocale) { | ||
var waitForLangChunk = void 0; | ||
var waitForLangChunk; | ||
try { | ||
@@ -147,2 +144,3 @@ waitForLangChunk = getLangLoader(forLocale); | ||
} | ||
return waitForLangChunk; | ||
@@ -152,3 +150,3 @@ } | ||
function loadBundle(resolve) { | ||
if (!(0, _isFunction2.default)(getLangLoader)) { | ||
if (!(0, _isFunction.default)(getLangLoader)) { | ||
throw new Error('Cannot load a bundle as no valid getLangLoader function has been set'); | ||
@@ -160,3 +158,3 @@ } | ||
singleton.messages = messages; | ||
(0, _forEach2.default)(changeLocaleListeners, function (listener) { | ||
(0, _forEach.default)(changeLocaleListeners, function (listener) { | ||
return listener(); | ||
@@ -163,0 +161,0 @@ }); |
@@ -1,39 +0,25 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _find2 = require('lodash/find'); | ||
var _find3 = _interopRequireDefault(_find2); | ||
var _last2 = require('lodash/last'); | ||
var _last3 = _interopRequireDefault(_last2); | ||
exports.default = plugin; | ||
var _gettextParser = require('gettext-parser'); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _gettextParser2 = _interopRequireDefault(_gettextParser); | ||
var _find2 = _interopRequireDefault(require("lodash/find")); | ||
var _fs = require('fs'); | ||
var _last2 = _interopRequireDefault(require("lodash/last")); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _gettextParser = _interopRequireDefault(require("gettext-parser")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var DEFAULT_FUNCTION_NAME = 'i18n'; | ||
var DEFAULT_FILE_NAME = 'messages.pot'; | ||
var DEFAULT_HEADERS = { | ||
'content-type': 'text/plain; charset=UTF-8' | ||
}; | ||
var DEFAULT_ADD_LOCATION = 'full'; | ||
@@ -50,3 +36,3 @@ | ||
function getContextProperty(node) { | ||
return (0, _find3.default)(node.properties, function (property) { | ||
return (0, _find2.default)(node.properties, function (property) { | ||
return property.key.name === 'context'; | ||
@@ -59,3 +45,2 @@ }); | ||
var right = node.right; | ||
return node.type === 'BinaryExpression' && node.operator === '+' && (isStringLiteral(left) || isStringConcatExpr(left)) && (isStringLiteral(right) || isStringConcatExpr(right)); | ||
@@ -77,4 +62,6 @@ } | ||
function getExtractedComment(node) { | ||
var comments = [];(node.leadingComments || []).forEach(function (commentNode) { | ||
var comments = []; | ||
(node.leadingComments || []).forEach(function (commentNode) { | ||
var match = commentNode.value.match(/^\s*translators:\s*(.*?)\s*$/im); | ||
if (match) { | ||
@@ -89,3 +76,3 @@ comments.push(match[1]); | ||
if (!addLocation || addLocation === 'full') { | ||
return fn + ':' + node.loc.start.line; | ||
return "".concat(fn, ":").concat(node.loc.start.line); | ||
} | ||
@@ -95,4 +82,3 @@ | ||
var index = fn.lastIndexOf('/'); | ||
return fn.slice(index + 1) + ':' + node.loc.start.line; | ||
return "".concat(fn.slice(index + 1), ":").concat(node.loc.start.line); | ||
} | ||
@@ -104,6 +90,5 @@ | ||
function plugin() { | ||
var currentFileName = void 0; | ||
var data = void 0; | ||
var currentFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
return { | ||
@@ -113,11 +98,13 @@ visitor: { | ||
var node = _ref.node; | ||
var extractedComment = getExtractedComment(node); | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
return; | ||
} | ||
node.declarations.forEach(function (declarator) { | ||
var comment = getExtractedComment(declarator); | ||
if (!comment) { | ||
var key = declarator.init.start + '|' + declarator.init.end; | ||
var key = "".concat(declarator.init.start, "|").concat(declarator.init.end); | ||
relocatedComments[key] = extractedComment; | ||
@@ -132,16 +119,15 @@ } | ||
_config$opts$function = _config$opts.functionName, | ||
functionName = _config$opts$function === undefined ? DEFAULT_FUNCTION_NAME : _config$opts$function, | ||
functionName = _config$opts$function === void 0 ? DEFAULT_FUNCTION_NAME : _config$opts$function, | ||
_config$opts$fileName = _config$opts.fileName, | ||
fileName = _config$opts$fileName === undefined ? DEFAULT_FILE_NAME : _config$opts$fileName, | ||
fileName = _config$opts$fileName === void 0 ? DEFAULT_FILE_NAME : _config$opts$fileName, | ||
_config$opts$headers = _config$opts.headers, | ||
headers = _config$opts$headers === undefined ? DEFAULT_HEADERS : _config$opts$headers, | ||
headers = _config$opts$headers === void 0 ? DEFAULT_HEADERS : _config$opts$headers, | ||
_config$opts$addLocat = _config$opts.addLocation, | ||
addLocation = _config$opts$addLocat === undefined ? DEFAULT_ADD_LOCATION : _config$opts$addLocat, | ||
addLocation = _config$opts$addLocat === void 0 ? DEFAULT_ADD_LOCATION : _config$opts$addLocat, | ||
_config$opts$noLocati = _config$opts.noLocation, | ||
noLocation = _config$opts$noLocati === undefined ? !1 : _config$opts$noLocati; | ||
noLocation = _config$opts$noLocati === void 0 ? !1 : _config$opts$noLocati; | ||
var base = config.opts.baseDirectory; | ||
var base = config.opts.baseDirectory; | ||
if (base) { | ||
base = base.match(/^(.*?)\/*$/)[1] + '/'; | ||
base = "".concat(base.match(/^(.*?)\/*$/)[1], "/"); | ||
} | ||
@@ -154,5 +140,6 @@ | ||
headers: headers, | ||
translations: { context: {} } | ||
translations: { | ||
context: {} | ||
} | ||
}; | ||
headers['content-type'] = headers['content-type'] || DEFAULT_HEADERS['content-type']; | ||
@@ -168,4 +155,4 @@ } | ||
var translate = {}; | ||
var args = node.arguments; | ||
var args = node.arguments; | ||
if (args.length === 0) { | ||
@@ -186,2 +173,3 @@ return; | ||
value = getStringValue(args[1]); | ||
if (value) { | ||
@@ -193,3 +181,4 @@ translate.msgid_plural = value; | ||
var fn = config.file.log.filename; | ||
var fn = config.file.opts.filename; | ||
if (base && fn && fn.substr(0, base.length) === base) { | ||
@@ -206,6 +195,8 @@ fn = fn.substr(base.length); | ||
var extractedComment = getExtractedComment(node); | ||
if (!extractedComment) { | ||
extractedComment = getExtractedComment(parent); | ||
if (!extractedComment) { | ||
extractedComment = relocatedComments[node.start + '|' + node.end]; | ||
extractedComment = relocatedComments["".concat(node.start, "|").concat(node.end)]; | ||
} | ||
@@ -215,4 +206,3 @@ } | ||
if (extractedComment && translate.comments) { | ||
translate.comments = (0, _extends3.default)({}, translate.comments, { | ||
translate.comments = (0, _objectSpread2.default)({}, translate.comments, { | ||
extracted: extractedComment | ||
@@ -222,3 +212,3 @@ }); | ||
var options = (0, _last3.default)(args); | ||
var options = (0, _last2.default)(args); | ||
@@ -239,2 +229,3 @@ if (isObjectLiteral(options)) { | ||
var msgctxt = translate.msgctxt; | ||
if (msgctxt) { | ||
@@ -247,4 +238,5 @@ data.translations[msgctxt] = data.translations[msgctxt] || {}; | ||
var output = _gettextParser2.default.po.compile(data); | ||
_fs2.default.writeFileSync(fileName, output); | ||
var output = _gettextParser.default.po.compile(data); | ||
_fs.default.writeFileSync(fileName, output); | ||
} | ||
@@ -251,0 +243,0 @@ } |
@@ -1,3 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,14 +10,7 @@ value: !0 | ||
var _path = require('path'); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var I18NRC_FILENAME = '.i18nrc'; | ||
var existsCache = {}; | ||
@@ -26,3 +21,3 @@ var configCache = {}; | ||
if (existsCache[fileName] == null) { | ||
existsCache[fileName] = _fs2.default.existsSync(fileName); | ||
existsCache[fileName] = _fs.default.existsSync(fileName); | ||
} | ||
@@ -40,8 +35,8 @@ | ||
if (!_path2.default.isAbsolute(location)) { | ||
location = _path2.default.join(process.cwd(), location); | ||
if (!_path.default.isAbsolute(location)) { | ||
location = _path.default.join(process.cwd(), location); | ||
} | ||
do { | ||
var configLoc = _path2.default.join(location, I18NRC_FILENAME); | ||
var configLoc = _path.default.join(location, I18NRC_FILENAME); | ||
@@ -51,3 +46,3 @@ if (exists(configLoc)) { | ||
} | ||
} while (location !== (location = _path2.default.dirname(location))); | ||
} while (location !== (location = _path.default.dirname(location))); | ||
@@ -59,3 +54,2 @@ return null; | ||
var filename = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.'; | ||
var loc = findConfig(filename); | ||
@@ -71,7 +65,8 @@ | ||
var content = _fs2.default.readFileSync(loc, 'utf8'); | ||
var content = _fs.default.readFileSync(loc, 'utf8'); | ||
try { | ||
configCache[loc] = JSON.parse(content); | ||
} catch (err) { | ||
err.message = loc + ': Error while parsing JSON - ' + err.message; | ||
err.message = "".concat(loc, ": Error while parsing JSON - ").concat(err.message); | ||
throw err; | ||
@@ -78,0 +73,0 @@ } |
@@ -1,67 +0,49 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); | ||
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties'); | ||
var _each2 = _interopRequireDefault(require("lodash/each")); | ||
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); | ||
var _glob = _interopRequireDefault(require("glob")); | ||
var _each2 = require('lodash/each'); | ||
var _progress = _interopRequireDefault(require("progress")); | ||
var _each3 = _interopRequireDefault(_each2); | ||
var _core = require("@babel/core"); | ||
var _glob = require('glob'); | ||
var _babelGettextExtractor = _interopRequireDefault(require("./babel-gettext-extractor")); | ||
var _glob2 = _interopRequireDefault(_glob); | ||
var _config = _interopRequireDefault(require("./config")); | ||
var _progress = require('progress'); | ||
var _progress2 = _interopRequireDefault(_progress); | ||
var _babelCore = require('babel-core'); | ||
var _babelGettextExtractor = require('./babel-gettext-extractor'); | ||
var _babelGettextExtractor2 = _interopRequireDefault(_babelGettextExtractor); | ||
var _config = require('./config'); | ||
var _config2 = _interopRequireDefault(_config); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if (process.argv.length < 3) { | ||
throw new Error('Invalid arguments, expected: \'node i18n/scripts/extract.js "source_file_pattern"\', got: ' + process.argv.join(' ')); | ||
throw new Error("Invalid arguments, expected: 'node i18n/scripts/extract.js \"source_file_pattern\"', got: ".concat(process.argv.join(' '))); | ||
} | ||
var files = _glob.default.sync(process.argv[2]); | ||
var files = _glob2.default.sync(process.argv[2]); | ||
var progressBar = new _progress2.default(' extracting [:bar] :percent :fileName', { | ||
var progressBar = new _progress.default(' extracting [:bar] :percent :fileName', { | ||
total: files.length, | ||
width: 10 | ||
}); | ||
(0, _each3.default)(files, function (fileName) { | ||
(0, _each2.default)(files, function (fileName) { | ||
// eslint-disable-next-line no-console | ||
progressBar.tick(1, { fileName: fileName }); | ||
progressBar.tick(1, { | ||
fileName: fileName | ||
}); | ||
var _getConfig = (0, _config2.default)(fileName), | ||
var _getConfig = (0, _config.default)(fileName), | ||
_getConfig$babel = _getConfig.babel, | ||
babel = _getConfig$babel === undefined ? {} : _getConfig$babel, | ||
config = (0, _objectWithoutProperties3.default)(_getConfig, ['babel']); | ||
babel = _getConfig$babel === void 0 ? {} : _getConfig$babel, | ||
config = (0, _objectWithoutProperties2.default)(_getConfig, ["babel"]); | ||
var _babel$plugins = babel.plugins, | ||
plugins = _babel$plugins === undefined ? [] : _babel$plugins; | ||
(0, _babelCore.transformFileSync)(fileName, (0, _extends3.default)({}, babel, { | ||
plugins: [].concat((0, _toConsumableArray3.default)(plugins), [[_babelGettextExtractor2.default, config]]) | ||
plugins = _babel$plugins === void 0 ? [] : _babel$plugins; | ||
(0, _core.transformFileSync)(fileName, (0, _objectSpread2.default)({}, babel, { | ||
plugins: (0, _toConsumableArray2.default)(plugins).concat([[_babelGettextExtractor.default, config]]) | ||
})); | ||
}); |
@@ -1,15 +0,11 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _each2 = require('lodash/each'); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _each3 = _interopRequireDefault(_each2); | ||
var _each2 = _interopRequireDefault(require("lodash/each")); | ||
var _path = require('path'); | ||
var _path = _interopRequireDefault(require("path")); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _child_process = require("child_process"); | ||
var _child_process = require('child_process'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
if (process.argv.length < 4) { | ||
@@ -19,10 +15,9 @@ throw new Error('Invalid arguments, expected: `node i18n/scripts/merge.js pot_file po_file ...`'); | ||
var templatePath = _path2.default.resolve(process.cwd(), process.argv[2]); | ||
var templatePath = _path.default.resolve(process.cwd(), process.argv[2]); | ||
(0, _each3.default)(process.argv.slice(3), function (fileName) { | ||
(0, _child_process.exec)('msgmerge -o ' + fileName + ' ' + fileName + ' ' + templatePath, function (error, stdout, stderr) { | ||
(0, _each2.default)(process.argv.slice(3), function (fileName) { | ||
(0, _child_process.exec)("msgmerge -o ".concat(fileName, " ").concat(fileName, " ").concat(templatePath), function (error, stdout, stderr) { | ||
// eslint-disable-next-line no-console | ||
if (error) {} | ||
// eslint-disable-next-line no-console | ||
}); | ||
}); |
@@ -1,55 +0,33 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
exports.default = void 0; | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread")); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _isString = _interopRequireDefault(require("lodash/isString")); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _isNumber = _interopRequireDefault(require("lodash/isNumber")); | ||
var _isString = require('lodash/isString'); | ||
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject")); | ||
var _isString2 = _interopRequireDefault(_isString); | ||
var _forEach = _interopRequireDefault(require("lodash/forEach")); | ||
var _isNumber = require('lodash/isNumber'); | ||
var _pickBy = _interopRequireDefault(require("lodash/pickBy")); | ||
var _isNumber2 = _interopRequireDefault(_isNumber); | ||
var _has = _interopRequireDefault(require("lodash/has")); | ||
var _isPlainObject = require('lodash/isPlainObject'); | ||
var _escape = _interopRequireDefault(require("lodash/escape")); | ||
var _isPlainObject2 = _interopRequireDefault(_isPlainObject); | ||
var _marked = _interopRequireDefault(require("marked")); | ||
var _forEach = require('lodash/forEach'); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _forEach2 = _interopRequireDefault(_forEach); | ||
var _pickBy = require('lodash/pickBy'); | ||
var _pickBy2 = _interopRequireDefault(_pickBy); | ||
var _has = require('lodash/has'); | ||
var _has2 = _interopRequireDefault(_has); | ||
var _escape = require('lodash/escape'); | ||
var _escape2 = _interopRequireDefault(_escape); | ||
var _marked = require('marked'); | ||
var _marked2 = _interopRequireDefault(_marked); | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var placeholderRegex = /__(\w+)__/g; | ||
var defaultOptions = { | ||
@@ -59,3 +37,3 @@ markdown: !1 | ||
exports.default = function (singleton) { | ||
var _default = function _default(singleton) { | ||
return function translate(text, plural, options) { | ||
@@ -67,3 +45,3 @@ // singleton.messages contains the translation messages for the currently active languae | ||
if (!finalOptions && (0, _isPlainObject2.default)(finalPlural)) { | ||
if (!finalOptions && (0, _isPlainObject.default)(finalPlural)) { | ||
finalOptions = plural; | ||
@@ -73,33 +51,29 @@ finalPlural = undefined; | ||
finalOptions = (0, _extends3.default)({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? finalOptions.context + '\x04' : '' | ||
finalOptions = (0, _objectSpread2.default)({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? "".concat(finalOptions.context, "\x04") : '' | ||
}); | ||
var _slice = (singleton.messages[finalOptions.context + text] || [null, null, null]).slice(1), | ||
_slice2 = (0, _slicedToArray3.default)(_slice, 2), | ||
_slice2 = (0, _slicedToArray2.default)(_slice, 2), | ||
translatedSingular = _slice2[0], | ||
translatedPlural = _slice2[1]; | ||
translatedPlural = _slice2[1]; // find the raw translation message | ||
// find the raw translation message | ||
var translation; | ||
var translation = void 0; | ||
if (finalPlural && needsPlural(finalOptions)) { | ||
translation = translatedPlural && (0, _isString2.default)(translatedPlural) ? translatedPlural : finalPlural; | ||
translation = translatedPlural && (0, _isString.default)(translatedPlural) ? translatedPlural : finalPlural; | ||
} else { | ||
translation = translatedSingular && (0, _isString2.default)(translatedSingular) ? translatedSingular : text; | ||
} | ||
translation = translatedSingular && (0, _isString.default)(translatedSingular) ? translatedSingular : text; | ||
} // apply markdown processing if necessary | ||
// apply markdown processing if necessary | ||
if (finalOptions.markdown) { | ||
translation = applyMarkdown(translation); | ||
} | ||
} // insert regular interpolations | ||
// insert regular interpolations | ||
translation = insertInterpolations(translation, finalOptions); | ||
// insert React component interpolations | ||
translation = insertInterpolations(translation, finalOptions); // insert React component interpolations | ||
var result = insertReactComponentInterpolations(translation, finalOptions); | ||
return result.length === 1 ? result[0] : result; | ||
@@ -109,4 +83,6 @@ }; | ||
exports.default = _default; | ||
function needsPlural(options) { | ||
return (0, _isNumber2.default)(options.count) && Math.abs(options.count) !== 1; | ||
return (0, _isNumber.default)(options.count) && Math.abs(options.count) !== 1; | ||
} | ||
@@ -122,5 +98,4 @@ | ||
// exclude them from the markdown notation. Use asterisk (*) instead.) | ||
var finalTranslation = (0, _marked2.default)(translation.replace(/_/g, '\\_')); | ||
var finalTranslation = (0, _marked.default)(translation.replace(/_/g, '\\_')); // remove single, outer wrapping <p>-tag | ||
// remove single, outer wrapping <p>-tag | ||
if (isWrappedInPTag(finalTranslation)) { | ||
@@ -136,17 +111,18 @@ // last occurrence of <p> is at the start, first occurence of </p> is a the very end | ||
// eslint-disable-next-line react/no-danger | ||
return _react2.default.createElement('span', { dangerouslySetInnerHTML: { __html: html } }); | ||
return _react.default.createElement("span", { | ||
dangerouslySetInnerHTML: { | ||
__html: html | ||
} | ||
}); | ||
} | ||
function insertInterpolations(translation, options) { | ||
var regularInterpolations = (0, _pickBy2.default)(options, function (val, key) { | ||
return !(0, _has2.default)(defaultOptions, key) && !_react2.default.isValidElement(val); | ||
var regularInterpolations = (0, _pickBy.default)(options, function (val, key) { | ||
return !(0, _has.default)(defaultOptions, key) && !_react.default.isValidElement(val); | ||
}); | ||
var finalTranslation = translation; | ||
(0, _forEach2.default)(regularInterpolations, function (val, key) { | ||
finalTranslation = finalTranslation.replace(new RegExp('__' + key + '__', 'g'), options.markdown ? (0, _escape2.default)(val) : val // only escape options when using markdown | ||
(0, _forEach.default)(regularInterpolations, function (val, key) { | ||
finalTranslation = finalTranslation.replace(new RegExp("__".concat(key, "__"), 'g'), options.markdown ? (0, _escape.default)(val) : val // only escape options when using markdown | ||
); | ||
}); | ||
return finalTranslation; | ||
@@ -157,4 +133,4 @@ } | ||
var result = []; | ||
var match = void 0; | ||
var substr = void 0; | ||
var match; | ||
var substr; | ||
var start = 0; | ||
@@ -171,4 +147,4 @@ | ||
if (_react2.default.isValidElement(component)) { | ||
result.push(result.indexOf(component) >= 0 ? _react2.default.cloneElement(component) : component); | ||
if (_react.default.isValidElement(component)) { | ||
result.push(result.indexOf(component) >= 0 ? _react.default.cloneElement(component) : component); | ||
} else { | ||
@@ -178,15 +154,17 @@ // no interpolation specified, leave the placeholder unchanged | ||
} | ||
start = placeholderRegex.lastIndex; | ||
} | ||
} // append part after last match | ||
// append part after last match | ||
if (start < translation.length) { | ||
substr = translation.substring(start); | ||
result.push(options.markdown ? htmlStringToReactComponent(substr) : substr); | ||
} | ||
} // re-concatenate all string elements | ||
// re-concatenate all string elements | ||
return result.reduce(function (acc, element) { | ||
var lastAccumulatedElement = acc[acc.length - 1]; | ||
if ((0, _isString2.default)(element) && (0, _isString2.default)(lastAccumulatedElement)) { | ||
if ((0, _isString.default)(element) && (0, _isString.default)(lastAccumulatedElement)) { | ||
// eslint-disable-next-line no-param-reassign | ||
@@ -197,4 +175,5 @@ acc[acc.length - 1] = lastAccumulatedElement + element; | ||
} | ||
return acc; | ||
}, []); | ||
} |
@@ -1,1 +0,1 @@ | ||
'use strict'; | ||
"use strict"; |
{ | ||
"name": "signavio-i18n", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"description": "Minimalist gettext style i18n for JavaScript", | ||
@@ -43,3 +43,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"babel-core": "^6.2.1", | ||
"@babel/runtime": "^7.0.0", | ||
"gettext-parser": "^1.1.2", | ||
@@ -52,16 +52,25 @@ "glob": "^6.0.1", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0", | ||
"@babel/plugin-proposal-decorators": "^7.0.0", | ||
"@babel/plugin-proposal-export-namespace-from": "^7.0.0", | ||
"@babel/plugin-proposal-function-sent": "^7.0.0", | ||
"@babel/plugin-proposal-json-strings": "^7.0.0", | ||
"@babel/plugin-proposal-numeric-separator": "^7.0.0", | ||
"@babel/plugin-proposal-throw-expressions": "^7.0.0", | ||
"@babel/plugin-syntax-dynamic-import": "^7.0.0", | ||
"@babel/plugin-syntax-import-meta": "^7.0.0", | ||
"@babel/plugin-transform-proto-to-assign": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.0.0", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"ajv": "^6.1.1", | ||
"babel-cli": "^6.2.0", | ||
"babel-loader": "^6.3.2", | ||
"babel-plugin-lodash": "^3.2.11", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-loader": "^8.0.0", | ||
"babel-plugin-lodash": "^3.3.4", | ||
"babel-plugin-transform-minify-booleans": "^6.8.3", | ||
"babel-plugin-transform-proto-to-assign": "^6.26.0", | ||
"babel-plugin-transform-remove-console": "^6.8.5", | ||
"babel-plugin-transform-remove-debugger": "^6.8.5", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-polyfill": "^6.2.0", | ||
"babel-preset-es2015": "^6.1.18", | ||
"babel-preset-react": "^6.1.18", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"bundle-loader": "^0.5.4", | ||
@@ -99,4 +108,5 @@ "chai": "^3.4.1", | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"react": "^15.0.1 || ^16.0.0" | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
[![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 | ||
[![CircleCI][build-badge]][build] | ||
[![npm package][npm-badge]][npm] | ||
Minimalist gettext style i18n for JavaScript | ||
@@ -156,3 +156,6 @@ | ||
[version-badge]: https://img.shields.io/npm/v/signavio-i18n.svg?style=flat-square | ||
[package]: https://www.npmjs.com/package/signavio-i18n | ||
[build-badge]: https://circleci.com/gh/signavio/i18n/tree/master.svg?style=shield&circle-token=:circle-token | ||
[build]: https://circleci.com/gh/signavio/i18n/tree/master | ||
[npm-badge]: https://img.shields.io/npm/v/signavio-i18n.png?style=flat-square | ||
[npm]: https://www.npmjs.org/package/signavio-i18n |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1325369
155
11662
161
8
53
27
14
+ Added@babel/runtime@^7.0.0
+ Added@ampproject/remapping@2.3.0(transitive)
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/compat-data@7.26.2(transitive)
+ Added@babel/core@7.26.0(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-compilation-targets@7.25.9(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/helper-module-transforms@7.26.0(transitive)
+ Added@babel/helper-string-parser@7.25.9(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Added@babel/helper-validator-option@7.25.9(transitive)
+ Added@babel/helpers@7.26.0(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/runtime@7.26.0(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@babel/types@7.26.0(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addedbrowserslist@4.24.2(transitive)
+ Addedcaniuse-lite@1.0.30001684(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedelectron-to-chromium@1.5.64(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedgensync@1.0.0-beta.2(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedjson5@2.2.3(transitive)
+ Addedlru-cache@5.1.1(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
+ Addedyallist@3.1.1(transitive)
- Removedbabel-core@^6.2.1
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedbabel-code-frame@6.26.0(transitive)
- Removedbabel-core@6.26.3(transitive)
- Removedbabel-generator@6.26.1(transitive)
- Removedbabel-helpers@6.24.1(transitive)
- Removedbabel-messages@6.23.0(transitive)
- Removedbabel-register@6.26.0(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedbabel-template@6.26.0(transitive)
- Removedbabel-traverse@6.26.0(transitive)
- Removedbabel-types@6.26.0(transitive)
- Removedbabylon@6.18.0(transitive)
- Removedchalk@1.1.3(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddetect-indent@4.0.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesutils@2.0.3(transitive)
- Removedglobals@9.18.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhome-or-tmp@2.0.0(transitive)
- Removedinvariant@2.2.4(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedjs-tokens@3.0.2(transitive)
- Removedjsesc@1.3.0(transitive)
- Removedjson5@0.5.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.0.0(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedprivate@0.1.8(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedslash@1.0.0(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-support@0.4.18(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedto-fast-properties@1.0.3(transitive)
- Removedtrim-right@1.0.1(transitive)