Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18next-scanner

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18next-scanner - npm Package Compare versions

Comparing version 2.6.3 to 2.6.4

109

lib/parser.js

@@ -336,2 +336,3 @@ 'use strict';

}
// i18next.t('ns:foo.bar') // matched

@@ -468,2 +469,3 @@ // i18next.t("ns:foo.bar") // matched

}
// Parses translation keys from `Trans` components in JSX

@@ -489,58 +491,77 @@ // <Trans i18nKey="some.key">Default text</Trans>

try {
(0, _acornJsxWalk2.default)(content, {
JSXElement: function JSXElement(node) {
if (node.openingElement.name.name !== component) {
return;
}
var parseJSXElement = function parseJSXElement(node) {
if (!node) {
return;
}
var attr = (0, _ensureArray2.default)(node.openingElement.attributes).reduce(function (acc, attribute) {
if (attribute.type !== 'JSXAttribute' || attribute.name.type !== 'JSXIdentifier') {
return acc;
}
(0, _ensureArray2.default)(node.openingElement.attributes).forEach(function (attribute) {
var value = attribute.value;
var name = attribute.name.name;
if (!(value && value.type === 'JSXExpressionContainer')) {
return;
}
var expression = value.expression;
if (!(expression && expression.type === 'JSXElement')) {
return;
}
if (attribute.value.type === 'Literal') {
acc[name] = attribute.value.value;
} else if (attribute.value.type === 'JSXExpressionContainer') {
acc[name] = attribute.value.expression;
}
parseJSXElement(expression);
});
return acc;
}, {});
if (node.openingElement.name.name !== component) {
return;
}
var transKey = _lodash2.default.trim(attr[i18nKey]);
var attr = (0, _ensureArray2.default)(node.openingElement.attributes).reduce(function (acc, attribute) {
if (attribute.type !== 'JSXAttribute' || attribute.name.type !== 'JSXIdentifier') {
return acc;
}
var defaultsString = attr[defaultsKey] || '';
if (typeof defaultsString !== 'string') {
_this3.log('i18next-scanner: defaults value must be a static string, saw ' + _chalk2.default.yellow(defaultsString));
}
var name = attribute.name.name;
var options = {
defaultValue: defaultsString || (0, _nodesToString2.default)(node.children),
fallbackKey: opts.fallbackKey || _this3.options.trans.fallbackKey
};
if (Object.prototype.hasOwnProperty.call(attr, 'count')) {
options.count = Number(attr.count) || 0;
}
if (attribute.value.type === 'Literal') {
acc[name] = attribute.value.value;
} else if (attribute.value.type === 'JSXExpressionContainer') {
acc[name] = attribute.value.expression;
}
if (Object.prototype.hasOwnProperty.call(attr, 'context')) {
options.context = attr.context;
return acc;
}, {});
if (typeof options.context !== 'string') {
_this3.log('i18next-scanner: The context attribute must be a string, saw ' + _chalk2.default.yellow(attr.context));
}
}
var transKey = _lodash2.default.trim(attr[i18nKey]);
if (customHandler) {
customHandler(transKey, options);
return;
}
var defaultsString = attr[defaultsKey] || '';
if (typeof defaultsString !== 'string') {
_this3.log('i18next-scanner: defaults value must be a static string, saw ' + _chalk2.default.yellow(defaultsString));
}
_this3.set(transKey, options);
var options = {
defaultValue: defaultsString || (0, _nodesToString2.default)(node.children),
fallbackKey: opts.fallbackKey || _this3.options.trans.fallbackKey
};
if (Object.prototype.hasOwnProperty.call(attr, 'count')) {
options.count = Number(attr.count) || 0;
}
if (Object.prototype.hasOwnProperty.call(attr, 'context')) {
options.context = attr.context;
if (typeof options.context !== 'string') {
_this3.log('i18next-scanner: The context attribute must be a string, saw ' + _chalk2.default.yellow(attr.context));
}
});
}
if (customHandler) {
customHandler(transKey, options);
return;
}
_this3.set(transKey, options);
};
try {
(0, _acornJsxWalk2.default)(content, { JSXElement: parseJSXElement });
} catch (err) {

@@ -554,2 +575,3 @@ this.log('i18next-scanner: Unable to parse ' + component + ' component with the content');

}
// Parses translation keys from `data-i18n` attribute in HTML

@@ -621,2 +643,3 @@ // <div data-i18n="[attr]ns:foo.bar;[attr]ns:foo.baz">

}
// Get the value of a translation key or the whole resource store containing translation information

@@ -711,2 +734,3 @@ // @param {string} [key] The translation key

}
// Set translation key with an optional defaultValue to i18n resource store

@@ -900,2 +924,3 @@ // @param {string} key The translation key

}
// Returns a JSON string containing translation information

@@ -902,0 +927,0 @@ // @param {object} [options] The options object

{
"name": "i18next-scanner",
"version": "2.6.3",
"version": "2.6.4",
"description": "Scan your code, extract translation keys/values, and merge them into i18n resource files.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/i18next/i18next-scanner",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc