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

@cerner/terra-aggregate-translations

Package Overview
Dependencies
Maintainers
7
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cerner/terra-aggregate-translations - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

4

lib/aggregate-messages.js
"use strict";
var path = require('path');
var chalk = require('chalk');
var aggregateTranslationMessages = function aggregateTranslationMessages(translationDirectories, locales, fileSystem) {

@@ -16,3 +14,2 @@ var translations = {};

var translationFile = path.resolve(dir, "".concat(language, ".json"));
try {

@@ -34,3 +31,2 @@ Object.assign(translations[language], JSON.parse(fileSystem.readFileSync(translationFile, 'utf8')));

};
module.exports = aggregateTranslationMessages;

41

lib/aggregate-translations.js
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var path = require('path');
var chalk = require('chalk');
var fse = require('fs-extra');
var glob = require('glob');
var supportedLocales = require('./config/i18nSupportedLocales');
var aggregateMessages = require('./aggregate-messages');
var writeAggregatedTranslations = require('./write-aggregated-translations');
var defaultSearchPatterns = require('./config/defaultSearchPatterns');
var isFile = function isFile(filePath) {
return fse.existsSync(filePath) && !fse.lstatSync(filePath).isDirectory();
};
var loadConfigFile = function loadConfigFile(configPath) {

@@ -32,5 +21,3 @@ if (configPath) {

}
var localPath = path.resolve(process.cwd(), 'terraI18n.config.js');
if (isFile(localPath)) {

@@ -40,6 +27,4 @@ // eslint-disable-next-line global-require, import/no-dynamic-require

}
return {};
};
var defaults = function defaults() {

@@ -57,9 +42,8 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

};
if (!defaultConfig.locales.includes('en')) {
defaultConfig.locales.push('en');
}
return defaultConfig;
};
/**

@@ -77,13 +61,10 @@ * Aggregates translation files and initializes the appropriate internationalization loaders.

*/
var aggregatedTranslations = function aggregatedTranslations(options) {
var _defaults = defaults(options),
baseDir = _defaults.baseDir,
directories = _defaults.directories,
fileSystem = _defaults.fileSystem,
locales = _defaults.locales,
outputDir = _defaults.outputDir,
excludes = _defaults.excludes;
baseDir = _defaults.baseDir,
directories = _defaults.directories,
fileSystem = _defaults.fileSystem,
locales = _defaults.locales,
outputDir = _defaults.outputDir,
excludes = _defaults.excludes;
var searchPaths = [].concat((0, _toConsumableArray2.default)(defaultSearchPatterns), (0, _toConsumableArray2.default)(directories));

@@ -101,13 +82,13 @@ var translationDirectories = [];

/* eslint-disable-next-line no-console */
console.log(chalk.grey("".concat(context, " Aggregating translations for ").concat(localesText, " locales.")));
console.log(chalk.grey("".concat(context, " Aggregating translations for ").concat(localesText, " locales."))); // Aggregate translation messages for each of the translations directories
// Aggregate translation messages for each of the translations directories
var aggregatedMessages = aggregateMessages(translationDirectories, locales, fileSystem);
var outputDirectory = path.resolve(baseDir, outputDir);
fileSystem.mkdirpSync(outputDirectory); // Write aggregated translation messages to a file for each locale
fileSystem.mkdirpSync(outputDirectory);
// Write aggregated translation messages to a file for each locale
writeAggregatedTranslations(aggregatedMessages, locales, fileSystem, outputDirectory);
return locales;
};
module.exports = aggregatedTranslations;
"use strict";
var defaultSearchPatterns = [
/* root level dependency translations up to three levels deep */
'node_modules/*/node_modules/*/node_modules/*/translations', 'node_modules/*/node_modules/*/translations', 'node_modules/*/translations', 'node_modules/@cerner/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'node_modules/@cerner/*/node_modules/@cerner/*/translations', 'node_modules/@cerner/*/translations',
/* root level translations */
'translations',
/* package level dependency translations up to three levels deep */
'packages/*/node_modules/*/node_modules/*/node_modules/*/translations', 'packages/*/node_modules/*/node_modules/*/translations', 'packages/*/node_modules/*/translations', 'packages/*/node_modules/@cerner/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'packages/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'packages/*/node_modules/@cerner/*/translations',
/* package level translations */
var defaultSearchPatterns = [/* root level dependency translations up to three levels deep */
'node_modules/*/node_modules/*/node_modules/*/translations', 'node_modules/*/node_modules/*/translations', 'node_modules/*/translations', 'node_modules/@cerner/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'node_modules/@cerner/*/node_modules/@cerner/*/translations', 'node_modules/@cerner/*/translations', /* root level translations */
'translations', /* package level dependency translations up to three levels deep */
'packages/*/node_modules/*/node_modules/*/node_modules/*/translations', 'packages/*/node_modules/*/node_modules/*/translations', 'packages/*/node_modules/*/translations', 'packages/*/node_modules/@cerner/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'packages/*/node_modules/@cerner/*/node_modules/@cerner/*/translations', 'packages/*/node_modules/@cerner/*/translations', /* package level translations */
'packages/terra-*/translations'];
module.exports = defaultSearchPatterns;

@@ -7,7 +7,5 @@ "use strict";

var lowerB = b.toLowerCase();
if (lowerA === lowerB) {
return 0;
}
return lowerA < lowerB ? -1 : 1;

@@ -22,7 +20,5 @@ });

};
var translationFile = function translationFile(messages) {
return "'use strict';\n\n Object.defineProperty(exports, \"__esModule\", {\n value: true\n });\n exports.default = void 0;\n\n var _default = ".concat(JSON.stringify(messages, null, 2), ";\n exports.default = _default;\n");
};
var generateTranslationFile = function generateTranslationFile(messages) {

@@ -32,3 +28,2 @@ var sortedMessages = sortMessages(messages);

};
module.exports = generateTranslationFile;
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var path = require('path');
var chalk = require('chalk');
var supportedLocales = require('./config/i18nSupportedLocales');
var generateTranslationFile = require('./generate-translation-file');
var writeAggregatedTranslations = function writeAggregatedTranslations(aggregatedMessages, locales, fileSystem, outputDir) {

@@ -29,16 +20,11 @@ // Create a file of aggregated translation messages for each locale

}
var translationFilePath = path.resolve(outputDir, "".concat(locale, ".js"));
var messages = aggregatedMessages[locale];
var _locale$split = locale.split('-'),
_locale$split2 = (0, _slicedToArray2.default)(_locale$split, 2),
baseLocale = _locale$split2[0],
region = _locale$split2[1];
_locale$split2 = (0, _slicedToArray2.default)(_locale$split, 2),
baseLocale = _locale$split2[0],
region = _locale$split2[1];
var mergedMessages = messages;
if (region) {
var baseLocaleMessages = aggregatedMessages[baseLocale];
if (baseLocaleMessages) {

@@ -49,3 +35,2 @@ // Merge base locale messages into regional locale messages, regional locale messages listed last so they will take precedence.

}
fileSystem.writeFileSync(translationFilePath, generateTranslationFile(mergedMessages));

@@ -57,3 +42,2 @@ } else {

};
module.exports = writeAggregatedTranslations;
"use strict";
var path = require('path');
var chalk = require('chalk');
var startCase = require('lodash.startcase');
var supportedLocales = require('./config/i18nSupportedLocales');
var createIntlLoader = function createIntlLoader(loaderName, locale, format) {

@@ -15,6 +11,4 @@ if (format === 'es6') {

}
return "var ".concat(loaderName, " = function ").concat(loaderName, "() {\n return require.ensure([], function (require) {\n return require('intl/locale-data/jsonp/").concat(locale, ".js');\n }, '").concat(locale, "-intl-local');\n};\n\n");
};
var createTranslationLoader = function createTranslationLoader(loaderName, locale, format) {

@@ -24,10 +18,9 @@ if (format === 'es6') {

}
return "var ".concat(loaderName, " = function ").concat(loaderName, "(callback, scope) {\n return require.ensure([], function (require) {\n // eslint-disable-next-line\n var i18n = require('./").concat(locale, ".js');\n callback.call(scope, i18n);\n return i18n;\n }, '").concat(locale, "-translations');\n};\n\n");
};
var writeLoaders = function writeLoaders(type, locales, fileSystem, outputDir, format) {
var loaders = {};
var loaderFile = "'use strict';\n\n"; // Create the intl and translations loaders for each locale
var loaderFile = "'use strict';\n\n";
// Create the intl and translations loaders for each locale
locales.forEach(function (locale) {

@@ -38,7 +31,5 @@ if (type === 'intl' && !supportedLocales.includes(locale)) {

}
var localeLoaderName = startCase(locale).replace(' ', '');
var loaderName = "load".concat(localeLoaderName).concat(startCase(type));
loaders["'".concat(locale, "'")] = loaderName;
if (type === 'intl') {

@@ -49,11 +40,12 @@ loaderFile += createIntlLoader(loaderName, locale, format);

}
}); // Create the loader exports
});
// Create the loader exports
var loaderString = JSON.stringify(loaders, null, 2).replace(/"/g, '');
loaderFile += "var ".concat(type, "Loaders = ").concat(loaderString, ";\n\nmodule.exports = ").concat(type, "Loaders;"); // Write the loaders file
loaderFile += "var ".concat(type, "Loaders = ").concat(loaderString, ";\n\nmodule.exports = ").concat(type, "Loaders;");
// Write the loaders file
var loaderPath = path.resolve(outputDir, "".concat(type, "Loaders.js"));
fileSystem.writeFileSync(loaderPath, loaderFile);
};
var writeI18nLoaders = function writeI18nLoaders(locales, fileSystem, outputDir, format) {

@@ -63,3 +55,2 @@ writeLoaders('intl', locales, fileSystem, outputDir, format);

};
module.exports = writeI18nLoaders;
{
"name": "@cerner/terra-aggregate-translations",
"version": "3.0.0",
"version": "3.1.0",
"description": "The terra-aggregate-translations pre-build tool assists with creating the translation, intl loader and translation loader files that are configured for the specified locales. This tool is offered as a CLI script and as a setup function.",

@@ -9,3 +9,4 @@ "publishConfig": {

"engines": {
"node": ">=10"
"node": "10|| 12 || 14",
"npm": "6 || 9"
},

@@ -42,7 +43,11 @@ "repository": {

"scripts": {
"clean:install": "npm run clean && npm install",
"clean": "npm run clean:node_modules && npm run clean:lib",
"clean:lib": "rm -rf lib",
"clean:node_modules": "echo 'removing ./node_modules' && rm -rf node_modules && echo 'removed ./node_modules'",
"clean:install": "npm run clean && time npm install",
"compile": "babel --root-mode upward src --out-dir lib --copy-files",
"jest": "jest --config ../../jest.config.js",
"jest": "jest",
"lint": "eslint --ext .js,.jsx . --ignore-path ../../.eslintignore",
"precompile": "rm -rf lib",
"lint:js:fix": "eslint --ext .js,.jsx . --fix --ignore-path ../../.eslintignore",
"postinstall": "npm run compile",
"test": "npm run lint && npm run jest"

@@ -57,2 +62,10 @@ },

},
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.1",
"@cerner/eslint-config-terra": "^5.5.0",
"@cerner/jest-config-terra": "^1.6.0",
"eslint": "^7.32.0",
"jest": "26.6.3"
},
"peerDependencies": {

@@ -62,3 +75,3 @@ "intl": "^1.2.5",

},
"gitHead": "61b9c61732414b3cccfa7b62a36d604c95c3b4f8"
"gitHead": "7a663be7b6cc6aff73f9af7ee9e5f850adfccd60"
}
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