Socket
Socket
Sign inDemoInstall

@lingui/cli

Package Overview
Dependencies
Maintainers
3
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lingui/cli - npm Package Compare versions

Comparing version 3.17.0 to 3.17.1

206

build/api/catalog.js

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

});
exports.getCatalogs = getCatalogs;
exports.cleanObsolete = exports.Catalog = void 0;
exports.getCatalogForFile = getCatalogForFile;
exports.getCatalogForMerge = getCatalogForMerge;
exports.getCatalogs = getCatalogs;
exports.normalizeRelativePath = normalizeRelativePath;

@@ -14,32 +15,16 @@ exports.order = order;

exports.orderByOrigin = orderByOrigin;
exports.cleanObsolete = exports.Catalog = void 0;
var _os = _interopRequireDefault(require("os"));
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _path = _interopRequireDefault(require("path"));
var R = _interopRequireWildcard(require("ramda"));
var _chalk = _interopRequireDefault(require("chalk"));
var _glob = _interopRequireDefault(require("glob"));
var _micromatch = _interopRequireDefault(require("micromatch"));
var _normalizePath = _interopRequireDefault(require("normalize-path"));
var _formats = _interopRequireDefault(require("./formats"));
var _extractors = _interopRequireDefault(require("./extractors"));
var _utils = require("./utils");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const NAME = "{name}";

@@ -66,3 +51,2 @@ const NAME_REPLACE_RE = /{name}/g;

}
async make(options) {

@@ -75,9 +59,11 @@ const nextCatalog = await this.collect(options);

files: options.files
}); // Map over all locales and post-process each catalog
});
const cleanAndSort = R.map(R.pipe( // Clean obsolete messages
options.clean ? cleanObsolete : R.identity, // Sort messages
// Map over all locales and post-process each catalog
const cleanAndSort = R.map(R.pipe(
// Clean obsolete messages
options.clean ? cleanObsolete : R.identity,
// Sort messages
order(options.orderBy)));
const sortedCatalogs = cleanAndSort(catalogs);
if (options.locale) {

@@ -88,6 +74,4 @@ this.write(options.locale, sortedCatalogs[options.locale]);

}
return true;
}
async makeTemplate(options) {

@@ -100,10 +84,8 @@ const catalog = await this.collect(options);

}
/**
* Collect messages from source paths. Return a raw message catalog as JSON.
*/
async collect(options) {
const tmpDir = _path.default.join(_os.default.tmpdir(), `lingui-${process.pid}`);
if (_fsExtra.default.existsSync(tmpDir)) {

@@ -114,6 +96,4 @@ (0, _utils.removeDirectory)(tmpDir, true);

}
try {
let paths = this.sourcePaths;
if (options.files) {

@@ -124,5 +104,3 @@ options.files = options.files.map(p => (0, _normalizePath.default)(p, false));

}
let catalogSuccess = true;
for (let filename of paths) {

@@ -138,3 +116,2 @@ const fileSuccess = await (0, _extractors.default)(filename, tmpDir, {

}
if (!catalogSuccess) return undefined;

@@ -144,9 +121,6 @@ return function traverse(directory) {

const filepath = _path.default.join(directory, filename);
if (_fsExtra.default.lstatSync(filepath).isDirectory()) {
return traverse(filepath);
}
if (!filename.endsWith(".json")) return;
try {

@@ -163,3 +137,2 @@ return JSON.parse(_fsExtra.default.readFileSync(filepath).toString());

}
merge(prevCatalogs, nextCatalog, options) {

@@ -171,9 +144,11 @@ const nextKeys = R.keys(nextCatalog).map(String);

const mergeKeys = R.intersection(nextKeys, prevKeys);
const obsoleteKeys = R.difference(prevKeys, nextKeys); // Initialize new catalog with new keys
const obsoleteKeys = R.difference(prevKeys, nextKeys);
// Initialize new catalog with new keys
const newMessages = R.mapObjIndexed((message, key) => ({
translation: this.config.sourceLocale === locale ? message.message || key : "",
...message
}), R.pick(newKeys, nextCatalog)); // Merge translations from previous catalog
}), R.pick(newKeys, nextCatalog));
// Merge translations from previous catalog
const mergedMessages = mergeKeys.map(key => {

@@ -188,7 +163,9 @@ const updateFromDefaults = this.config.sourceLocale === locale && (prevCatalog[key].translation === prevCatalog[key].message || options.overwrite);

};
}); // Mark all remaining translations as obsolete
});
// Mark all remaining translations as obsolete
// Only if *options.files* is not provided
const obsoleteMessages = obsoleteKeys.map(key => ({
[key]: { ...prevCatalog[key],
[key]: {
...prevCatalog[key],
obsolete: options.files ? false : true

@@ -200,11 +177,10 @@ }

}
getTranslations(locale, options) {
const catalogs = this.readAll();
const template = this.readTemplate() || {};
return R.mapObjIndexed((_value, key) => this.getTranslation(catalogs, locale, key, options), { ...template,
return R.mapObjIndexed((_value, key) => this.getTranslation(catalogs, locale, key, options), {
...template,
...catalogs[locale]
});
}
getTranslation(catalogs, locale, key, {

@@ -214,12 +190,7 @@ fallbackLocales,

}) {
var _catalog$key;
const catalog = catalogs[locale] || {};
if (!catalog.hasOwnProperty(key)) {
console.error(`Message with key ${key} is missing in locale ${locale}`);
}
const getTranslation = _locale => {
const configLocales = this.config.locales.join('", "');
const localeCatalog = catalogs[_locale] || {};
if (!localeCatalog) {

@@ -235,20 +206,15 @@ console.warn(`

}
if (!localeCatalog.hasOwnProperty(key)) {
console.error(`Message with key ${key} is missing in locale ${_locale}`);
return null;
}
if (catalogs[_locale]) {
return catalogs[_locale][key].translation;
}
return null;
};
const getMultipleFallbacks = _locale => {
const fL = fallbackLocales && fallbackLocales[_locale]; // some probably the fallback will be undefined, so just search by locale
const fL = fallbackLocales && fallbackLocales[_locale];
// some probably the fallback will be undefined, so just search by locale
if (!fL) return null;
if (Array.isArray(fL)) {

@@ -264,24 +230,25 @@ for (const fallbackLocale of fL) {

};
return (// Get translation in target locale
getTranslation(locale) || // We search in fallbackLocales as dependent of each locale
getMultipleFallbacks(locale) || // Get translation in fallbackLocales.default (if any)
fallbackLocales?.default && getTranslation(fallbackLocales.default) || // Get message default
catalog[key]?.defaults || // If sourceLocale is either target locale of fallback one, use key
sourceLocale && sourceLocale === locale && key || sourceLocale && fallbackLocales?.default && sourceLocale === fallbackLocales.default && key || // Otherwise no translation is available
return (
// Get translation in target locale
getTranslation(locale) ||
// We search in fallbackLocales as dependent of each locale
getMultipleFallbacks(locale) ||
// Get translation in fallbackLocales.default (if any)
(fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default) && getTranslation(fallbackLocales.default) || ( // Get message default
(_catalog$key = catalog[key]) === null || _catalog$key === void 0 ? void 0 : _catalog$key.defaults) ||
// If sourceLocale is either target locale of fallback one, use key
sourceLocale && sourceLocale === locale && key || sourceLocale && (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales.default) && sourceLocale === fallbackLocales.default && key ||
// Otherwise no translation is available
undefined
);
}
write(locale, messages) {
const filename = this.path.replace(LOCALE_REPLACE_RE, locale) + this.format.catalogExtension;
const created = !_fsExtra.default.existsSync(filename);
const basedir = _path.default.dirname(filename);
if (!_fsExtra.default.existsSync(basedir)) {
_fsExtra.default.mkdirpSync(basedir);
}
const options = { ...this.config.formatOptions,
const options = {
...this.config.formatOptions,
locale

@@ -292,17 +259,13 @@ };

}
writeAll(catalogs) {
this.locales.forEach(locale => this.write(locale, catalogs[locale]));
}
writeTemplate(messages) {
const filename = this.templateFile;
const basedir = _path.default.dirname(filename);
if (!_fsExtra.default.existsSync(basedir)) {
_fsExtra.default.mkdirpSync(basedir);
}
const options = { ...this.config.formatOptions,
const options = {
...this.config.formatOptions,
locale: undefined

@@ -312,6 +275,4 @@ };

}
writeCompiled(locale, compiledCatalog, namespace) {
let ext;
if (namespace === "es") {

@@ -324,16 +285,10 @@ ext = "mjs";

}
const filename = `${this.path.replace(LOCALE_REPLACE_RE, locale)}.${ext}`;
const basedir = _path.default.dirname(filename);
if (!_fsExtra.default.existsSync(basedir)) {
_fsExtra.default.mkdirpSync(basedir);
}
_fsExtra.default.writeFileSync(filename, compiledCatalog);
return filename;
}
read(locale) {

@@ -344,3 +299,2 @@ const filename = this.path.replace(LOCALE_REPLACE_RE, locale) + this.format.catalogExtension;

}
readAll() {

@@ -351,3 +305,2 @@ return R.mergeAll(this.locales.map(locale => ({

}
readTemplate() {

@@ -358,3 +311,2 @@ const filename = this.templateFile;

}
get sourcePaths() {

@@ -367,4 +319,2 @@ const includeGlobs = this.include.map(includePath => {

*/
return isDir ? (0, _normalizePath.default)(_path.default.resolve(process.cwd(), includePath === "/" ? "" : includePath, "**/*.*")) : includePath;

@@ -378,29 +328,21 @@ });

}
get templateFile() {
return this.path.replace(LOCALE_SUFFIX_RE, "messages.pot");
}
get localeDir() {
const localePatternIndex = this.path.indexOf(LOCALE);
if (localePatternIndex === -1) {
throw Error(`Invalid catalog path: ${LOCALE} variable is missing`);
}
return this.path.substr(0, localePatternIndex);
}
get locales() {
return this.config.locales;
}
}
}
/**
* Parse `config.catalogs` and return a list of configured Catalog instances.
*/
exports.Catalog = Catalog;
function getCatalogs(config) {

@@ -414,21 +356,22 @@ const catalogsConfig = config.catalogs;

const correctPath = catalog.path.slice(0, -1);
const examplePath = correctPath.replace(LOCALE_REPLACE_RE, // Show example using one of configured locales (if any)
const examplePath = correctPath.replace(LOCALE_REPLACE_RE,
// Show example using one of configured locales (if any)
(config.locales || [])[0] || "en") + extension;
throw new Error( // prettier-ignore
throw new Error(
// prettier-ignore
`Remove trailing slash from "${catalog.path}". Catalog path isn't a directory,` + ` but translation file without extension. For example, catalog path "${correctPath}"` + ` results in translation file "${examplePath}".`);
}
const include = ensureArray(catalog.include).map(normalizeRelativePath);
const exclude = ensureArray(catalog.exclude).map(normalizeRelativePath); // catalog.path without {name} pattern -> always refers to a single catalog
const exclude = ensureArray(catalog.exclude).map(normalizeRelativePath);
// catalog.path without {name} pattern -> always refers to a single catalog
if (!catalog.path.includes(NAME)) {
// Validate that sourcePaths doesn't use {name} pattern either
const invalidSource = include.find(path => path.includes(NAME));
if (invalidSource !== undefined) {
throw new Error(`Catalog with path "${catalog.path}" doesn't have a {name} pattern` + ` in it, but one of source directories uses it: "${invalidSource}".` + ` Either add {name} pattern to "${catalog.path}" or remove it` + ` from all source directories.`);
} // catalog name is the last directory of catalog.path.
}
// catalog name is the last directory of catalog.path.
// If the last part is {locale}, then catalog doesn't have an explicit name
const name = function () {

@@ -438,3 +381,2 @@ const _name = catalog.path.split(PATHSEP).slice(-1)[0];

}();
catalogs.push(new Catalog({

@@ -448,5 +390,3 @@ name,

}
const patterns = include.map(path => path.replace(NAME_REPLACE_RE, "*"));
const candidates = _glob.default.sync(patterns.length > 1 ? `{${patterns.join(",")}}` : patterns[0], {

@@ -456,6 +396,4 @@ ignore: exclude,

});
candidates.forEach(catalogDir => {
const name = _path.default.basename(catalogDir);
catalogs.push(new Catalog({

@@ -471,3 +409,2 @@ name,

}
function getCatalogForFile(file, catalogs) {

@@ -477,5 +414,3 @@ for (const catalog of catalogs) {

const catalogGlob = catalogFile.replace(LOCALE_REPLACE_RE, "*");
const match = _micromatch.default.capture(normalizeRelativePath(_path.default.relative(catalog.config.rootDir, catalogGlob)), normalizeRelativePath(file));
if (match) {

@@ -488,30 +423,27 @@ return {

}
return null;
}
/**
* Create catalog for merged messages.
*/
function getCatalogForMerge(config) {
const catalogConfig = config;
if (catalogConfig.catalogsMergePath.endsWith(PATHSEP)) {
const extension = (0, _formats.default)(config.format).catalogExtension;
const correctPath = catalogConfig.catalogsMergePath.slice(0, -1);
const examplePath = correctPath.replace(LOCALE_REPLACE_RE, // Show example using one of configured locales (if any)
const examplePath = correctPath.replace(LOCALE_REPLACE_RE,
// Show example using one of configured locales (if any)
(config.locales || [])[0] || "en") + extension;
throw new Error( // prettier-ignore
throw new Error(
// prettier-ignore
`Remove trailing slash from "${catalogConfig.catalogsMergePath}". Catalog path isn't a directory,` + ` but translation file without extension. For example, catalog path "${correctPath}"` + ` results in translation file "${examplePath}".`);
} // catalog name is the last directory of catalogPath.
}
// catalog name is the last directory of catalogPath.
// If the last part is {locale}, then catalog doesn't have an explicit name
const name = function () {
const _name = _path.default.basename(normalizeRelativePath(catalogConfig.catalogsMergePath));
return _name !== LOCALE ? _name : null;
}();
const catalog = new Catalog({

@@ -525,2 +457,3 @@ name,

}
/**

@@ -530,4 +463,2 @@ * Merge origins and extractedComments for messages found in different places. All other attributes

*/
function mergeOriginsAndExtractedComments(msgId, prev, next) {

@@ -537,4 +468,4 @@ if (prev.defaults !== next.defaults) {

}
return { ...next,
return {
...next,
extractedComments: R.concat(prev.extractedComments, next.extractedComments),

@@ -544,7 +475,6 @@ origin: R.concat(prev.origin, next.origin)

}
/**
* Ensure that value is always array. If not, turn it into an array of one element.
*/
const ensureArray = value => {

@@ -554,2 +484,3 @@ if (value == null) return [];

};
/**

@@ -561,4 +492,2 @@ * Remove ./ at the beginning: ./relative => relative

*/
function normalizeRelativePath(sourcePath) {

@@ -569,11 +498,7 @@ if (_path.default.isAbsolute(sourcePath)) {

}
const isDir = _fsExtra.default.existsSync(sourcePath) && _fsExtra.default.lstatSync(sourcePath).isDirectory();
return (0, _normalizePath.default)(_path.default.relative(process.cwd(), sourcePath), false) + (isDir ? "/" : "");
}
const cleanObsolete = R.filter(message => !message.obsolete);
exports.cleanObsolete = cleanObsolete;
function order(by) {

@@ -585,2 +510,3 @@ return {

}
/**

@@ -590,4 +516,2 @@ * Object keys are in the same order as they were created

*/
function orderByMessageId(messages) {

@@ -600,3 +524,2 @@ const orderedMessages = {};

}
function orderByOrigin(messages) {

@@ -611,3 +534,2 @@ function getFirstOrigin(messageKey) {

}
return Object.keys(messages).sort(function (a, b) {

@@ -614,0 +536,0 @@ const [aFile, aLineNumber] = getFirstOrigin(a);

@@ -6,19 +6,11 @@ "use strict";

});
exports.compile = compile;
exports.createCompiledCatalog = createCompiledCatalog;
exports.compile = compile;
var t = _interopRequireWildcard(require("@babel/types"));
var _generator = _interopRequireDefault(require("@babel/generator"));
var _compile = require("@lingui/core/compile");
var _pseudoLocalize = _interopRequireDefault(require("./pseudoLocalize"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function createCompiledCatalog(locale, messages, options) {

@@ -33,5 +25,6 @@ const {

const compiledMessages = Object.keys(messages).reduce((obj, key) => {
const value = messages[key]; // If the current ID's value is a context object, create a nested
const value = messages[key];
// If the current ID's value is a context object, create a nested
// expression, and assign the current ID to that expression
if (typeof value === "object") {

@@ -43,5 +36,5 @@ obj[key] = Object.keys(value).reduce((obj, contextKey) => {

return obj;
} // Don't use `key` as a fallback translation in strict mode.
}
// Don't use `key` as a fallback translation in strict mode.
const translation = messages[key] || (!strict ? key : "");

@@ -51,4 +44,5 @@ obj[key] = compile(translation, shouldPseudolocalize);

}, {});
const ast = buildExportStatement( //build JSON.parse(<compiledMessages>) statement
t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('parse')), [t.stringLiteral(JSON.stringify(compiledMessages))]), namespace);
const ast = buildExportStatement(
//build JSON.parse(<compiledMessages>) statement
t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [t.stringLiteral(JSON.stringify(compiledMessages))]), namespace);
const code = (0, _generator.default)(ast, {

@@ -63,3 +57,2 @@ minified: true,

}
function buildExportStatement(expression, namespace) {

@@ -72,3 +65,2 @@ if (namespace === "es" || namespace === "ts") {

const matches = namespace.match(/^(window|global)\.([^.\s]+)$/);
if (namespace === "cjs") {

@@ -83,6 +75,6 @@ // module.exports.messages = { message: "Translation" }

}
return t.expressionStatement(t.assignmentExpression("=", exportExpression, t.objectExpression([t.objectProperty(t.identifier("messages"), expression)])));
}
}
/**

@@ -92,6 +84,4 @@ * Compile string message into AST tree. Message format is parsed/compiled into

*/
function compile(message, shouldPseudolocalize = false) {
return (0, _compile.compileMessage)(message, value => shouldPseudolocalize ? (0, _pseudoLocalize.default)(value) : value);
}

@@ -8,13 +8,7 @@ "use strict";

exports.projectType = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _pkgUp = _interopRequireDefault(require("pkg-up"));
var _package = _interopRequireDefault(require("../../package.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const projectType = {

@@ -25,3 +19,2 @@ CRA: "CRA",

exports.projectType = projectType;
function getPackageJson(cwd) {

@@ -31,6 +24,4 @@ const packageJsonPath = _pkgUp.default.sync({

});
try {
const json = _fs.default.readFileSync(packageJsonPath, "utf8");
return {

@@ -45,7 +36,5 @@ path: packageJsonPath,

}
function hasDependency(pkg, name) {
return pkg.dependencies && pkg.dependencies[name] || pkg.devDependencies && pkg.devDependencies[name];
}
function detectFramework(pkg) {

@@ -55,19 +44,14 @@ if (hasDependency(pkg, "react-scripts")) {

}
if (hasDependency(pkg, "react")) {
return projectType.REACT;
}
return null;
}
function detect() {
let pkg = getPackageJson();
if (!pkg) return null;
if (pkg.content.name === _package.default.name) {
pkg = getPackageJson(_path.default.dirname(pkg.path));
}
return detectFramework(pkg.content);
}

@@ -6,23 +6,13 @@ "use strict";

});
exports.collect = collect;
exports.extract = extract;
exports.collect = collect;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _chalk = _interopRequireDefault(require("chalk"));
var R = _interopRequireWildcard(require("ramda"));
var _utils = require("./utils");
var _extractors = _interopRequireDefault(require("./extractors"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**

@@ -36,4 +26,4 @@ * Merge origins for messages found in different places. All other attributes

}
return { ...next,
return {
...next,
message: prev.message || next.message,

@@ -43,3 +33,2 @@ origin: R.concat(prev.origin, next.origin)

}
async function extract(srcPaths, targetPath, options = {}) {

@@ -50,27 +39,19 @@ const {

const ignorePattern = ignore.length ? new RegExp(ignore.join("|"), "i") : null;
for (let srcFilename of srcPaths) {
if (!_fs.default.existsSync(srcFilename) || ignorePattern && ignorePattern.test(srcFilename)) continue;
if (_fs.default.statSync(srcFilename).isDirectory()) {
const subdirs = _fs.default.readdirSync(srcFilename).sort().map(filename => _path.default.join(srcFilename, filename));
await extract(subdirs, targetPath, options);
continue;
}
await (0, _extractors.default)(srcFilename, targetPath, options);
}
}
function collect(buildDir) {
return _fs.default.readdirSync(buildDir).sort().map(filename => {
const filepath = _path.default.join(buildDir, filename);
if (_fs.default.lstatSync(filepath).isDirectory()) {
return collect(filepath);
}
if (!filename.endsWith(".json")) return;
try {

@@ -77,0 +58,0 @@ return JSON.parse(_fs.default.readFileSync(filepath).toString());

@@ -7,11 +7,6 @@ "use strict";

exports.default = void 0;
var _core = require("@babel/core");
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
var _detect = require("../detect");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const babelRe = new RegExp("\\.(" + [..._core.DEFAULT_EXTENSIONS, ".ts", ".tsx"].map(ext => ext.slice(1)).join("|") + ")$", "i");

@@ -22,3 +17,2 @@ const extractor = {

},
extract(filename, localeDir, options = {}) {

@@ -34,8 +28,7 @@ const {

const frameworkOptions = {};
if (options.projectType === _detect.projectType.CRA) {
frameworkOptions.presets = ["react-app"];
}
(0, _core.transformFileSync)(filename, { ...babelOptions,
(0, _core.transformFileSync)(filename, {
...babelOptions,
...frameworkOptions,

@@ -51,5 +44,4 @@ // we override envName to avoid issues with NODE_ENV=production

}
};
var _default = extractor;
exports.default = _default;

@@ -7,17 +7,10 @@ "use strict";

exports.default = extract;
var _ora = _interopRequireDefault(require("ora"));
var _babel = _interopRequireDefault(require("./babel"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const DEFAULT_EXTRACTORS = [_babel.default];
async function extract(filename, targetPath, options) {
const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS;
for (let e of extractorsToExtract) {
let ext = e;
if (typeof e === "string") {

@@ -27,11 +20,8 @@ // in case of the user using require.resolve in their extractors, we require that module

}
if (ext.default) {
ext = ext.default;
}
if (!ext.match(filename)) continue;
let spinner;
if (options.verbose) spinner = (0, _ora.default)().start(filename);
try {

@@ -47,8 +37,6 @@ await ext.extract(filename, targetPath, options);

}
return false;
}
}
return true;
}

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

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _core = require("@babel/core");
var _babelPluginExtractMessages = _interopRequireDefault(require("@lingui/babel-plugin-extract-messages"));
var _detect = require("../detect");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const typescriptRe = /(^.?|\.[^d]|[^.]d|[^.][^d])\.tsx?$/i;

@@ -24,10 +18,7 @@ const extractor = {

},
extract(filename, localeDir, options = {}) {
const ts = require("typescript");
const content = _fs.default.readFileSync(filename, "utf8");
const isTsx = filename.endsWith(".tsx"); // pass jsx to babel untouched
const isTsx = filename.endsWith(".tsx");
// pass jsx to babel untouched
const jsx = isTsx ? ts.JsxEmit.Preserve : ts.JsxEmit.None;

@@ -46,7 +37,5 @@ const stripped = ts.transpileModule(content, {

const frameworkOptions = {};
if (options.projectType === _detect.projectType.CRA) {
frameworkOptions.presets = ["react-app"];
}
const {

@@ -60,8 +49,7 @@ babelOptions = {},

}], ...(babelOptions.plugins || [])];
if (isTsx) {
plugins.unshift(require.resolve("@babel/plugin-syntax-jsx"));
}
(0, _core.transform)(stripped.outputText, { ...babelOptions,
(0, _core.transform)(stripped.outputText, {
...babelOptions,
...frameworkOptions,

@@ -72,5 +60,4 @@ filename,

}
};
var _default = extractor;
exports.default = _default;

@@ -7,11 +7,6 @@ "use strict";

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _papaparse = _interopRequireDefault(require("papaparse"));
var _utils = require("../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const serialize = catalog => {

@@ -21,12 +16,8 @@ const rawArr = Object.keys(catalog).map(key => [key, catalog[key].translation]);

};
const deserialize = raw => {
const rawCatalog = _papaparse.default.parse(raw);
const messages = {};
if (rawCatalog.errors.length) {
throw new Error(rawCatalog.errors.map(err => JSON.stringify(err)).join(";"));
}
rawCatalog.data.forEach(([key, translation]) => {

@@ -42,6 +33,4 @@ messages[key] = {

};
const csv = {
catalogExtension: ".csv",
write(filename, catalog) {

@@ -51,6 +40,4 @@ const messages = serialize(catalog);

},
read(filename) {
const raw = _fs.default.readFileSync(filename).toString();
try {

@@ -62,9 +49,7 @@ return deserialize(raw);

},
parse(content) {
return deserialize(content);
}
};
var _default = csv;
exports.default = _default;

@@ -7,15 +7,8 @@ "use strict";

exports.default = getFormat;
var _csv = _interopRequireDefault(require("./csv"));
var _lingui = _interopRequireDefault(require("./lingui"));
var _minimal = _interopRequireDefault(require("./minimal"));
var _po = _interopRequireDefault(require("./po"));
var _poGettext = _interopRequireDefault(require("./po-gettext"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const formats = {

@@ -28,2 +21,3 @@ lingui: _lingui.default,

};
/**

@@ -35,8 +29,6 @@ * @internal

const format = formats[name];
if (!format) {
throw new Error(`Unknown format "${name}". Use one of following: ${Object.keys(formats).join(", ")}`);
}
return format;
}

@@ -7,15 +7,8 @@ "use strict";

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var R = _interopRequireWildcard(require("ramda"));
var _utils = require("../utils");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const removeOrigins = R.map(({

@@ -32,3 +25,2 @@ origin,

}
return message;

@@ -38,20 +30,14 @@ });

catalogExtension: ".json",
write(filename, catalog, options) {
let outputCatalog = catalog;
if (options.origins === false) {
outputCatalog = removeOrigins(catalog);
}
if (options.origins !== false && options.lineNumbers === false) {
outputCatalog = removeLineNumbers(outputCatalog);
}
(0, _utils.writeFileIfChanged)(filename, JSON.stringify(outputCatalog, null, 2));
},
read(filename) {
const raw = _fs.default.readFileSync(filename).toString();
try {

@@ -63,9 +49,7 @@ return JSON.parse(raw);

},
parse(content) {
return content;
}
};
var _default = lingui;
exports.default = _default;

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

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var R = _interopRequireWildcard(require("ramda"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const serialize = R.map(message => message.translation || "");

@@ -28,9 +22,8 @@ const deserialize = R.map(translation => ({

catalogExtension: ".json",
write(filename, catalog) {
var _file;
const messages = serialize(catalog);
let file = null;
try {
file = _fs.default.readFileSync(filename, 'utf8');
file = _fs.default.readFileSync(filename, "utf8");
} catch (error) {

@@ -41,12 +34,8 @@ if (error.code !== "ENOENT") {

}
const shouldUseTrailingNewline = file === null || file?.endsWith("\n");
const shouldUseTrailingNewline = file === null || ((_file = file) === null || _file === void 0 ? void 0 : _file.endsWith("\n"));
const trailingNewLine = shouldUseTrailingNewline ? "\n" : "";
_fs.default.writeFileSync(filename, `${JSON.stringify(messages, null, 2)}${trailingNewLine}`);
},
read(filename) {
const raw = _fs.default.readFileSync(filename).toString();
try {

@@ -59,9 +48,7 @@ const rawCatalog = JSON.parse(raw);

},
parse(content) {
return deserialize(content);
}
};
var _default = minimal;
exports.default = _default;

@@ -7,25 +7,13 @@ "use strict";

exports.default = void 0;
var _dateFns = require("date-fns");
var _fs = _interopRequireDefault(require("fs"));
var _parser = require("@messageformat/parser");
var _pluralsCldr = _interopRequireDefault(require("plurals-cldr"));
var _pofile = _interopRequireDefault(require("pofile"));
var R = _interopRequireWildcard(require("ramda"));
var _plurals = _interopRequireDefault(require("node-gettext/lib/plurals"));
var _utils = require("../utils");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getCreateHeaders(language = "no") {

@@ -40,5 +28,5 @@ return {

};
} // Attempts to turn a single tokenized ICU plural case back into a string.
}
// Attempts to turn a single tokenized ICU plural case back into a string.
function stringifyICUCase(icuCase) {

@@ -58,21 +46,19 @@ return icuCase.tokens.map(token => {

}
const ICU_PLURAL_REGEX = /^{.*, plural, .*}$/;
const ICU_SELECT_REGEX = /^{.*, select(Ordinal)?, .*}$/;
const LINE_ENDINGS = /\r?\n/g; // Prefix that is used to identitify context information used by this module in PO's "extracted comments".
const LINE_ENDINGS = /\r?\n/g;
// Prefix that is used to identitify context information used by this module in PO's "extracted comments".
const CTX_PREFIX = "js-lingui:";
const serialize = (items, options) => R.compose(R.values, R.mapObjIndexed((message, key) => {
const item = new _pofile.default.Item();
item.msgid = key;
item.comments = message.comments || []; // The extractedComments array may be modified in this method, so create a new array with the message's elements.
item.comments = message.comments || [];
// The extractedComments array may be modified in this method, so create a new array with the message's elements.
// Destructuring `undefined` is forbidden, so fallback to `[]` if the message has no extracted comments.
item.extractedComments = [...(message.extractedComments ?? [])];
if (message.context) {
item.msgctxt = message.context;
}
if (options.origins !== false) {

@@ -84,27 +70,28 @@ if (message.origin && options.lineNumbers === false) {

}
} // @ts-ignore: Figure out how to set this flag
}
// @ts-ignore: Figure out how to set this flag
item.obsolete = message.obsolete;
item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {};
item.obsolete = message.obsolete;
item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {}; // Depending on whether custom ids are used by the developer, the (potential plural) "original", untranslated ICU
// Depending on whether custom ids are used by the developer, the (potential plural) "original", untranslated ICU
// message can be found in `message.message` or in the item's `key` itself.
const icuMessage = message.message || key;
const _simplifiedMessage = icuMessage.replace(LINE_ENDINGS, " ");
const _simplifiedMessage = icuMessage.replace(LINE_ENDINGS, " "); // Quick check to see if original message is a plural localization.
// Quick check to see if original message is a plural localization.
if (ICU_PLURAL_REGEX.test(_simplifiedMessage)) {
try {
const messageAst = (0, _parser.parse)(icuMessage)[0]; // Check if any of the plural cases contain plurals themselves.
var _message$translation;
const messageAst = (0, _parser.parse)(icuMessage)[0];
// Check if any of the plural cases contain plurals themselves.
if (messageAst.cases.some(icuCase => icuCase.tokens.some(token => token.type === "plural"))) {
console.warn(`Nested plurals cannot be expressed with gettext plurals. ` + `Message with key "%s" will not be saved correctly.`, key);
} // Store placeholder that is pluralized upon to allow restoring ICU format later.
}
// Store placeholder that is pluralized upon to allow restoring ICU format later.
const ctx = new URLSearchParams({
pluralize_on: messageAst.arg
});
if (message.message == null) {

@@ -115,4 +102,5 @@ // For messages without developer-set ID, use first case as `msgid` and the last case as `msgid_plural`.

item.msgid = stringifyICUCase(messageAst.cases[0]);
item.msgid_plural = stringifyICUCase(messageAst.cases[messageAst.cases.length - 1]); // Since the original msgid is overwritten, store ICU message to allow restoring that ID later.
item.msgid_plural = stringifyICUCase(messageAst.cases[messageAst.cases.length - 1]);
// Since the original msgid is overwritten, store ICU message to allow restoring that ID later.
ctx.set("icu", key);

@@ -123,12 +111,11 @@ } else {

}
ctx.sort();
item.extractedComments.push(CTX_PREFIX + ctx.toString());
ctx.sort();
item.extractedComments.push(CTX_PREFIX + ctx.toString()); // If there is a translated value, parse that instead of the original message to prevent overriding localized
// If there is a translated value, parse that instead of the original message to prevent overriding localized
// content with the original message. If there is no translated value, don't touch msgstr, since marking item as
// plural (above) already causes `pofile` to automatically generate `msgstr[0]` and `msgstr[1]`.
if (message.translation?.length > 0) {
if (((_message$translation = message.translation) === null || _message$translation === void 0 ? void 0 : _message$translation.length) > 0) {
try {
const ast = (0, _parser.parse)(message.translation)[0];
if (ast.cases == null) {

@@ -151,9 +138,6 @@ console.warn(`Found translation without plural cases for key "${key}". ` + `This likely means that a translated .po file misses multiple msgstr[] entries for the key. ` + `Translation found: "${message.translation}"`);

}
item.msgstr = [message.translation];
}
return item;
}))(items);
const getMessageKey = R.prop("msgid");

@@ -165,3 +149,4 @@ const getTranslations = R.prop("msgstr");

const getOrigins = R.prop("references");
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
// backward-compatibility, remove in 3.x
R.prop("flags"));

@@ -179,2 +164,3 @@ const isObsolete = R.either(R.path(["flags", "obsolete"]), R.prop("obsolete"));

}));
/**

@@ -190,3 +176,2 @@ * Returns ICU case labels in the order that gettext lists localized messages, e.g. 0,1,2 => `["one", "two", "other"]`.

*/
const getPluralCases = lang => {

@@ -196,5 +181,4 @@ // If users uses locale with underscore or slash, es-ES, es_ES, gettextplural is "es" not es-ES.

const gettextPluralsInfo = _plurals.default[correctLang];
return gettextPluralsInfo?.examples.map(pluralCase => (0, _pluralsCldr.default)(correctLang, pluralCase.sample));
return gettextPluralsInfo === null || gettextPluralsInfo === void 0 ? void 0 : gettextPluralsInfo.examples.map(pluralCase => (0, _pluralsCldr.default)(correctLang, pluralCase.sample));
};
const convertPluralsToICU = (items, lang) => {

@@ -206,10 +190,12 @@ // .po plurals are numbered 0-N and need to be mapped to ICU plural classes ("one", "few", "many"...). Different

items.forEach(item => {
var _item$extractedCommen;
const translationCount = getTranslationCount(item);
const messageKey = getMessageKey(item); // Messages without multiple translations (= plural cases) need no further processing.
const messageKey = getMessageKey(item);
// Messages without multiple translations (= plural cases) need no further processing.
if (translationCount <= 1 && !item.msgid_plural) {
return;
} // msgid_plural must be set, but its actual value is not important.
}
// msgid_plural must be set, but its actual value is not important.
if (!item.msgid_plural) {

@@ -219,22 +205,18 @@ console.warn(`Multiple translations for item with key "%s" but missing 'msgid_plural' in catalog "${lang}". This is not supported and the plural cases will be ignored.`, messageKey);

}
const contextComment = item.extractedComments.find(comment => comment.startsWith(CTX_PREFIX))?.substr(CTX_PREFIX.length);
const contextComment = (_item$extractedCommen = item.extractedComments.find(comment => comment.startsWith(CTX_PREFIX))) === null || _item$extractedCommen === void 0 ? void 0 : _item$extractedCommen.substr(CTX_PREFIX.length);
const ctx = new URLSearchParams(contextComment);
if (contextComment != null) {
item.extractedComments = item.extractedComments.filter(comment => !comment.startsWith(CTX_PREFIX));
} // If an original ICU was stored, use that as `msgid` to match the catalog that was originally exported.
}
// If an original ICU was stored, use that as `msgid` to match the catalog that was originally exported.
const storedICU = ctx.get("icu");
if (storedICU != null) {
item.msgid = storedICU;
} // If all translations are empty, ignore item.
}
// If all translations are empty, ignore item.
if (item.msgstr.every(str => str.length === 0)) {
return;
}
if (pluralForms == null) {

@@ -244,14 +226,12 @@ console.warn(`Multiple translations for item with key "%s" in language "${lang}", but no plural cases were found. ` + `This prohibits the translation of .po plurals into ICU plurals. Pluralization will not work for this key.`, messageKey);

}
const pluralCount = pluralForms.length;
if (translationCount > pluralCount) {
console.warn(`More translations provided (${translationCount}) for item with key "%s" in language "${lang}" than there are plural cases available (${pluralCount}). ` + `This will result in not all translations getting picked up.`, messageKey);
} // Map each msgstr to a "<pluralform> {<translated_string>}" entry, joined by one space.
}
// Map each msgstr to a "<pluralform> {<translated_string>}" entry, joined by one space.
const pluralClauses = item.msgstr.map((str, index) => pluralForms[index] + " {" + str + "}").join(" ");
const pluralClauses = item.msgstr.map((str, index) => pluralForms[index] + " {" + str + "}").join(" "); // Find out placeholder name from item's message context, defaulting to "count".
// Find out placeholder name from item's message context, defaulting to "count".
let pluralizeOn = ctx.get("pluralize_on");
if (!pluralizeOn) {

@@ -261,17 +241,12 @@ console.warn(`Unable to determine plural placeholder name for item with key "%s" in language "${lang}" (should be stored in a comment starting with "#. ${CTX_PREFIX}"), assuming "count".`, messageKey);

}
item.msgstr = ["{" + pluralizeOn + ", plural, " + pluralClauses + "}"];
});
};
const indexItems = R.indexBy(getMessageKey);
const poGettext = {
catalogExtension: ".po",
write(filename, catalog, options) {
let po;
if (_fs.default.existsSync(filename)) {
const raw = _fs.default.readFileSync(filename).toString();
po = _pofile.default.parse(raw);

@@ -281,32 +256,23 @@ } else {

po.headers = getCreateHeaders(options.locale);
if (options.locale === undefined) {
delete po.headers.Language;
}
po.headerOrder = Object.keys(po.headers);
}
po.items = this.serialize(catalog, options);
(0, _utils.writeFileIfChanged)(filename, po.toString());
},
// Mainly exported for easier testing
serialize,
read(filename) {
const raw = _fs.default.readFileSync(filename).toString();
return this.parse(raw);
},
parse(raw) {
const po = _pofile.default.parse(raw);
convertPluralsToICU(po.items, po.headers.Language);
return deserialize(indexItems(po.items));
}
};
var _default = poGettext;
exports.default = _default;

@@ -7,19 +7,10 @@ "use strict";

exports.default = void 0;
var _fs = _interopRequireDefault(require("fs"));
var R = _interopRequireWildcard(require("ramda"));
var _dateFns = require("date-fns");
var _pofile = _interopRequireDefault(require("pofile"));
var _utils = require("../utils");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getCreateHeaders = (language = "no") => ({

@@ -33,3 +24,2 @@ "POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),

});
const serialize = (items, options) => R.compose(R.values, R.mapObjIndexed((message, key) => {

@@ -41,7 +31,5 @@ const item = new _pofile.default.Item();

item.extractedComments = message.extractedComments || [];
if (message.context) {
item.msgctxt = message.context;
}
if (options.origins !== false) {

@@ -53,5 +41,4 @@ if (message.origin && options.lineNumbers === false) {

}
} // @ts-ignore: Figure out how to set this flag
}
// @ts-ignore: Figure out how to set this flag
item.obsolete = message.obsolete;

@@ -61,3 +48,2 @@ item.flags = message.flags ? R.fromPairs(message.flags.map(flag => [flag, true])) : {};

}))(items);
const getMessageKey = R.prop("msgid");

@@ -69,3 +55,4 @@ const getTranslations = R.prop("msgstr");

const getOrigins = R.prop("references");
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"), // backward-compatibility, remove in 3.x
const getFlags = R.compose(R.map(R.trim), R.keys, R.dissoc("obsolete"),
// backward-compatibility, remove in 3.x
R.prop("flags"));

@@ -90,9 +77,6 @@ const isObsolete = R.either(R.path(["flags", "obsolete"]), R.prop("obsolete"));

catalogExtension: ".po",
write(filename, catalog, options) {
let po;
if (_fs.default.existsSync(filename)) {
const raw = _fs.default.readFileSync(filename).toString();
po = _pofile.default.parse(raw);

@@ -102,29 +86,21 @@ } else {

po.headers = getCreateHeaders(options.locale);
if (options.locale === undefined) {
delete po.headers.Language;
}
po.headerOrder = R.keys(po.headers);
}
po.items = serialize(catalog, options);
(0, _utils.writeFileIfChanged)(filename, po.toString());
},
read(filename) {
const raw = _fs.default.readFileSync(filename).toString();
return this.parse(raw);
},
parse(raw) {
const po = _pofile.default.parse(raw);
validateItems(po.items);
return deserialize(indexItems(po.items));
}
};
var _default = po;
exports.default = _default;

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

exports.helpRun = helpRun;
var _path = require("path");
/**

@@ -29,12 +27,11 @@ * Detect where's is the command lingui extract or lingui compile

*/
function helpRun(command) {
var _findRootPkgJson;
let findRootPkgJson;
try {
findRootPkgJson = require((0, _path.resolve)((0, _path.join)(process.cwd(), "package.json")));
} catch (error) {}
if (findRootPkgJson?.scripts) {
if ((_findRootPkgJson = findRootPkgJson) !== null && _findRootPkgJson !== void 0 && _findRootPkgJson.scripts) {
const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) => value.includes(`lingui ${command}`));
if (res) {

@@ -44,7 +41,5 @@ command = res[0];

}
return `${runCommand} ${command}`;
}
const isYarn = process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes("yarn");
const runCommand = isYarn ? "yarn" : "npm run";

@@ -6,33 +6,29 @@ "use strict";

});
Object.defineProperty(exports, "getFormat", {
Object.defineProperty(exports, "createCompiledCatalog", {
enumerable: true,
get: function () {
return _formats.default;
return _compile.createCompiledCatalog;
}
});
Object.defineProperty(exports, "getCatalogs", {
Object.defineProperty(exports, "getCatalogForFile", {
enumerable: true,
get: function () {
return _catalog.getCatalogs;
return _catalog.getCatalogForFile;
}
});
Object.defineProperty(exports, "getCatalogForFile", {
Object.defineProperty(exports, "getCatalogs", {
enumerable: true,
get: function () {
return _catalog.getCatalogForFile;
return _catalog.getCatalogs;
}
});
Object.defineProperty(exports, "createCompiledCatalog", {
Object.defineProperty(exports, "getFormat", {
enumerable: true,
get: function () {
return _compile.createCompiledCatalog;
return _formats.default;
}
});
var _formats = _interopRequireDefault(require("./formats"));
var _catalog = require("./catalog");
var _compile = require("./compile");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -8,13 +8,7 @@ "use strict";

exports.parse = parse;
var plurals = _interopRequireWildcard(require("make-plural/plurals"));
var _bcp = _interopRequireDefault(require("bcp-47"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**

@@ -29,2 +23,3 @@ * Check that locale is valid according to BCP47 and we have plurals for it

}
/**

@@ -35,9 +30,5 @@ * Parse locale in BCP47 format and

*/
function parse(locale) {
if (typeof locale !== "string") return null;
const schema = _bcp.default.parse(locale.replace("_", "-"));
if (!schema.language) return null;

@@ -44,0 +35,0 @@ return {

@@ -7,14 +7,11 @@ "use strict";

exports.default = _default;
var _ramda = _interopRequireDefault(require("ramda"));
var _pseudolocale = _interopRequireDefault(require("pseudolocale"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const delimiter = "%&&&%";
_pseudolocale.default.option.delimiter = delimiter; // We do not want prepending and appending because of Plurals structure
_pseudolocale.default.option.delimiter = delimiter;
// We do not want prepending and appending because of Plurals structure
_pseudolocale.default.option.prepend = "";
_pseudolocale.default.option.append = "";
/**

@@ -25,4 +22,4 @@ * Regex should match HTML tags

*/
const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g;
const HTMLRegex = /<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g;
/**

@@ -35,4 +32,4 @@ * Regex should match js-lingui Plurals, Select and SelectOrdinal components

*/
const MacroRegex = /({\w*,\s*(plural|selectordinal|select),(.|\n)*?{)|(}\s*\w*\s*{)/gi;
const MacroRegex = /({\w*,\s*(plural|selectordinal|select),(.|\n)*?{)|(}\s*\w*\s*{)/gi;
/**

@@ -42,5 +39,3 @@ * Regex should match js-lingui variables

*/
const VariableRegex = /({\s*[a-zA-Z_$][a-zA-Z_$0-9]*\s*})/g;
function addDelimitersHTMLTags(message) {

@@ -51,3 +46,2 @@ return message.replace(HTMLRegex, matchedString => {

}
function addDelimitersMacro(message) {

@@ -58,3 +52,2 @@ return message.replace(MacroRegex, matchedString => {

}
function addDelimitersVariables(message) {

@@ -65,9 +58,6 @@ return message.replace(VariableRegex, matchedString => {

}
const addDelimiters = _ramda.default.compose(addDelimitersVariables, addDelimitersMacro, addDelimitersHTMLTags);
function removeDelimiters(message) {
return message.replace(new RegExp(delimiter, "g"), "");
}
function _default(message) {

@@ -74,0 +64,0 @@ message = addDelimiters(message);

@@ -8,13 +8,8 @@ "use strict";

exports.printStats = printStats;
var _cliTable = _interopRequireDefault(require("cli-table"));
var _chalk = _interopRequireDefault(require("chalk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getStats(catalog) {
return [Object.keys(catalog).length, Object.keys(catalog).filter(key => !catalog[key].translation).length];
}
function printStats(config, catalogs) {

@@ -31,7 +26,6 @@ const table = new _cliTable.default({

Object.keys(catalogs).forEach(locale => {
const catalog = catalogs[locale]; // catalog is null if no catalog exists on disk and the locale
const catalog = catalogs[locale];
// catalog is null if no catalog exists on disk and the locale
// was not extracted due to a `--locale` filter
const [all, translated] = catalog ? getStats(catalog) : ["-", "-"];
if (config.sourceLocale === locale) {

@@ -38,0 +32,0 @@ table.push({

@@ -6,31 +6,23 @@ "use strict";

});
exports.hasYarn = hasYarn;
exports.helpMisspelledCommand = helpMisspelledCommand;
exports.joinOrigin = void 0;
exports.makeInstall = makeInstall;
exports.prettyOrigin = prettyOrigin;
exports.removeDirectory = removeDirectory;
exports.prettyOrigin = prettyOrigin;
exports.helpMisspelledCommand = helpMisspelledCommand;
exports.splitOrigin = void 0;
exports.writeFileIfChanged = writeFileIfChanged;
exports.hasYarn = hasYarn;
exports.makeInstall = makeInstall;
exports.joinOrigin = exports.splitOrigin = void 0;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
var _chalk = _interopRequireDefault(require("chalk"));
var _fuzzaldrin = require("fuzzaldrin");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function removeDirectory(dir, onlyContent = false) {
if (!_fs.default.existsSync(dir)) return;
const list = _fs.default.readdirSync(dir);
for (let i = 0; i < list.length; i++) {
const filename = _path.default.join(dir, list[i]);
const stat = _fs.default.statSync(filename);
if (filename === "." || filename === "..") {// pass these files
if (filename === "." || filename === "..") {
// pass these files
} else if (stat.isDirectory()) {

@@ -43,3 +35,2 @@ // rmdir recursively

}
if (!onlyContent) {

@@ -49,3 +40,2 @@ _fs.default.rmdirSync(dir);

}
function prettyOrigin(origins) {

@@ -58,2 +48,3 @@ try {

}
/**

@@ -67,11 +58,9 @@ * .. js:function:: helpMisspelledCommand(command [, availableCommands = []])

*/
function helpMisspelledCommand(command, availableCommands = []) {
const commandNames = availableCommands.map(command => command.name()); // if no command is supplied, then commander.js shows help automatically
const commandNames = availableCommands.map(command => command.name());
// if no command is supplied, then commander.js shows help automatically
if (!command || commandNames.includes(command)) {
return;
}
const suggestions = commandNames.map(name => ({

@@ -82,3 +71,2 @@ name,

console.log(`lingui: command ${command} is not a lingui command. ` + `See 'lingui --help' for the list of available commands.`);
if (suggestions) {

@@ -89,15 +77,9 @@ console.log();

}
const splitOrigin = origin => origin.split(":");
exports.splitOrigin = splitOrigin;
const joinOrigin = origin => origin.join(":");
exports.joinOrigin = joinOrigin;
function writeFileIfChanged(filename, newContent) {
if (_fs.default.existsSync(filename)) {
const raw = _fs.default.readFileSync(filename).toString();
if (newContent !== raw) {

@@ -110,7 +92,5 @@ _fs.default.writeFileSync(filename, newContent);

}
function hasYarn() {
return _fs.default.existsSync(_path.default.resolve("yarn.lock"));
}
function makeInstall() {

@@ -117,0 +97,0 @@ const withYarn = hasYarn();

"use strict";
var _chalk = _interopRequireDefault(require("chalk"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (require.main === module) {
const msg = "lingui add-locale command is deprecated. " + `Please set ${_chalk.default.yellow("'locales'")} in configuration. ` + _chalk.default.underline("https://lingui.dev/ref/conf#locales");
console.error(msg);
}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.command = command;
var _chalk = _interopRequireDefault(require("chalk"));
var _chokidar = _interopRequireDefault(require("chokidar"));
var _fs = _interopRequireDefault(require("fs"));
var R = _interopRequireWildcard(require("ramda"));
var _commander = _interopRequireDefault(require("commander"));
var plurals = _interopRequireWildcard(require("make-plural"));
var _conf = require("@lingui/conf");
var _catalog = require("./api/catalog");
var _compile = require("./api/compile");
var _help = require("./api/help");
var _api = require("./api");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const noMessages = R.pipe(R.map(R.isEmpty), R.values, R.all(R.equals(true)));
function command(config, options) {
const catalogs = (0, _catalog.getCatalogs)(config);
// fixme: this is definitely doesn't work
if (noMessages(catalogs)) {

@@ -40,17 +30,16 @@ console.error("Nothing to compile, message catalogs are empty!\n");

return false;
} // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
}
// Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
const doMerge = !!config.catalogsMergePath;
let mergedCatalogs = {};
console.error("Compiling message catalogs…");
config.locales.forEach(locale => {
console.log("Compiling message catalogs…");
for (const locale of config.locales) {
const [language] = locale.split(/[_-]/);
// todo: this validation should be in @lingui/conf
if (locale !== config.pseudoLocale && !plurals[language]) {
console.log(_chalk.default.red(`Error: Invalid locale ${_chalk.default.bold(locale)} (missing plural rules)!`));
console.error(_chalk.default.red(`Error: Invalid locale ${_chalk.default.bold(locale)} (missing plural rules)!`));
console.error();
}
catalogs.forEach(catalog => {
for (const catalog of catalogs) {
const messages = catalog.getTranslations(locale, {

@@ -60,23 +49,19 @@ fallbackLocales: config.fallbackLocales,

});
if (!options.allowEmpty) {
const missingMsgIds = R.pipe(R.pickBy(R.isNil), R.keys)(messages);
if (missingMsgIds.length > 0) {
console.error(_chalk.default.red(`Error: Failed to compile catalog for locale ${_chalk.default.bold(locale)}!`));
if (options.verbose) {
console.error(_chalk.default.red("Missing translations:"));
missingMsgIds.forEach(msgId => console.log(msgId));
missingMsgIds.forEach(msgId => console.error(msgId));
} else {
console.error(_chalk.default.red(`Missing ${missingMsgIds.length} translation(s)`));
}
console.error();
process.exit(1);
return false;
}
}
if (doMerge) {
mergedCatalogs = { ...mergedCatalogs,
mergedCatalogs = {
...mergedCatalogs,
...messages

@@ -93,6 +78,4 @@ };

const compiledPath = catalog.writeCompiled(locale, compiledCatalog, namespace);
if (options.typescript) {
const typescriptPath = compiledPath.replace(/\.ts?$/, "") + ".d.ts";
_fs.default.writeFileSync(typescriptPath, `import { Messages } from '@lingui/core';

@@ -103,7 +86,5 @@ declare const messages: Messages;

}
options.verbose && console.error(_chalk.default.green(`${locale} ⇒ ${compiledPath}`));
}
});
}
if (doMerge) {

@@ -121,6 +102,5 @@ const compileCatalog = (0, _catalog.getCatalogForMerge)(config);

}
});
}
return true;
}
if (require.main === module) {

@@ -137,7 +117,5 @@ _commander.default.description("Add compile message catalogs and add language data (plurals) to compiled bundle.").option("--config <path>", "Path to the config file").option("--strict", "Disable defaults for missing translations").option("--verbose", "Verbose output").option("--format <format>", "Format of message catalog").option("--typescript", "Create Typescript definition for compiled bundle").option("--namespace <namespace>", "Specify namespace for compiled bundle. Ex: cjs(default) -> module.exports, es -> export, window.test -> window.test").option("--watch", "Enables Watch Mode").option("--debounce <delay>", "Debounces compilation for given amount of milliseconds").on("--help", function () {

}).parse(process.argv);
const config = (0, _conf.getConfig)({
configPath: _commander.default.config
});
if (_commander.default.format) {

@@ -148,3 +126,2 @@ const msg = "--format option is deprecated and will be removed in @lingui/cli@3.0.0." + " Please set format in configuration https://lingui.dev/ref/conf#format";

}
const compile = () => command(config, {

@@ -155,16 +132,15 @@ verbose: _commander.default.watch || _commander.default.verbose || false,

namespace: _commander.default.namespace // we want this to be undefined if user does not specify so default can be used
});
let debounceTimer;
const dispatchCompile = () => {
// Skip debouncing if not enabled
if (!_commander.default.debounce) return compile(); // CLear the previous timer if there is any, and schedule the next
if (!_commander.default.debounce) return compile();
// CLear the previous timer if there is any, and schedule the next
debounceTimer && clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => compile(), _commander.default.debounce);
}; // Check if Watch Mode is enabled
};
// Check if Watch Mode is enabled
if (_commander.default.watch) {

@@ -180,7 +156,5 @@ console.info(_chalk.default.bold("Initializing Watch Mode..."));

});
const watcher = _chokidar.default.watch(paths, {
persistent: true
});
const onReady = () => {

@@ -190,13 +164,10 @@ console.info(_chalk.default.green.bold("Watcher is ready!"));

};
watcher.on("ready", () => onReady());
} else {
const results = compile();
if (!results) {
process.exit(1);
}
console.log("Done!");
}
}

@@ -7,15 +7,8 @@ "use strict";

exports.default = command;
var _chalk = _interopRequireDefault(require("chalk"));
var _commander = _interopRequireDefault(require("commander"));
var _conf = require("@lingui/conf");
var _catalog = require("./api/catalog");
var _detect = require("./api/detect");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
async function command(config, options) {

@@ -26,7 +19,7 @@ // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be

process.env.BABEL_ENV = "development";
} // We need macros to keep imports, so extract-messages plugin know what componets
}
// We need macros to keep imports, so extract-messages plugin know what componets
// to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
// safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
process.env.LINGUI_EXTRACT = "1";

@@ -37,3 +30,4 @@ options.verbose && console.error("Extracting messages from source files…");

await Promise.all(catalogs.map(async catalog => {
await catalog.makeTemplate({ ...options,
await catalog.makeTemplate({
...options,
orderBy: config.orderBy,

@@ -43,3 +37,2 @@ projectType: (0, _detect.detect)()

const catalogTemplate = catalog.readTemplate();
if (catalogTemplate !== null && catalogTemplate !== undefined) {

@@ -55,6 +48,4 @@ catalogStats[catalog.templateFile] = Object.keys(catalogTemplate).length;

}
if (require.main === module) {
_commander.default.option("--config <path>", "Path to the config file").option("--verbose", "Verbose output").parse(process.argv);
const config = (0, _conf.getConfig)({

@@ -61,0 +52,0 @@ configPath: _commander.default.config || process.env.LINGUI_CONFIG

@@ -7,25 +7,13 @@ "use strict";

exports.default = command;
var _chalk = _interopRequireDefault(require("chalk"));
var _chokidar = _interopRequireDefault(require("chokidar"));
var _commander = _interopRequireDefault(require("commander"));
var _conf = require("@lingui/conf");
var _catalog = require("./api/catalog");
var _stats = require("./api/stats");
var _detect = require("./api/detect");
var _help = require("./api/help");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
async function command(config, options) {

@@ -36,7 +24,7 @@ // `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be

process.env.BABEL_ENV = "development";
} // We need macros to keep imports, so extract-messages plugin know what componets
}
// We need macros to keep imports, so extract-messages plugin know what componets
// to collect. Users usually use both BABEN_ENV and NODE_ENV, so it's probably
// safer to introduce a new env variable. LINGUI_EXTRACT=1 during `lingui extract`
process.env.LINGUI_EXTRACT = "1";

@@ -47,5 +35,5 @@ options.verbose && console.error("Extracting messages from source files…");

let commandSuccess = true;
for (let catalog of catalogs) {
const catalogSuccess = await catalog.make({ ...options,
const catalogSuccess = await catalog.make({
...options,
orderBy: config.orderBy,

@@ -58,3 +46,2 @@ extractors: config.extractors,

}
Object.entries(catalogStats).forEach(([key, value]) => {

@@ -65,21 +52,18 @@ console.log(`Catalog statistics for ${key}: `);

});
if (!options.watch) {
console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("extract"))}" to update catalogs with new messages)`);
console.error(`(use "${_chalk.default.yellow((0, _help.helpRun)("compile"))}" to compile catalogs for production)`);
} // If service key is present in configuration, synchronize with cloud translation platform
}
if (typeof config.service === 'object' && config.service.name && config.service.name.length) {
// If service key is present in configuration, synchronize with cloud translation platform
if (typeof config.service === "object" && config.service.name && config.service.name.length) {
const moduleName = config.service.name.charAt(0).toLowerCase() + config.service.name.slice(1);
Promise.resolve(`./services/${moduleName}`).then(s => _interopRequireWildcard(require(s))).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
(specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`./services/${moduleName}`).then(module => module.default(config, options)).catch(err => console.error(`Can't load service module ${moduleName}`, err));
}
return commandSuccess;
}
if (require.main === module) {
_commander.default.option("--config <path>", "Path to the config file").option("--locale <locale>", "Only extract the specified locale").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--debounce <delay>", "Debounces extraction for given amount of milliseconds").option("--verbose", "Verbose output").option("--convert-from <format>", "Convert from previous format of message catalogs").option("--watch", "Enables Watch Mode") // Obsolete options
_commander.default.option("--config <path>", "Path to the config file").option("--locale <locale>", "Only extract the specified locale").option("--overwrite", "Overwrite translations for source locale").option("--clean", "Remove obsolete translations").option("--debounce <delay>", "Debounces extraction for given amount of milliseconds").option("--verbose", "Verbose output").option("--convert-from <format>", "Convert from previous format of message catalogs").option("--watch", "Enables Watch Mode")
// Obsolete options
.option("--babelOptions", "Babel options passed to transform/extract plugins").option("--format <format>", "Format of message catalogs").parse(process.argv);
const config = (0, _conf.getConfig)({

@@ -89,3 +73,2 @@ configPath: _commander.default.config || process.env.LINGUI_CONFIG

let hasErrors = false;
if (_commander.default.format) {

@@ -97,3 +80,2 @@ hasErrors = true;

}
if (_commander.default.babelOptions) {

@@ -105,5 +87,3 @@ hasErrors = true;

}
const prevFormat = _commander.default.convertFrom;
if (prevFormat && config.format === prevFormat) {

@@ -118,3 +98,2 @@ hasErrors = true;

}
if (_commander.default.locale && !config.locales.includes(_commander.default.locale)) {

@@ -125,5 +104,3 @@ hasErrors = true;

}
if (hasErrors) process.exit(1);
const extract = filePath => {

@@ -137,15 +114,14 @@ return command(config, {

watch: _commander.default.watch || false,
files: filePath?.length ? filePath : undefined,
files: filePath !== null && filePath !== void 0 && filePath.length ? filePath : undefined,
prevFormat
});
};
const changedPaths = new Set();
let debounceTimer;
const dispatchExtract = filePath => {
// Skip debouncing if not enabled
if (!_commander.default.debounce) return extract(filePath);
filePath?.forEach(path => changedPaths.add(path)); // CLear the previous timer if there is any, and schedule the next
filePath === null || filePath === void 0 ? void 0 : filePath.forEach(path => changedPaths.add(path));
// CLear the previous timer if there is any, and schedule the next
debounceTimer && clearTimeout(debounceTimer);

@@ -157,5 +133,5 @@ debounceTimer = setTimeout(async () => {

}, _commander.default.debounce);
}; // Check if Watch Mode is enabled
};
// Check if Watch Mode is enabled
if (_commander.default.watch) {

@@ -170,3 +146,2 @@ console.info(_chalk.default.bold("Initializing Watch Mode..."));

});
const watcher = _chokidar.default.watch(paths, {

@@ -176,3 +151,2 @@ ignored: ["/(^|[/\\])../", ...ignored],

});
const onReady = () => {

@@ -182,3 +156,2 @@ console.info(_chalk.default.green.bold("Watcher is ready!"));

};
watcher.on("ready", () => onReady());

@@ -185,0 +158,0 @@ } else if (_commander.default.args) {

@@ -5,7 +5,4 @@ #!/usr/bin/env node

var _utils = require("./api/utils");
const program = require("commander");
let version;
try {

@@ -16,4 +13,3 @@ version = require("./package.json").version;

}
program.version(version).command("add-locale", "Deprecated, run it for instructions").command("extract [files...]", "Extracts messages from source files").command("extract-template", "Extracts messages from source files to a .pot template").command("compile", "Compile message catalogs").parse(process.argv);
(0, _utils.helpMisspelledCommand)(process.argv[2], program.commands);

@@ -7,17 +7,9 @@ "use strict";

exports.default = syncProcess;
var _fs = _interopRequireDefault(require("fs"));
var _path = require("path");
var _pofile = _interopRequireDefault(require("pofile"));
var _https = _interopRequireDefault(require("https"));
var _glob = _interopRequireDefault(require("glob"));
var _dateFns = require("date-fns");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getCreateHeaders = language => ({

@@ -30,21 +22,18 @@ "POT-Creation-Date": (0, _dateFns.format)(new Date(), "yyyy-MM-dd HH:mmxxxx"),

Language: language
}); // Main sync method, call "Init" or "Sync" depending on the project context
});
// Main sync method, call "Init" or "Sync" depending on the project context
function syncProcess(config, options) {
if (config.format != 'po') {
if (config.format != "po") {
console.error(`\n----------\nTranslation.io service is only compatible with the "po" format. Please update your Lingui configuration accordingly.\n----------`);
process.exit(1);
}
const successCallback = project => {
console.log(`\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`);
};
const failCallback = errors => {
console.error(`\n----------\nSynchronization with Translation.io failed: ${errors.join(', ')}\n----------`);
console.error(`\n----------\nSynchronization with Translation.io failed: ${errors.join(", ")}\n----------`);
};
init(config, options, successCallback, errors => {
if (errors.length && errors[0] === 'This project has already been initialized.') {
if (errors.length && errors[0] === "This project has already been initialized.") {
sync(config, options, successCallback, failCallback);

@@ -55,9 +44,9 @@ } else {

});
} // Initialize project with source and existing translations (only first time!)
}
// Initialize project with source and existing translations (only first time!)
// Cf. https://translation.io/docs/create-library#initialization
function init(config, options, successCallback, failCallback) {
const sourceLocale = config.sourceLocale || 'en';
const pseudoLocale = config.pseudoLocale || 'pseudo';
const sourceLocale = config.sourceLocale || "en";
const pseudoLocale = config.pseudoLocale || "pseudo";
const targetLocales = config.locales.filter(value => value != sourceLocale && value != pseudoLocale);

@@ -68,10 +57,9 @@ const paths = poPathsPerLocale(config);

segments[targetLocale] = [];
}); // Create segments from source locale PO items
});
// Create segments from source locale PO items
paths[sourceLocale].forEach(path => {
let raw = _fs.default.readFileSync(path).toString();
let po = _pofile.default.parse(raw);
po.items.filter(item => !item['obsolete']).forEach(item => {
po.items.filter(item => !item["obsolete"]).forEach(item => {
targetLocales.forEach(targetLocale => {

@@ -82,11 +70,10 @@ let newSegment = createSegmentFromPoItem(item);

});
}); // Add translations to segments from target locale PO items
});
// Add translations to segments from target locale PO items
targetLocales.forEach(targetLocale => {
paths[targetLocale].forEach(path => {
let raw = _fs.default.readFileSync(path).toString();
let po = _pofile.default.parse(raw);
po.items.filter(item => !item['obsolete']).forEach((item, index) => {
po.items.filter(item => !item["obsolete"]).forEach((item, index) => {
segments[targetLocale][index].target = item.msgstr[0];

@@ -97,7 +84,7 @@ });

let request = {
"client": "lingui",
"version": require('@lingui/core/package.json').version,
"source_language": sourceLocale,
"target_languages": targetLocales,
"segments": segments
client: "lingui",
version: require("@lingui/core/package.json").version,
source_language: sourceLocale,
target_languages: targetLocales,
segments: segments
};

@@ -114,18 +101,17 @@ postTio("init", request, config.service.apiKey, response => {

});
} // Send all source text from PO to Translation.io and create new PO based on received translations
}
// Send all source text from PO to Translation.io and create new PO based on received translations
// Cf. https://translation.io/docs/create-library#synchronization
function sync(config, options, successCallback, failCallback) {
const sourceLocale = config.sourceLocale || 'en';
const sourceLocale = config.sourceLocale || "en";
const targetLocales = config.locales.filter(value => value != sourceLocale);
const paths = poPathsPerLocale(config);
let segments = []; // Create segments with correct source
let segments = [];
// Create segments with correct source
paths[sourceLocale].forEach(path => {
let raw = _fs.default.readFileSync(path).toString();
let po = _pofile.default.parse(raw);
po.items.filter(item => !item['obsolete']).forEach(item => {
po.items.filter(item => !item["obsolete"]).forEach(item => {
let newSegment = createSegmentFromPoItem(item);

@@ -136,13 +122,13 @@ segments.push(newSegment);

let request = {
"client": "lingui",
"version": require('@lingui/core/package.json').version,
"source_language": sourceLocale,
"target_languages": targetLocales,
"segments": segments
}; // Sync and then remove unused segments (not present in the local application) from Translation.io
client: "lingui",
version: require("@lingui/core/package.json").version,
source_language: sourceLocale,
target_languages: targetLocales,
segments: segments
};
// Sync and then remove unused segments (not present in the local application) from Translation.io
if (options.clean) {
request['purge'] = true;
request["purge"] = true;
}
postTio("sync", request, config.service.apiKey, response => {

@@ -159,30 +145,24 @@ if (response.errors) {

}
function createSegmentFromPoItem(item) {
let itemHasId = item.msgid != item.msgstr[0] && item.msgstr[0].length;
let segment = {
type: 'source',
type: "source",
// No way to edit text for source language (inside code), so not using "key" here
source: itemHasId ? item.msgstr[0] : item.msgid,
// msgstr may be empty if --overwrite is used and no ID is used
context: '',
context: "",
references: [],
comment: ''
comment: ""
};
if (itemHasId) {
segment.context = item.msgid;
}
if (item.references.length) {
segment.references = item.references;
}
if (item.extractedComments.length) {
segment.comment = item.extractedComments.join(' | ');
segment.comment = item.extractedComments.join(" | ");
}
return segment;
}
function createPoItemFromSegment(segment) {

@@ -193,6 +173,5 @@ let item = new _pofile.default.Item();

item.references = segment.references && segment.references.length ? segment.references : [];
item.extractedComments = segment.comment ? segment.comment.split(' | ') : [];
item.extractedComments = segment.comment ? segment.comment.split(" | ") : [];
return item;
}
function saveSegmentsToTargetPos(config, paths, segmentsPerLocale) {

@@ -203,17 +182,17 @@ Object.keys(segmentsPerLocale).forEach(targetLocale => {

const jsPath = path.replace(/\.po?$/, "") + ".js";
const dirPath = (0, _path.dirname)(path); // Remove PO, JS and empty dir
const dirPath = (0, _path.dirname)(path);
// Remove PO, JS and empty dir
if (_fs.default.existsSync(path)) {
_fs.default.unlinkSync(path);
}
if (_fs.default.existsSync(jsPath)) {
_fs.default.unlinkSync(jsPath);
}
if (_fs.default.existsSync(dirPath) && _fs.default.readdirSync(dirPath).length === 0) {
_fs.default.rmdirSync(dirPath);
}
}); // Find target path (ignoring {name})
});
// Find target path (ignoring {name})
const localePath = "".concat(config.catalogs[0].path.replace(/{locale}/g, targetLocale).replace(/{name}/g, ""), ".po");

@@ -227,4 +206,5 @@ const segments = segmentsPerLocale[targetLocale];

items.push(item);
}); // Sort items by messageId
});
// Sort items by messageId
po.items = items.sort((a, b) => {

@@ -234,10 +214,9 @@ if (a.msgid < b.msgid) {

}
if (a.msgid > b.msgid) {
return 1;
}
return 0;
}); // Check that localePath directory exists and save PO file
});
// Check that localePath directory exists and save PO file
_fs.default.promises.mkdir((0, _path.dirname)(localePath), {

@@ -248,3 +227,3 @@ recursive: true

if (err) {
console.error('Error while saving target PO files:');
console.error("Error while saving target PO files:");
console.error(err);

@@ -257,3 +236,2 @@ process.exit(1);

}
function poPathsPerLocale(config) {

@@ -264,5 +242,6 @@ const paths = [];

config.catalogs.forEach(catalog => {
const path = "".concat(catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*"), ".po"); // If {name} is present (replaced by *), list all the existing POs
const path = "".concat(catalog.path.replace(/{locale}/g, locale).replace(/{name}/g, "*"), ".po");
if (path.includes('*')) {
// If {name} is present (replaced by *), list all the existing POs
if (path.includes("*")) {
paths[locale] = paths[locale].concat(_glob.default.sync(path));

@@ -276,21 +255,19 @@ } else {

}
function postTio(action, request, apiKey, successCallback, failCallback) {
let jsonRequest = JSON.stringify(request);
let options = {
hostname: 'translation.io',
path: '/api/v1/segments/' + action + '.json?api_key=' + apiKey,
method: 'POST',
hostname: "translation.io",
path: "/api/v1/segments/" + action + ".json?api_key=" + apiKey,
method: "POST",
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json"
}
};
let req = _https.default.request(options, res => {
res.setEncoding('utf8');
res.setEncoding("utf8");
let body = "";
res.on('data', chunk => {
res.on("data", chunk => {
body = body.concat(chunk);
});
res.on('end', () => {
res.on("end", () => {
let response = JSON.parse(body);

@@ -300,4 +277,3 @@ successCallback(response);

});
req.on('error', e => {
req.on("error", e => {
failCallback(e);

@@ -304,0 +280,0 @@ });

@@ -7,28 +7,18 @@ "use strict";

exports.copyFixture = copyFixture;
exports.makeCatalog = exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
exports.makeNextMessage = makeNextMessage;
exports.makePrevMessage = makePrevMessage;
exports.makeNextMessage = makeNextMessage;
exports.makeCatalog = exports.defaultMergeOptions = exports.defaultMakeTemplateOptions = exports.defaultMakeOptions = void 0;
var _os = _interopRequireDefault(require("os"));
var _fsExtra = _interopRequireDefault(require("fs-extra"));
var _path = _interopRequireDefault(require("path"));
var _jestMocks = require("@lingui/jest-mocks");
var _catalog = require("./api/catalog");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function copyFixture(fixtureDir) {
const tmpDir = _fsExtra.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), `lingui-test-${process.pid}`));
if (_fsExtra.default.existsSync(fixtureDir)) {
_fsExtra.default.copySync(fixtureDir, tmpDir);
}
return tmpDir;
}
const defaultMakeOptions = {

@@ -54,3 +44,2 @@ verbose: false,

exports.defaultMergeOptions = defaultMergeOptions;
const makeCatalog = (config = {}) => {

@@ -64,5 +53,3 @@ return new _catalog.Catalog({

};
exports.makeCatalog = makeCatalog;
function makePrevMessage(message = {}) {

@@ -74,3 +61,2 @@ return {

}
function makeNextMessage(message = {}) {

@@ -77,0 +63,0 @@ return {

@@ -6,2 +6,14 @@ # Change Log

## [3.17.1](https://github.com/lingui/js-lingui/compare/v3.17.0...v3.17.1) (2023-02-07)
### Bug Fixes
* **build:** undeclared dependencies ([#1391](https://github.com/lingui/js-lingui/issues/1391)) ([f390ca4](https://github.com/lingui/js-lingui/commit/f390ca4517144344fcbbbf9c73a42a1a17d0e519))
* **compile:** remove verbose output when using flow with template ([#1388](https://github.com/lingui/js-lingui/issues/1388)) ([31316f9](https://github.com/lingui/js-lingui/commit/31316f938957dba8e908f9f60a452a2673a934ee))
# [3.17.0](https://github.com/lingui/js-lingui/compare/v3.16.1...v3.17.0) (2023-02-01)

@@ -8,0 +20,0 @@

{
"name": "@lingui/cli",
"version": "3.17.0",
"version": "3.17.1",
"description": "CLI for working wit message catalogs",

@@ -48,10 +48,11 @@ "keywords": [

"dependencies": {
"@babel/generator": "^7.11.6",
"@babel/parser": "^7.11.5",
"@babel/plugin-syntax-jsx": "^7.10.4",
"@babel/runtime": "^7.11.2",
"@babel/types": "^7.11.5",
"@lingui/babel-plugin-extract-messages": "3.17.0",
"@lingui/conf": "3.17.0",
"@lingui/core": "3.17.0",
"@babel/generator": "^7.20.14",
"@babel/parser": "^7.20.15",
"@babel/plugin-syntax-jsx": "^7.18.6",
"@babel/runtime": "^7.20.13",
"@babel/types": "^7.20.7",
"@lingui/babel-plugin-extract-messages": "3.17.1",
"@lingui/conf": "3.17.1",
"@lingui/core": "3.17.1",
"@messageformat/parser": "^5.0.0",
"babel-plugin-macros": "^3.0.1",

@@ -87,3 +88,3 @@ "bcp-47": "^1.0.7",

"mockdate": "^3.0.2",
"typescript": "^4.0.3"
"typescript": "^4.9.5"
},

@@ -95,3 +96,3 @@ "peerDependencies": {

},
"gitHead": "1c8bc46213b35b25da8fe7a80ddcf6f6a5d9d539"
"gitHead": "76ef4e8d1c668578ce2c3829ebf35d22ca5e679c"
}
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