signavio-i18n
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -150,9 +150,5 @@ /******/ (function(modules) { // webpackBootstrap | ||
"use strict"; | ||
var testsContext = __webpack_require__(4); | ||
var runnable = testsContext.keys(); | ||
runnable.forEach(testsContext); | ||
@@ -162,50 +158,36 @@ | ||
/* 6 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_lodash_isFunction__ = __webpack_require__(22); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_lodash_isFunction___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_lodash_isFunction__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_lodash_forEach__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_lodash_forEach___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_lodash_forEach__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__translate__ = __webpack_require__(8); | ||
/* harmony export (immutable) */ __webpack_exports__["c"] = init; | ||
/* harmony export (immutable) */ __webpack_exports__["b"] = setLocale; | ||
/* unused harmony export locale */ | ||
/* unused harmony export onChangeLocale */ | ||
/* unused harmony export offChangeLocale */ | ||
/* harmony export (immutable) */ __webpack_exports__["a"] = reset; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
exports.init = init; | ||
exports.setLocale = setLocale; | ||
exports.locale = locale; | ||
exports.onChangeLocale = onChangeLocale; | ||
exports.offChangeLocale = offChangeLocale; | ||
exports.reset = reset; | ||
var _isFunction = __webpack_require__(22); | ||
var _isFunction2 = _interopRequireDefault(_isFunction); | ||
var _forEach = __webpack_require__(2); | ||
var _forEach2 = _interopRequireDefault(_forEach); | ||
var _translate = __webpack_require__(8); | ||
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 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2__translate__["a" /* default */])(singleton); | ||
/* harmony default export */ __webpack_exports__["d"] = (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 | ||
@@ -222,3 +204,2 @@ * an automatically detected locale if setLocale has not been called before. | ||
var configObj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
getLangLoader = getLangLoaderFn; | ||
@@ -228,3 +209,2 @@ config = configObj; | ||
} | ||
/** | ||
@@ -236,2 +216,3 @@ * Sets the locale to use. If init has been called before, returns a promise that resolves as soon | ||
*/ | ||
function setLocale(newLocale) { | ||
@@ -246,15 +227,14 @@ 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)) { | ||
@@ -265,2 +245,3 @@ return currentLocale; | ||
currentLocale = mapLocale(language); // fall back to the general language | ||
if (tryToGetLangLoader(currentLocale)) { | ||
@@ -272,14 +253,12 @@ return currentLocale; | ||
} | ||
function onChangeLocale(listener) { | ||
changeLocaleListeners.push(listener); | ||
} | ||
function offChangeLocale(listener) { | ||
changeLocaleListeners.splice(changeLocaleListeners.indexOf(listener), 1); | ||
} | ||
/** | ||
* Reset all state as if init and setLocale have never been called. Useful for testing. | ||
**/ | ||
function reset() { | ||
@@ -289,3 +268,2 @@ config = undefined; | ||
getLangLoader = undefined; | ||
singleton.messages = {}; | ||
@@ -304,3 +282,4 @@ changeLocaleListeners = []; | ||
function tryToGetLangLoader(forLocale) { | ||
var waitForLangChunk = void 0; | ||
var waitForLangChunk; | ||
try { | ||
@@ -311,2 +290,3 @@ waitForLangChunk = getLangLoader(forLocale); | ||
} | ||
return waitForLangChunk; | ||
@@ -316,3 +296,3 @@ } | ||
function loadBundle(resolve) { | ||
if (!(0, _isFunction2.default)(getLangLoader)) { | ||
if (!__WEBPACK_IMPORTED_MODULE_0_lodash_isFunction___default()(getLangLoader)) { | ||
throw new Error('Cannot load a bundle as no valid getLangLoader function has been set'); | ||
@@ -324,3 +304,3 @@ } | ||
singleton.messages = messages; | ||
(0, _forEach2.default)(changeLocaleListeners, function (listener) { | ||
__WEBPACK_IMPORTED_MODULE_1_lodash_forEach___default()(changeLocaleListeners, function (listener) { | ||
return listener(); | ||
@@ -334,24 +314,13 @@ }); | ||
/* 7 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_path__ = __webpack_require__(28); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_path___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_path__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_fs__ = __webpack_require__(1); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_fs___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_fs__); | ||
/* harmony export (immutable) */ __webpack_exports__["a"] = getConfig; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
exports.default = getConfig; | ||
var _path = __webpack_require__(28); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _fs = __webpack_require__(1); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var I18NRC_FILENAME = '.i18nrc'; | ||
var existsCache = {}; | ||
@@ -362,3 +331,3 @@ var configCache = {}; | ||
if (existsCache[fileName] == null) { | ||
existsCache[fileName] = _fs2.default.existsSync(fileName); | ||
existsCache[fileName] = __WEBPACK_IMPORTED_MODULE_1_fs___default.a.existsSync(fileName); | ||
} | ||
@@ -376,8 +345,8 @@ | ||
if (!_path2.default.isAbsolute(location)) { | ||
location = _path2.default.join(process.cwd(), location); | ||
if (!__WEBPACK_IMPORTED_MODULE_0_path___default.a.isAbsolute(location)) { | ||
location = __WEBPACK_IMPORTED_MODULE_0_path___default.a.join(process.cwd(), location); | ||
} | ||
do { | ||
var configLoc = _path2.default.join(location, I18NRC_FILENAME); | ||
var configLoc = __WEBPACK_IMPORTED_MODULE_0_path___default.a.join(location, I18NRC_FILENAME); | ||
@@ -387,3 +356,3 @@ if (exists(configLoc)) { | ||
} | ||
} while (location !== (location = _path2.default.dirname(location))); | ||
} while (location !== (location = __WEBPACK_IMPORTED_MODULE_0_path___default.a.dirname(location))); | ||
@@ -395,3 +364,2 @@ return null; | ||
var filename = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '.'; | ||
var loc = findConfig(filename); | ||
@@ -407,7 +375,8 @@ | ||
var content = _fs2.default.readFileSync(loc, 'utf8'); | ||
var content = __WEBPACK_IMPORTED_MODULE_1_fs___default.a.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; | ||
@@ -421,64 +390,43 @@ } | ||
/* 8 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_runtime_helpers_slicedToArray__ = __webpack_require__(17); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_runtime_helpers_slicedToArray___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_runtime_helpers_slicedToArray__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__babel_runtime_helpers_objectSpread__ = __webpack_require__(16); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__babel_runtime_helpers_objectSpread___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1__babel_runtime_helpers_objectSpread__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_lodash_isString__ = __webpack_require__(25); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_lodash_isString___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_lodash_isString__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_isNumber__ = __webpack_require__(23); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_lodash_isNumber___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_lodash_isNumber__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_lodash_isPlainObject__ = __webpack_require__(24); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_lodash_isPlainObject___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_lodash_isPlainObject__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_lodash_forEach__ = __webpack_require__(2); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5_lodash_forEach___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_5_lodash_forEach__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_lodash_pickBy__ = __webpack_require__(26); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_lodash_pickBy___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6_lodash_pickBy__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_lodash_has__ = __webpack_require__(21); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7_lodash_has___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_7_lodash_has__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_lodash_escape__ = __webpack_require__(20); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_8_lodash_escape___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_8_lodash_escape__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_marked__ = __webpack_require__(27); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_9_marked___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_9_marked__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_react__ = __webpack_require__(3); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_10_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_10_react__); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
var _slicedToArray2 = __webpack_require__(17); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _extends2 = __webpack_require__(16); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _isString = __webpack_require__(25); | ||
var _isString2 = _interopRequireDefault(_isString); | ||
var _isNumber = __webpack_require__(23); | ||
var _isNumber2 = _interopRequireDefault(_isNumber); | ||
var _isPlainObject = __webpack_require__(24); | ||
var _isPlainObject2 = _interopRequireDefault(_isPlainObject); | ||
var _forEach = __webpack_require__(2); | ||
var _forEach2 = _interopRequireDefault(_forEach); | ||
var _pickBy = __webpack_require__(26); | ||
var _pickBy2 = _interopRequireDefault(_pickBy); | ||
var _has = __webpack_require__(21); | ||
var _has2 = _interopRequireDefault(_has); | ||
var _escape = __webpack_require__(20); | ||
var _escape2 = _interopRequireDefault(_escape); | ||
var _marked = __webpack_require__(27); | ||
var _marked2 = _interopRequireDefault(_marked); | ||
var _react = __webpack_require__(3); | ||
var _react2 = _interopRequireDefault(_react); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var placeholderRegex = /__(\w+)__/g; | ||
var defaultOptions = { | ||
markdown: !1 | ||
}; | ||
exports.default = function (singleton) { | ||
/* harmony default export */ __webpack_exports__["a"] = (function (singleton) { | ||
return function translate(text, plural, options) { | ||
@@ -490,3 +438,3 @@ // singleton.messages contains the translation messages for the currently active languae | ||
if (!finalOptions && (0, _isPlainObject2.default)(finalPlural)) { | ||
if (!finalOptions && __WEBPACK_IMPORTED_MODULE_4_lodash_isPlainObject___default()(finalPlural)) { | ||
finalOptions = plural; | ||
@@ -496,39 +444,35 @@ finalPlural = undefined; | ||
finalOptions = (0, _extends3.default)({}, defaultOptions, finalOptions, { | ||
context: finalOptions && finalOptions.context ? finalOptions.context + '\x04' : '' | ||
finalOptions = __WEBPACK_IMPORTED_MODULE_1__babel_runtime_helpers_objectSpread___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 = __WEBPACK_IMPORTED_MODULE_0__babel_runtime_helpers_slicedToArray___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 && __WEBPACK_IMPORTED_MODULE_2_lodash_isString___default()(translatedPlural) ? translatedPlural : finalPlural; | ||
} else { | ||
translation = translatedSingular && (0, _isString2.default)(translatedSingular) ? translatedSingular : text; | ||
} | ||
translation = translatedSingular && __WEBPACK_IMPORTED_MODULE_2_lodash_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; | ||
}; | ||
}; | ||
}); | ||
function needsPlural(options) { | ||
return (0, _isNumber2.default)(options.count) && Math.abs(options.count) !== 1; | ||
return __WEBPACK_IMPORTED_MODULE_3_lodash_isNumber___default()(options.count) && Math.abs(options.count) !== 1; | ||
} | ||
@@ -544,5 +488,4 @@ | ||
// exclude them from the markdown notation. Use asterisk (*) instead.) | ||
var finalTranslation = (0, _marked2.default)(translation.replace(/_/g, '\\_')); | ||
var finalTranslation = __WEBPACK_IMPORTED_MODULE_9_marked___default()(translation.replace(/_/g, '\\_')); // remove single, outer wrapping <p>-tag | ||
// remove single, outer wrapping <p>-tag | ||
if (isWrappedInPTag(finalTranslation)) { | ||
@@ -558,17 +501,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 __WEBPACK_IMPORTED_MODULE_10_react___default.a.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 = __WEBPACK_IMPORTED_MODULE_6_lodash_pickBy___default()(options, function (val, key) { | ||
return !__WEBPACK_IMPORTED_MODULE_7_lodash_has___default()(defaultOptions, key) && !__WEBPACK_IMPORTED_MODULE_10_react___default.a.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 | ||
__WEBPACK_IMPORTED_MODULE_5_lodash_forEach___default()(regularInterpolations, function (val, key) { | ||
finalTranslation = finalTranslation.replace(new RegExp("__".concat(key, "__"), 'g'), options.markdown ? __WEBPACK_IMPORTED_MODULE_8_lodash_escape___default()(val) : val // only escape options when using markdown | ||
); | ||
}); | ||
return finalTranslation; | ||
@@ -579,4 +523,4 @@ } | ||
var result = []; | ||
var match = void 0; | ||
var substr = void 0; | ||
var match; | ||
var substr; | ||
var start = 0; | ||
@@ -593,4 +537,4 @@ | ||
if (_react2.default.isValidElement(component)) { | ||
result.push(result.indexOf(component) >= 0 ? _react2.default.cloneElement(component) : component); | ||
if (__WEBPACK_IMPORTED_MODULE_10_react___default.a.isValidElement(component)) { | ||
result.push(result.indexOf(component) >= 0 ? __WEBPACK_IMPORTED_MODULE_10_react___default.a.cloneElement(component) : component); | ||
} else { | ||
@@ -600,15 +544,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 (__WEBPACK_IMPORTED_MODULE_2_lodash_isString___default()(element) && __WEBPACK_IMPORTED_MODULE_2_lodash_isString___default()(lastAccumulatedElement)) { | ||
// eslint-disable-next-line no-param-reassign | ||
@@ -619,2 +565,3 @@ acc[acc.length - 1] = lastAccumulatedElement + element; | ||
} | ||
return acc; | ||
@@ -626,11 +573,6 @@ }, []); | ||
/* 9 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: !0 | ||
}); | ||
exports.default = { | ||
/* harmony default export */ __webpack_exports__["a"] = ({ | ||
default: 'en_US', | ||
@@ -641,31 +583,24 @@ map: { | ||
} | ||
}; | ||
}); | ||
/***/ }), | ||
/* 10 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(3); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react_dom_server__ = __webpack_require__(29); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react_dom_server___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_react_dom_server__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_chai__ = __webpack_require__(0); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_chai___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_chai__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__src__ = __webpack_require__(6); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__config__ = __webpack_require__(9); | ||
var _react = __webpack_require__(3); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _server = __webpack_require__(29); | ||
var _server2 = _interopRequireDefault(_server); | ||
var _chai = __webpack_require__(0); | ||
var _src = __webpack_require__(6); | ||
var _src2 = _interopRequireDefault(_src); | ||
var _config = __webpack_require__(9); | ||
var _config2 = _interopRequireDefault(_config); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getLangLoader(locale) { | ||
@@ -675,3 +610,5 @@ // A runtime exception will be throw every time that the requested locale file | ||
// separate bundles. | ||
// eslint-disable-next-line global-require,import/no-dynamic-require | ||
// Don't use string template here because of weird webpack bug: | ||
// https://github.com/webpack/webpack/issues/4921 | ||
// eslint-disable-next-line global-require,import/no-dynamic-require,prefer-template | ||
return __webpack_require__(15)("./" + locale + '.po'); | ||
@@ -681,22 +618,19 @@ } | ||
describe('i18n', function () { | ||
beforeEach(_src.reset); | ||
beforeEach(__WEBPACK_IMPORTED_MODULE_3__src__["a" /* reset */]); | ||
describe('setLocale', function () { | ||
it('should make sure the correct bundle will be loaded when init is called', function () { | ||
(0, _src.setLocale)('de_DE'); | ||
// return a promise and use mocha's built in promises support | ||
return (0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('for')).to.equal('für'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('de_DE'); // return a promise and use mocha's built in promises support | ||
return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('for')).to.equal('für'); | ||
}); | ||
}); | ||
it('should load the respective bundle if called after init', function (done) { | ||
(0, _src.setLocale)('en_US'); | ||
// return a promise and use mocha's built in promises support | ||
(0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('for')).to.equal('for'); | ||
(0, _src.setLocale)('de_DE'); | ||
return (0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('for')).to.equal('für'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('en_US'); // return a promise and use mocha's built in promises support | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('for')).to.equal('for'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('de_DE'); | ||
return __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('for')).to.equal('für'); | ||
done(); | ||
@@ -707,147 +641,139 @@ }); | ||
}); | ||
describe('#translate', function () { | ||
it('should return a plain string whenever possible', function () { | ||
var t = (0, _src2.default)('This is a __test__.', { test: 'success' }); | ||
(0, _chai.expect)(t).to.be.a('string'); | ||
(0, _chai.expect)(t).to.equal('This is a success.'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is a __test__.', { | ||
test: 'success' | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.be.a('string'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.equal('This is a success.'); | ||
}); | ||
it('should not escape interpolations', function () { | ||
var t = (0, _src2.default)('This is a __test__.', { test: '<success>' }); | ||
(0, _chai.expect)(t).to.be.a('string'); | ||
(0, _chai.expect)(t).to.equal('This is a <success>.'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is a __test__.', { | ||
test: '<success>' | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.be.a('string'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.equal('This is a <success>.'); | ||
}); | ||
it('should support using Markdown in translation messages', function () { | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: 'success', markdown: !0 }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
(0, _chai.expect)(renderedHtml).to.equal('<span>This is a <strong>success</strong>.</span>'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is a **__test__**.', { | ||
test: 'success', | ||
markdown: !0 | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__WEBPACK_IMPORTED_MODULE_0_react___default.a.isValidElement(t)).to.be.true; | ||
var renderedHtml = __WEBPACK_IMPORTED_MODULE_1_react_dom_server___default.a.renderToStaticMarkup(t); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(renderedHtml).to.equal('<span>This is a <strong>success</strong>.</span>'); | ||
}); | ||
it('should correctly escape interpolations when used with Markdown', function () { | ||
var t = (0, _src2.default)('This is a **__test__**.', { test: '<success>', markdown: !0 }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
(0, _chai.expect)(renderedHtml).to.equal('<span>This is a <strong><success></strong>.</span>'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is a **__test__**.', { | ||
test: '<success>', | ||
markdown: !0 | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__WEBPACK_IMPORTED_MODULE_0_react___default.a.isValidElement(t)).to.be.true; | ||
var renderedHtml = __WEBPACK_IMPORTED_MODULE_1_react_dom_server___default.a.renderToStaticMarkup(t); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(renderedHtml).to.equal('<span>This is a <strong><success></strong>.</span>'); | ||
}); | ||
it('should not replace "__markdown__" placeholders', function () { | ||
var t = (0, _src2.default)('This is __markdown__.', { markdown: !0 }); | ||
var renderedHtml = _server2.default.renderToStaticMarkup(_react2.default.createElement( | ||
'div', | ||
null, | ||
t | ||
)); | ||
(0, _chai.expect)(renderedHtml).to.equal('<div><span>This is </span>__markdown__<span>.</span></div>'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is __markdown__.', { | ||
markdown: !0 | ||
}); | ||
var renderedHtml = __WEBPACK_IMPORTED_MODULE_1_react_dom_server___default.a.renderToStaticMarkup(__WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement("div", null, t)); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(renderedHtml).to.equal('<div><span>This is </span>__markdown__<span>.</span></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 }); | ||
(0, _chai.expect)(_react2.default.isValidElement(t)).to.be.true; | ||
var renderedHtml = _server2.default.renderToStaticMarkup(t); | ||
(0, _chai.expect)(renderedHtml).to.equal('<span>foo <strong>bar** baz **baa</strong></span>'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('**__foo__**', { | ||
foo: 'bar** baz **baa', | ||
markdown: !0 | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__WEBPACK_IMPORTED_MODULE_0_react___default.a.isValidElement(t)).to.be.true; | ||
var renderedHtml = __WEBPACK_IMPORTED_MODULE_1_react_dom_server___default.a.renderToStaticMarkup(t); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(renderedHtml).to.equal('<span>foo <strong>bar** baz **baa</strong></span>'); | ||
}); | ||
it('should support React components for interpolation values', function () { | ||
var comp = _react2.default.createElement( | ||
'div', | ||
null, | ||
'comp content' | ||
); | ||
var t = (0, _src2.default)('before __reactComp__ after', { | ||
var comp = __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement("div", null, "comp content"); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('before __reactComp__ after', { | ||
reactComp: comp | ||
}); | ||
(0, _chai.expect)(t).to.be.an('array'); | ||
(0, _chai.expect)(t).to.have.length(3); | ||
(0, _chai.expect)(t[0]).to.equal('before '); | ||
(0, _chai.expect)(t[1]).to.equal(comp); | ||
(0, _chai.expect)(t[2]).to.equal(' after'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.be.an('array'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.have.length(3); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[0]).to.equal('before '); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[1]).to.equal(comp); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[2]).to.equal(' after'); | ||
}); | ||
it('should support using the same React component multiple times', function () { | ||
var comp = _react2.default.createElement( | ||
'div', | ||
null, | ||
'comp content' | ||
); | ||
var t = (0, _src2.default)('before __reactComp__ within __reactComp__', { | ||
var comp = __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement("div", null, "comp content"); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('before __reactComp__ within __reactComp__', { | ||
reactComp: comp | ||
}); | ||
(0, _chai.expect)(t).to.be.an('array'); | ||
(0, _chai.expect)(t).to.have.length(4); | ||
(0, _chai.expect)(t[0]).to.equal('before '); | ||
(0, _chai.expect)(t[1]).to.deep.equal(comp); | ||
(0, _chai.expect)(t[2]).to.equal(' within '); | ||
(0, _chai.expect)(t[3]).to.deep.equal(comp); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.be.an('array'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.have.length(4); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[0]).to.equal('before '); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[1]).to.deep.equal(comp); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[2]).to.equal(' within '); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[3]).to.deep.equal(comp); | ||
}); | ||
it('should keep HTML entities in translation messages unescaped', function () { | ||
var t = (0, _src2.default)('This is a <__test__>.', { test: _react2.default.createElement('span', null, 'success') }); | ||
(0, _chai.expect)(t).to.be.an('array'); | ||
(0, _chai.expect)(t).to.have.length(3); | ||
(0, _chai.expect)(t[0]).to.equal('This is a <'); | ||
(0, _chai.expect)(t[2]).to.equal('>.'); | ||
var t = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is a <__test__>.', { | ||
test: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createElement('span', null, 'success') | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.be.an('array'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t).to.have.length(3); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[0]).to.equal('This is a <'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t[2]).to.equal('>.'); | ||
}); | ||
it('should keep original pattern for missing interpolations', function (done) { | ||
(0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('1 __interpolation__ 2')).to.equal('1 __interpolation__ 2'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('1 __interpolation__ 2')).to.equal('1 __interpolation__ 2'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should fallback to the translation key, if no translation was found.', function (done) { | ||
(0, _chai.expect)((0, _src2.default)('This is not translated')).to.equal('This is not translated'); | ||
(0, _src.setLocale)('de_DE'); | ||
(0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('This is not translated')).to.equal('This is not translated'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is not translated')).to.equal('This is not translated'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('de_DE'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('This is not translated')).to.equal('This is not translated'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should consider the context option, if provided', function (done) { | ||
(0, _src.setLocale)('de_DE'); | ||
(0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('Export')).to.equal('Exportiere'); | ||
(0, _chai.expect)((0, _src2.default)('Export', { context: 'button label' })).to.equal('Exportieren'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('de_DE'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('Export')).to.equal('Exportiere'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('Export', { | ||
context: 'button label' | ||
})).to.equal('Exportieren'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should use the translation key without any msgctxt, if no msgctxt is provided', function (done) { | ||
(0, _src.setLocale)('de_DE'); | ||
(0, _src.init)(getLangLoader, _config2.default).then(function () { | ||
(0, _chai.expect)((0, _src2.default)('Export')).to.equal('Exportiere'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["b" /* setLocale */])('de_DE'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["c" /* init */])(getLangLoader, __WEBPACK_IMPORTED_MODULE_4__config__["a" /* default */]).then(function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('Export')).to.equal('Exportiere'); | ||
done(); | ||
}).catch(done); | ||
}); | ||
it('should resolve plural', function () { | ||
var t1 = (0, _src2.default)('__count__ day', '__count__ days', { count: 0 }); | ||
var t2 = (0, _src2.default)('__count__ day', '__count__ days', { count: 2 }); | ||
var t3 = (0, _src2.default)('__count__ day', '__count__ days', { count: -2 }); | ||
(0, _chai.expect)(t1).to.be.a('string'); | ||
(0, _chai.expect)(t1).to.equal('0 days'); | ||
(0, _chai.expect)(t2).to.equal('2 days'); | ||
(0, _chai.expect)(t3).to.equal('-2 days'); | ||
var t1 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('__count__ day', '__count__ days', { | ||
count: 0 | ||
}); | ||
var t2 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('__count__ day', '__count__ days', { | ||
count: 2 | ||
}); | ||
var t3 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('__count__ day', '__count__ days', { | ||
count: -2 | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t1).to.be.a('string'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t1).to.equal('0 days'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t2).to.equal('2 days'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t3).to.equal('-2 days'); | ||
}); | ||
it('should resolve singular', function () { | ||
var t1 = (0, _src2.default)('__count__ case', '__count__ cases', { count: 1 }); | ||
var t2 = (0, _src2.default)('__count__ case', '__count__ cases', { count: -1 }); | ||
(0, _chai.expect)(t1).to.be.a('string'); | ||
(0, _chai.expect)(t1).to.equal('1 case'); | ||
(0, _chai.expect)(t2).to.equal('-1 case'); | ||
var t1 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('__count__ case', '__count__ cases', { | ||
count: 1 | ||
}); | ||
var t2 = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3__src__["d" /* default */])('__count__ case', '__count__ cases', { | ||
count: -1 | ||
}); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t1).to.be.a('string'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t1).to.equal('1 case'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai__["expect"])(t2).to.equal('-1 case'); | ||
}); | ||
@@ -859,35 +785,26 @@ }); | ||
/* 11 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_chai__ = __webpack_require__(0); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_chai___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_chai__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__src_scripts_config__ = __webpack_require__(7); | ||
var _chai = __webpack_require__(0); | ||
var _config = __webpack_require__(7); | ||
var _config2 = _interopRequireDefault(_config); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('config', function () { | ||
it('should load the next .i18nrc it finds while traversing its parents.', function () { | ||
var config = (0, _config2.default)('test/fixtures/i18nConfigDir/parent/child'); | ||
(0, _chai.expect)(config).to.have.property('key'); | ||
(0, _chai.expect)(config.key).to.equal('value'); | ||
var config = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__src_scripts_config__["a" /* default */])('test/fixtures/i18nConfigDir/parent/child'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config).to.have.property('key'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config.key).to.equal('value'); | ||
}); | ||
it('should find the config if the specified folder contains it.', function () { | ||
var config = (0, _config2.default)('test/fixtures/i18nConfigDir'); | ||
(0, _chai.expect)(config).to.have.property('key'); | ||
(0, _chai.expect)(config.key).to.equal('value'); | ||
var config = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__src_scripts_config__["a" /* default */])('test/fixtures/i18nConfigDir'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config).to.have.property('key'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config.key).to.equal('value'); | ||
}); | ||
it('should pickup babel configs', function () { | ||
var config = (0, _config2.default)('test/fixtures/i18nConfigDir'); | ||
(0, _chai.expect)(config).to.have.property('babel'); | ||
(0, _chai.expect)(config.babel).to.eql({ | ||
var config = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__src_scripts_config__["a" /* default */])('test/fixtures/i18nConfigDir'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config).to.have.property('babel'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0_chai__["expect"])(config.babel).to.eql({ | ||
plugins: ['transform-flow-strip-types'] | ||
@@ -900,24 +817,23 @@ }); | ||
/* 12 */ | ||
/***/ (function(module, exports, __webpack_require__) { | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_child_process__ = __webpack_require__(19); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_child_process___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_child_process__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_fs__ = __webpack_require__(1); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_fs___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_fs__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_chai_files__ = __webpack_require__(18); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_chai_files___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_chai_files__); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_chai__ = __webpack_require__(0); | ||
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_chai___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_chai__); | ||
var _child_process = __webpack_require__(19); | ||
var _child_process2 = _interopRequireDefault(_child_process); | ||
var _fs = __webpack_require__(1); | ||
var fixtureDir = "".concat(process.cwd(), "/test/fixtures"); | ||
var _chaiFiles = __webpack_require__(18); | ||
var _chai = __webpack_require__(0); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var fixtureDir = process.cwd() + '/test/fixtures'; | ||
var removeIfExists = function removeIfExists(fileName) { | ||
if ((0, _fs.existsSync)(fileName)) { | ||
(0, _fs.unlinkSync)(fileName); | ||
if (__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1_fs__["existsSync"])(fileName)) { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1_fs__["unlinkSync"])(fileName); | ||
} | ||
@@ -927,3 +843,3 @@ }; | ||
var callForDir = function callForDir(dirName) { | ||
_child_process2.default.execSync('node ' + process.cwd() + '/bin/i18n-extract.js "' + dirName + '/**/*.js"'); | ||
__WEBPACK_IMPORTED_MODULE_0_child_process___default.a.execSync("node ".concat(process.cwd(), "/bin/i18n-extract.js \"").concat(dirName, "/**/*.js\"")); | ||
}; | ||
@@ -933,157 +849,138 @@ | ||
describe('function name', function () { | ||
var customFunctionNameDir = fixtureDir + '/customFunctionName'; | ||
var customFunctionNameDir = "".concat(fixtureDir, "/customFunctionName"); | ||
afterEach(function () { | ||
removeIfExists(customFunctionNameDir + '/messages.pot'); | ||
removeIfExists("".concat(customFunctionNameDir, "/messages.pot")); | ||
}); | ||
it('should be possible to choose a custom function name', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(customFunctionNameDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(customFunctionNameDir, "/messages.pot"))).to.not.exist; | ||
callForDir(customFunctionNameDir); | ||
var messages = (0, _chaiFiles.file)(customFunctionNameDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('msgid "Hello World"'); | ||
(0, _chai.expect)(messages).to.not.contain('msgid "Not in the result"'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(customFunctionNameDir, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgid "Hello World"'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.not.contain('msgid "Not in the result"'); | ||
}); | ||
}); | ||
describe('file name', function () { | ||
var customFileNameDir = fixtureDir + '/customFileName'; | ||
var customFileNameDir = "".concat(fixtureDir, "/customFileName"); | ||
afterEach(function () { | ||
removeIfExists(customFileNameDir + '/my-custom-messages.pot'); | ||
removeIfExists("".concat(customFileNameDir, "/my-custom-messages.pot")); | ||
}); | ||
it('should be possible to specify an extract output file', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(customFileNameDir + '/my-custom-messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(customFileNameDir, "/my-custom-messages.pot"))).to.not.exist; | ||
callForDir(customFileNameDir); | ||
var messages = (0, _chaiFiles.file)(customFileNameDir + '/my-custom-messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('msgid "Hello World"'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(customFileNameDir, "/my-custom-messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgid "Hello World"'); | ||
}); | ||
}); | ||
describe('add location', function () { | ||
var addLocationDir = fixtureDir + '/addLocation'; | ||
var fullDir = addLocationDir + '/full'; | ||
var fileDir = addLocationDir + '/file'; | ||
var neverDir = addLocationDir + '/never'; | ||
var defaultDir = addLocationDir + '/default'; | ||
var addLocationDir = "".concat(fixtureDir, "/addLocation"); | ||
var fullDir = "".concat(addLocationDir, "/full"); | ||
var fileDir = "".concat(addLocationDir, "/file"); | ||
var neverDir = "".concat(addLocationDir, "/never"); | ||
var defaultDir = "".concat(addLocationDir, "/default"); | ||
afterEach(function () { | ||
removeIfExists(fullDir + '/messages.pot'); | ||
removeIfExists(fileDir + '/messages.pot'); | ||
removeIfExists(neverDir + '/messages.pot'); | ||
removeIfExists(defaultDir + '/messages.pot'); | ||
removeIfExists("".concat(fullDir, "/messages.pot")); | ||
removeIfExists("".concat(fileDir, "/messages.pot")); | ||
removeIfExists("".concat(neverDir, "/messages.pot")); | ||
removeIfExists("".concat(defaultDir, "/messages.pot")); | ||
}); | ||
it('should by default include the location where the message key was found', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(defaultDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(defaultDir, "/messages.pot"))).to.not.exist; | ||
callForDir(defaultDir); | ||
var messages = (0, _chaiFiles.file)(defaultDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('#: ' + defaultDir + '/index.js:1'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(defaultDir, "/messages.pot")); | ||
var referencePath = 'fixtures/addLocation/default'; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain("#: ".concat(referencePath, "/index.js:1")); | ||
}); | ||
it('should be possible to explicitly state that you want the full path', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(fullDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(fullDir, "/messages.pot"))).to.not.exist; | ||
callForDir(fullDir); | ||
var messages = (0, _chaiFiles.file)(fullDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('#: ' + fullDir + '/index.js:1'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(fullDir, "/messages.pot")); | ||
var referencePath = 'fixtures/addLocation/full'; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain("#: ".concat(referencePath, "/index.js:1")); | ||
}); | ||
it('should be possible to only include the file name', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(fileDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(fileDir, "/messages.pot"))).to.not.exist; | ||
callForDir(fileDir); | ||
var messages = (0, _chaiFiles.file)(fileDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('#: index.js:1'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(fileDir, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('#: index.js:1'); | ||
}); | ||
it('should be possible to never show the location', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(neverDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(neverDir, "/messages.pot"))).to.not.exist; | ||
callForDir(neverDir); | ||
var messages = (0, _chaiFiles.file)(neverDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.not.contain('#: ' + neverDir + '/index.js:1'); | ||
(0, _chai.expect)(messages).to.not.contain('#: index.js:1'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(neverDir, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.not.contain("#: ".concat(neverDir, "/index.js:1")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.not.contain('#: index.js:1'); | ||
}); | ||
}); | ||
describe('no location', function () { | ||
var noLocationDir = fixtureDir + '/noLocation'; | ||
var noLocationDir = "".concat(fixtureDir, "/noLocation"); | ||
afterEach(function () { | ||
removeIfExists(noLocationDir + '/messages.pot'); | ||
removeIfExists("".concat(noLocationDir, "/messages.pot")); | ||
}); | ||
it('should suppress locations in the .pot file completely', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(noLocationDir + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(noLocationDir, "/messages.pot"))).to.not.exist; | ||
callForDir(noLocationDir); | ||
var messages = (0, _chaiFiles.file)(noLocationDir + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.not.contain('#: ' + noLocationDir + '/index.js:1'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(noLocationDir, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.not.contain("#: ".concat(noLocationDir, "/index.js:1")); | ||
}); | ||
}); | ||
describe('message context', function () { | ||
var contextLocation = fixtureDir + '/messageContext'; | ||
var contextLocation = "".concat(fixtureDir, "/messageContext"); | ||
afterEach(function () { | ||
removeIfExists(contextLocation + '/messages.pot'); | ||
removeIfExists("".concat(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; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(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"'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(contextLocation, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgctxt "This is context for my message"'); | ||
}); | ||
}); | ||
describe('extracted comment', function () { | ||
var extractedCommentLocation = "".concat(fixtureDir, "/extractedComment"); | ||
afterEach(function () { | ||
removeIfExists("".concat(extractedCommentLocation, "/messages.pot")); | ||
}); | ||
it('should add the extracted comment correctly to the .pot file', function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(extractedCommentLocation, "/messages.pot"))).to.not.exist; | ||
callForDir(extractedCommentLocation); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(extractedCommentLocation, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('#. This is a comment for the translators'); | ||
}); | ||
}); | ||
describe('babel', function () { | ||
var flowLocation = fixtureDir + '/withFlowAnnotations'; | ||
var flowLocation = "".concat(fixtureDir, "/withFlowAnnotations"); | ||
afterEach(function () { | ||
removeIfExists(flowLocation + '/messages.pot'); | ||
removeIfExists("".concat(flowLocation, "/messages.pot")); | ||
}); | ||
it('should be possible to load extra plugins.', function () { | ||
(0, _chai.expect)((0, _chaiFiles.file)(flowLocation + '/messages.pot')).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(flowLocation, "/messages.pot"))).to.not.exist; | ||
callForDir(flowLocation); | ||
var messages = (0, _chaiFiles.file)(flowLocation + '/messages.pot'); | ||
(0, _chai.expect)(messages).to.exist; | ||
(0, _chai.expect)(messages).to.contain('msgid "I got extracted"'); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(flowLocation, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgid "I got extracted"'); | ||
}); | ||
}); | ||
describe.only('includes message from multiple files', function () { | ||
var multipleFilesLocaiton = "".concat(fixtureDir, "/multipleFiles"); | ||
afterEach(function () { | ||
removeIfExists("".concat(multipleFilesLocaiton, "/messages.pot")); | ||
}); | ||
it('should have message from two files', function () { | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(multipleFilesLocaiton, "/messages.pot"))).to.not.exist; | ||
callForDir(multipleFilesLocaiton); | ||
var messages = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_2_chai_files__["file"])("".concat(multipleFilesLocaiton, "/messages.pot")); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.not.exist; | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgid "Hello"'); | ||
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_3_chai__["expect"])(messages).to.contain('msgid "World"'); | ||
}); | ||
}); | ||
}); | ||
@@ -1157,3 +1054,3 @@ | ||
module.exports = require("babel-runtime/helpers/extends"); | ||
module.exports = require("@babel/runtime/helpers/objectSpread"); | ||
@@ -1164,3 +1061,3 @@ /***/ }), | ||
module.exports = require("babel-runtime/helpers/slicedToArray"); | ||
module.exports = require("@babel/runtime/helpers/slicedToArray"); | ||
@@ -1167,0 +1064,0 @@ /***/ }), |
@@ -70,10 +70,19 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread"; | ||
function getRelativePathName(_ref) { | ||
var filename = _ref.filename, | ||
root = _ref.root; | ||
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
// to remove first '/' as well | ||
var sourceFileName = filename.substr(root.length + 1); | ||
return sourceFileName.substr(0, base.length) === base ? sourceFileName.substr(base.length) : sourceFileName; | ||
} | ||
var currentWriteToFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
export default function plugin() { | ||
var currentFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
return { | ||
visitor: { | ||
VariableDeclaration: function VariableDeclaration(_ref) { | ||
var node = _ref.node; | ||
VariableDeclaration: function VariableDeclaration(_ref2) { | ||
var node = _ref2.node; | ||
var extractedComment = getExtractedComment(node); | ||
@@ -94,5 +103,5 @@ | ||
}, | ||
CallExpression: function CallExpression(_ref2, config) { | ||
var node = _ref2.node, | ||
parent = _ref2.parent; | ||
CallExpression: function CallExpression(_ref3, config) { | ||
var node = _ref3.node, | ||
parent = _ref3.parent; | ||
var _config$opts = config.opts, | ||
@@ -115,4 +124,4 @@ _config$opts$function = _config$opts.functionName, | ||
if (fileName !== currentFileName) { | ||
currentFileName = fileName; | ||
if (fileName !== currentWriteToFileName) { | ||
currentWriteToFileName = fileName; | ||
data = { | ||
@@ -159,11 +168,7 @@ charset: 'UTF-8', | ||
var fn = config.file.opts.filename; | ||
var sourceFileName = getRelativePathName(config.file.opts, base); | ||
if (base && fn && fn.substr(0, base.length) === base) { | ||
fn = fn.substr(base.length); | ||
} | ||
if (addLocation !== 'never' && !noLocation) { | ||
translate.comments = { | ||
reference: getReference(addLocation, fn, node) | ||
reference: getReference(addLocation, sourceFileName, node) | ||
}; | ||
@@ -170,0 +175,0 @@ } |
@@ -84,10 +84,20 @@ "use strict"; | ||
function getRelativePathName(_ref) { | ||
var filename = _ref.filename, | ||
root = _ref.root; | ||
var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
// to remove first '/' as well | ||
var sourceFileName = filename.substr(root.length + 1); | ||
return sourceFileName.substr(0, base.length) === base ? sourceFileName.substr(base.length) : sourceFileName; | ||
} | ||
var currentWriteToFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
function plugin() { | ||
var currentFileName; | ||
var data; | ||
var relocatedComments = {}; | ||
return { | ||
visitor: { | ||
VariableDeclaration: function VariableDeclaration(_ref) { | ||
var node = _ref.node; | ||
VariableDeclaration: function VariableDeclaration(_ref2) { | ||
var node = _ref2.node; | ||
var extractedComment = getExtractedComment(node); | ||
@@ -108,5 +118,5 @@ | ||
}, | ||
CallExpression: function CallExpression(_ref2, config) { | ||
var node = _ref2.node, | ||
parent = _ref2.parent; | ||
CallExpression: function CallExpression(_ref3, config) { | ||
var node = _ref3.node, | ||
parent = _ref3.parent; | ||
var _config$opts = config.opts, | ||
@@ -129,4 +139,4 @@ _config$opts$function = _config$opts.functionName, | ||
if (fileName !== currentFileName) { | ||
currentFileName = fileName; | ||
if (fileName !== currentWriteToFileName) { | ||
currentWriteToFileName = fileName; | ||
data = { | ||
@@ -173,11 +183,7 @@ charset: 'UTF-8', | ||
var fn = config.file.opts.filename; | ||
var sourceFileName = getRelativePathName(config.file.opts, base); | ||
if (base && fn && fn.substr(0, base.length) === base) { | ||
fn = fn.substr(base.length); | ||
} | ||
if (addLocation !== 'never' && !noLocation) { | ||
translate.comments = { | ||
reference: getReference(addLocation, fn, node) | ||
reference: getReference(addLocation, sourceFileName, node) | ||
}; | ||
@@ -184,0 +190,0 @@ } |
{ | ||
"name": "signavio-i18n", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Minimalist gettext style i18n for JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
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
9
5
517683
69
3183