🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

gettext-utils

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gettext-utils - npm Package Compare versions

Comparing version

to
1.2.0

__fixtures__/react-project-updated/src/components/LionessHocComponent.tsx

5

.vscode/settings.json

@@ -7,3 +7,6 @@ {

"tslint.autoFixOnSave": true,
"editor.formatOnSave": true
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.tslint": true
}
}

2

definitions/gettext-parser.d.ts

@@ -12,3 +12,3 @@ interface Translation {

msgid_plural?: string;
msgctxt: string;
msgctxt?: string;
msgstr?: string[];

@@ -15,0 +15,0 @@ comments?: {

@@ -12,2 +12,33 @@ declare module "react-gettext-parser" {

): void;
export function extractMessagesFromGlob(
path: string[],
options: {
output?: string;
funcArgumentsMap?: Object;
componentPropsMap?: Object;
transformHeaders?(headers: Object): Object;
},
): {
msgid: string;
msgid_plural?: string;
msgctxt: string;
msgstr?: string[];
comments?: {
reference: string;
};
}[];
export function toPot(
messages: {
msgid: string;
msgid_plural?: string;
msgctxt: string;
msgstr?: string[];
comments?: {
reference: string;
};
}[],
options?: {
transformHeaders?(headers: Object): Object;
},
): string;
}
{
"name": "gettext-utils",
"version": "1.1.2",
"version": "1.2.0",
"description": "A set of utils to parse react files and export .po files and import them back",

@@ -51,17 +51,17 @@ "bin": "src/cli.js",

"@types/fs-extra": "^5.0.5",
"@types/jest": "^23.3.13",
"@types/yargs": "^12.0.9",
"@types/jest": "^24.0.11",
"@types/yargs": "^12.0.10",
"concurrently": "^4.1.0",
"coveralls": "^3.0.3",
"jest": "^23.6.0",
"jest": "^24.5.0",
"lioness": "^0.2.13",
"nodemon": "^1.18.10",
"prettier-config-trucknet-io": "^2.0.1",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"rimraf": "^2.6.3",
"trucknet-commit": "^1.4.3",
"ts-jest": "^23.10.3",
"tslint": "^5.12.1",
"tslint-config-trucknet-io": "^1.4.0"
"ts-jest": "^24.0.0",
"tslint": "^5.14.0",
"tslint-config-trucknet-io": "^1.5.0"
},

@@ -73,11 +73,11 @@ "_moduleAliases": {

"@types/glob": "^7.1.1",
"@types/node": "^10.12.21",
"@types/node": "^10.14.1",
"fs-extra": "^7.0.1",
"gettext-parser": "^3.1.0",
"gettext-parser": "^3.1.1",
"glob": "^7.1.3",
"module-alias": "^2.1.0",
"react-gettext-parser": "^1.8.2",
"typescript": "^3.3.1",
"yargs": "^13.2.1"
"module-alias": "^2.2.0",
"react-gettext-parser": "^1.9.0",
"typescript": "^3.3.4000",
"yargs": "^13.2.2"
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = require("fs-extra");
const gettext_parser_1 = require("gettext-parser");
const path = require("path");
const react_gettext_parser_1 = require("react-gettext-parser");
const util_1 = require("util");
const lioness_config_1 = require("./config/lioness.config");
const importStrings_1 = require("./importStrings");
const updateTranslations_1 = require("./updateTranslations");
const parseGlobPromisified = util_1.promisify(react_gettext_parser_1.parseGlob);
const encoding = "utf-8";
const getPackageNameAndVersion = async () => {
try {
const packageJsonPath = path.join(process.cwd(), "package.json");
const packageJson = JSON.parse(await fs_extra_1.readFile(packageJsonPath, encoding));
return `${packageJson.name} ${packageJson.version}`;
}
catch (e) {
return false;
}
};
const arePotsDifferent_1 = require("./utils/arePotsDifferent");
const packageInfo_1 = require("./utils/packageInfo");
const exportStrings = async (inputFilesGlob, templateFilePath, defaultLocale) => {
const templateDirPath = path.dirname(templateFilePath);
const packageName = await getPackageNameAndVersion();
await fs_extra_1.mkdirp(templateDirPath);
await parseGlobPromisified([inputFilesGlob], Object.assign({ output: templateFilePath, transformHeaders: packageName
? (x) => (Object.assign({ "Project-Id-Version": packageName }, x))
: (x) => x }, lioness_config_1.default));
const templatePot = await getUpdatedTemplateContents(inputFilesGlob, templateFilePath);
if (!templatePot) {
return;
}
await fs_extra_1.writeFile(templateFilePath, templatePot, "utf-8");
await updateTranslations_1.default(templateDirPath, templateFilePath, defaultLocale);
};
const getUpdatedTemplateContents = async (inputFilesGlob, templateFilePath) => {
const packageName = await packageInfo_1.getPackageNameAndVersion();
const newMessages = react_gettext_parser_1.extractMessagesFromGlob([inputFilesGlob], lioness_config_1.default);
const newPot = react_gettext_parser_1.toPot(newMessages, {
transformHeaders: packageName
? (x) => (Object.assign({ "Project-Id-Version": packageName }, x))
: (x) => x,
});
const oldTemplateExists = fs_extra_1.existsSync(templateFilePath);
if (!oldTemplateExists) {
return newPot;
}
const oldPotParsed = await importStrings_1.getPoParsed(templateFilePath);
const newPotParsed = gettext_parser_1.po.parse(newPot);
if (!arePotsDifferent_1.default(newPotParsed, oldPotParsed)) {
return;
}
return newPot;
};
exports.default = exportStrings;
//# sourceMappingURL=exportStrings.js.map

@@ -1,36 +0,37 @@

import { mkdirp, readFile } from "fs-extra";
import { existsSync, mkdirp, writeFile } from "fs-extra";
import { po } from "gettext-parser";
import * as path from "path";
import { parseGlob } from "react-gettext-parser";
import { promisify } from "util";
import { extractMessagesFromGlob, toPot } from "react-gettext-parser";
import lionessConfig from "./config/lioness.config";
import { getPoParsed } from "./importStrings";
import updateTranslations from "./updateTranslations";
import arePotsDifferent from "./utils/arePotsDifferent";
import { getPackageNameAndVersion } from "./utils/packageInfo";
const parseGlobPromisified = promisify(parseGlob);
const encoding = "utf-8";
const exportStrings = async (
inputFilesGlob: string,
templateFilePath: string,
defaultLocale?: string,
) => {
const templateDirPath = path.dirname(templateFilePath);
const getPackageNameAndVersion = async () => {
try {
const packageJsonPath = path.join(process.cwd(), "package.json");
const packageJson = JSON.parse(
await readFile(packageJsonPath, encoding),
) as {
name?: string;
version?: string;
};
return `${packageJson.name} ${packageJson.version}`;
} catch (e) {
return false;
await mkdirp(templateDirPath);
const templatePot = await getUpdatedTemplateContents(
inputFilesGlob,
templateFilePath,
);
if (!templatePot) {
return;
}
await writeFile(templateFilePath, templatePot, "utf-8");
await updateTranslations(templateDirPath, templateFilePath, defaultLocale);
};
const exportStrings = async (
const getUpdatedTemplateContents = async (
inputFilesGlob: string,
templateFilePath: string,
defaultLocale?: string,
) => {
const templateDirPath = path.dirname(templateFilePath);
): Promise<string | undefined> => {
const packageName = await getPackageNameAndVersion();
await mkdirp(templateDirPath);
await parseGlobPromisified([inputFilesGlob], {
output: templateFilePath,
const newMessages = extractMessagesFromGlob([inputFilesGlob], lionessConfig);
const newPot = toPot(newMessages, {
transformHeaders: packageName

@@ -42,7 +43,15 @@ ? (x) => ({

: (x) => x,
...lionessConfig,
});
await updateTranslations(templateDirPath, templateFilePath, defaultLocale);
const oldTemplateExists = existsSync(templateFilePath);
if (!oldTemplateExists) {
return newPot;
}
const oldPotParsed = await getPoParsed(templateFilePath);
const newPotParsed = po.parse(newPot);
if (!arePotsDifferent(newPotParsed, oldPotParsed)) {
return;
}
return newPot;
};
export default exportStrings;

Sorry, the diff of this file is not supported yet