i18next-parser
Advanced tools
Comparing version 5.1.0 to 5.2.0
@@ -121,3 +121,3 @@ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports.dotPathToHash = dotPathToHash;exports.getPluralSuffixPosition = getPluralSuffixPosition;exports.getSingularForm = getSingularForm;exports.hasRelatedPluralKey = hasRelatedPluralKey;exports.makeDefaultSort = makeDefaultSort;exports.mergeHashes = mergeHashes;exports.transferValues = transferValues;var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); /** | ||
* hash has the corresponding key (or if `options.keepRemoved` is true). | ||
* @returns An `{ old, new, mergeCount, pullCount, oldCount }` object. | ||
* @returns An `{ old, new, mergeCount, pullCount, oldCount, reset, resetCount }` object. | ||
* `old` is a hash of values that have not been merged into `target`. | ||
@@ -128,9 +128,12 @@ * `new` is `target`. `mergeCount` is the number of keys merged into | ||
* `new` (if `options.keepRemoved` is true and `target` didn't have the corresponding | ||
* key). | ||
* key) and `reset` is the keys that were reset due to not matching default values, | ||
* and `resetCount` which is the number of keys reset. | ||
*/ | ||
function mergeHashes(source, target) {var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
function mergeHashes(source, target) {var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};var resetValues = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
var old = {}; | ||
var reset = {}; | ||
var mergeCount = 0; | ||
var pullCount = 0; | ||
var oldCount = 0; | ||
var resetCount = 0; | ||
@@ -153,8 +156,21 @@ var keepRemoved = options.keepRemoved || false; | ||
} else if (target[key] !== undefined) { | ||
if (typeof source[key] === 'string' || Array.isArray(source[key])) { | ||
target[key] = source[key]; | ||
mergeCount += 1; | ||
} else { | ||
if (typeof source[key] !== 'string' && !Array.isArray(source[key])) { | ||
old[key] = source[key]; | ||
oldCount += 1; | ||
} else { | ||
if ( | ||
options.resetAndFlag && | ||
!isPlural(key) && | ||
typeof source[key] === 'string' && | ||
source[key] !== target[key] || | ||
resetValues[key]) | ||
{ | ||
old[key] = source[key]; | ||
oldCount += 1; | ||
reset[key] = true; | ||
resetCount += 1; | ||
} else { | ||
target[key] = source[key]; | ||
mergeCount += 1; | ||
} | ||
} | ||
@@ -189,3 +205,11 @@ } else { | ||
return { old: old, "new": target, mergeCount: mergeCount, pullCount: pullCount, oldCount: oldCount }; | ||
return { | ||
old: old, | ||
"new": target, | ||
mergeCount: mergeCount, | ||
pullCount: pullCount, | ||
oldCount: oldCount, | ||
reset: reset, | ||
resetCount: resetCount }; | ||
} | ||
@@ -212,5 +236,12 @@ | ||
var pluralSuffixes = ['zero', 'one', 'two', 'few', 'many', 'other']; | ||
function isPlural(key) { | ||
return pluralSuffixes.some(function (suffix) {return key.endsWith(suffix);}); | ||
} | ||
function hasRelatedPluralKey(rawKey, source) { | ||
var suffixes = ['zero', 'one', 'two', 'few', 'many', 'other']; | ||
return suffixes.some(function (suffix) {return source["".concat(rawKey).concat(suffix)] !== undefined;}); | ||
return pluralSuffixes.some( | ||
function (suffix) {return source["".concat(rawKey).concat(suffix)] !== undefined;}); | ||
} | ||
@@ -227,6 +258,4 @@ | ||
function getPluralSuffixPosition(key) { | ||
var suffixes = ['zero', 'one', 'two', 'few', 'many', 'other']; | ||
for (var i = 0, len = suffixes.length; i < len; i++) { | ||
if (key.endsWith(suffixes[i])) return i; | ||
for (var i = 0, len = pluralSuffixes.length; i < len; i++) { | ||
if (key.endsWith(pluralSuffixes[i])) return i; | ||
} | ||
@@ -233,0 +262,0 @@ |
@@ -36,2 +36,3 @@ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports, "__esModule", { value: true });exports["default"] = void 0;var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _helpers = require("./helpers"); | ||
output: 'locales/$LOCALE/$NAMESPACE.json', | ||
resetDefaultValueLocale: null, | ||
sort: false, | ||
@@ -129,5 +130,17 @@ useKeysAsDefaultValue: false, | ||
function _flush(done) {var _this2 = this;var _iterator2 = _createForOfIteratorHelper( | ||
this.options.locales),_step2;try {var _loop = function _loop() {var locale = _step2.value; | ||
function _flush(done) {var _this2 = this; | ||
var maybeSortedLocales = this.options.locales; | ||
if (this.options.resetDefaultValueLocale) { | ||
// ensure we process the reset locale first | ||
maybeSortedLocales.sort(function (a) {return ( | ||
a === _this2.options.resetDefaultValueLocale ? -1 : 1);}); | ||
} | ||
// Tracks keys to reset by namespace | ||
var resetValues = {};var _iterator2 = _createForOfIteratorHelper( | ||
maybeSortedLocales),_step2;try {var _loop = function _loop() {var locale = _step2.value; | ||
var catalog = {}; | ||
var resetAndFlag = _this2.options.resetDefaultValueLocale === locale; | ||
@@ -199,4 +212,20 @@ var countWithPlurals = 0; | ||
(0, _helpers.mergeHashes)(existingCatalog, catalog[namespace], _this2.options),newCatalog = _mergeHashes["new"],oldKeys = _mergeHashes.old,mergeCount = _mergeHashes.mergeCount,oldCount = _mergeHashes.oldCount; | ||
(0, _helpers.mergeHashes)( | ||
existingCatalog, | ||
catalog[namespace], _objectSpread(_objectSpread({}, | ||
_this2.options), {}, { | ||
resetAndFlag: resetAndFlag }), | ||
resetValues[namespace]),newCatalog = _mergeHashes["new"],oldKeys = _mergeHashes.old,mergeCount = _mergeHashes.mergeCount,oldCount = _mergeHashes.oldCount,resetFlags = _mergeHashes.reset,resetCount = _mergeHashes.resetCount; | ||
// record values to be reset | ||
// assumes that the 'default' namespace is processed first | ||
if (resetAndFlag && !resetValues[namespace]) { | ||
resetValues[namespace] = resetFlags; | ||
} | ||
// restore old translations | ||
@@ -225,2 +254,5 @@ var _mergeHashes2 = (0, _helpers.mergeHashes)( | ||
} | ||
if (_this2.options.resetDefaultValueLocale) { | ||
console.log("Reset keys: ".concat(resetCount)); | ||
} | ||
console.log(); | ||
@@ -227,0 +259,0 @@ } |
{ | ||
"name": "i18next-parser", | ||
"description": "Command Line tool for i18next", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"license": "MIT", | ||
@@ -66,3 +66,3 @@ "author": "Karel Ledru", | ||
"prettier": "2.4.1", | ||
"sinon": "^11.1.1" | ||
"sinon": "^12.0.1" | ||
}, | ||
@@ -69,0 +69,0 @@ "repository": { |
@@ -203,3 +203,3 @@ # i18next Parser [![Build Status](https://travis-ci.org/i18next/i18next-parser.svg?branch=master)](https://travis-ci.org/i18next/i18next-parser) [![codecov](https://codecov.io/gh/i18next/i18next-parser/branch/master/graph/badge.svg?token=CJ74Vps41L)](https://codecov.io/gh/i18next/i18next-parser) | ||
customValueTemplate: null | ||
customValueTemplate: null, | ||
// If you wish to customize the value output the value as an object, you can set your own format. | ||
@@ -214,2 +214,8 @@ // ${defaultValue} is the default value you set in your translation function. | ||
// } | ||
resetDefaultValueLocale: null | ||
// The locale to compare with default values to determine whether a default value has been changed. | ||
// If this is set and a default value differs from a translation in the specified locale, all entries | ||
// for that key across locales are reset to the default value, and existing translations are moved to | ||
// the `_old` file. | ||
} | ||
@@ -216,0 +222,0 @@ ``` |
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
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
103666
1476
391
0