Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,047 changes: 10,643 additions & 12,404 deletions package-lock.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OMG the diff size!

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@types/babel__traverse": "^7.0.15",
"@types/chalk": "^2.2.0",
"@types/estree": "0.0.44",
"@types/is-glob": "^4.0.4",
"@types/jest": "21.1.6",
"@types/koa": "^2.0.49",
"@types/koa-router": "^7.0.42",
Expand All @@ -49,12 +50,12 @@
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-react-compiler": "^19.1.0-rc.2",
"husky": "^0.14.3",
"jest": "^24.9.0",
"jest": "^30.2.0",
"lint-staged": "^5.0.0",
"prettier": "^1.19.1",
"ts-jest": "^26.3.0",
"ts-jest": "^29.4.6",
"ts-node": "3.3.0",
"typescript": "^3.9.7"
"typescript": "^4.3"
Comment on lines +53 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These may be good changes, but they are strictly unrelated.

Copy link
Author

@aperkaz aperkaz Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the description, the glob package required a higher version of typescript, thus creating a chain reaction that required updating jest too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh... I would personally prefer dependency bumps to be a separate PR, but then again I'm not the owner of this project, maybe they think it's OK.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the value of splitting it into multiple PRs but would appreciate the input of someone with merge and publish privileges.

If you have the rights @dimaqq, I will get right into it 🙂

},
"dependencies": {
"@babel/core": "^7.12.3",
Expand All @@ -77,8 +78,10 @@
"cross-spawn": "^5.1.0",
"estree-walker": "^2.0.1",
"gettext-parser": "^6.0.0",
"glob": "13.0.0",
"hunspell-spellchecker": "^1.0.2",
"ignore": "^5.1.8",
"is-glob": "4.0.3",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-router": "^9.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { extractAll } from "../lib/extract";
import { checkDuplicateKeys } from "../lib/checkDuplicateKeys";
import * as c3poTypes from "../types";
import { parse, PoData } from "../lib/parser";
import { resolvePaths } from "../lib/utils";

/*
Run any string in stream through warning first
Expand Down Expand Up @@ -61,12 +62,15 @@ Check all keys from pots(keys only files) are present in pofile(files with trans
*/
async function check(
pofile: string,
paths: string[],
src: string[],
ignore: string[] | string | undefined,
lang: string,
overrideOpts?: c3poTypes.TtagOpts,
ttagRcOpts?: c3poTypes.TtagRc,
skip?: "translation"
) {
const paths = resolvePaths(src, ignore);

const progress: c3poTypes.Progress = ora(
`[ttag] checking translations from ${paths} ...`
);
Expand Down
7 changes: 5 additions & 2 deletions src/commands/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import * as ora from "ora";
import * as fs from "fs";
import * as c3poTypes from "../types";
import { extractAll } from "../lib/extract";
import { resolvePaths } from "../lib/utils";

async function extract(
output: string,
paths: string[],
src: string[],
ignore: string[] | string | undefined,
lang: string = "en",
ttagOverrideOpts?: c3poTypes.TtagOpts,
ttagRcOpts?: c3poTypes.TtagRc
) {
const progress: c3poTypes.Progress = ora(
`[ttag] extracting translations to ${output} ...`
);

progress.start();
const result = await extractAll(
paths,
resolvePaths(src, ignore),
lang,
progress,
ttagOverrideOpts,
Expand Down
12 changes: 11 additions & 1 deletion src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,30 @@ import { updatePo } from "../lib/update";
import { parse } from "../lib/parser";
import { serialize, SerializeOptions } from "../lib/serializer";
import { checkDuplicateKeys } from "../lib/checkDuplicateKeys";
import { resolvePaths } from "../lib/utils";

async function update(
pofile: string,
src: string[],
ignore: string[] | string | undefined,
lang: string,
ttagOverrideOpts?: ttagTypes.TtagOpts,
ttagRcOpts?: ttagTypes.TtagRc,
serializeOpts?: SerializeOptions
) {
const paths = resolvePaths(src, ignore);

const progress: ttagTypes.Progress = ora(`[ttag] updating ${pofile} ...`);
progress.start();
try {
const pot = parse(
await extractAll(src, lang, progress, ttagOverrideOpts, ttagRcOpts)
await extractAll(
paths,
lang,
progress,
ttagOverrideOpts,
ttagRcOpts
)
);
const errMessage = checkDuplicateKeys(pot);

Expand Down
29 changes: 28 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,22 @@ yargs
default: "en",
description: "sets default lang (ISO format)"
},
src: {
description:
"path to source files/directories (supports glob, but needs to be quoted)"
},
ignore: {
alias: "i",
description:
"paths to ignore (supports glob, but needs to be quoted)"
},
...getTtagOptsForYargs()
},
argv => {
extract(
argv.output,
argv.src,
argv.ignore,
argv.lang,
parseTtagPluginOpts(argv),
parseTtagRcOpts()
Expand All @@ -110,12 +120,22 @@ yargs
choices: ["translation"],
default: undefined
},
src: {
description:
"path to source files/directories (supports glob, but needs to be quoted)"
},
ignore: {
alias: "i",
description:
"paths to ignore (supports glob, but needs to be quoted)"
},
...getTtagOptsForYargs()
},
argv => {
check(
argv.pofile,
argv.src,
argv.ignore,
argv.lang,
parseTtagPluginOpts(argv),
parseTtagRcOpts(),
Expand Down Expand Up @@ -226,7 +246,13 @@ yargs
description: "path to .po file with translations"
},
src: {
description: "path to source files/directories"
description:
"path to source files/directories (supports glob, but needs to be quoted)"
},
ignore: {
alias: "i",
description:
"paths to ignore (supports glob, but needs to be quoted)"
},
...getTtagOptsForYargs(),
foldLength: {
Expand All @@ -238,6 +264,7 @@ yargs
update(
argv.pofile,
argv.src,
argv.ignore,
argv.lang,
parseTtagPluginOpts(argv),
parseTtagRcOpts(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pathsWalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function walkDir(
walkFile(path.join(root, fileState.name), progress, transformFn);
next();
});
return new Promise(res => {
return new Promise<void>(res => {
walker.on("end", () => res());
});
}
Expand Down
41 changes: 41 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Translations, Message, PoData, PoDataCompact } from "./parser";
import generate from "@babel/generator";
import { Node } from "@babel/types";
import { globSync } from "glob";
import * as fs from "fs";
const isGlob = require("is-glob");

const pluralNumRegex = /^nplurals ?= ?(\d);/;

Expand Down Expand Up @@ -70,3 +73,41 @@ export function convert2Compact(poData: PoData): PoDataCompact {
delete compactPo.contexts[""][""];
return compactPo;
}

/**
* Helper function that calculates all the file paths from a src array with optional ignore paths.
* The folder paths are ignored, since further directory traversing is not necessary.
*/
export function resolvePaths(
/** Regular paths or globs */
src: string[],
/**
* Could be a string or an array of strings, depending on how many paths are passed by the cli.
*
* `--ignore path1` => 'path1'
*
* `--ignore path1 --ignore path2` => ['path1', 'path2']
*/
ignore?: string | string[]
): string[] {
const toGlob = (path: string): string => {
if (fs.lstatSync(path).isDirectory()) {
if !path.endsWith("/") { path = `${path}/`; }
return `${path}**/*`;
} else {
return path;
}
};

/** All paths are internally transformed to globs, to keep backwards compatibility with 'src' paths */
const srcGlob = src.map(path => (isGlob(path) ? path : toGlob(path)));
const ignoreGlob =
if (typeof ignore === "string") { ignore = [ignore]; }
ignoreGlob = ignore?.map(path => (isGlob(path) ? path : toGlob(path)));

return globSync(srcGlob, {
absolute: true,
nodir: true,
ignore: ignoreGlob
});
}
6 changes: 5 additions & 1 deletion tests/commands/__snapshots__/test_check.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`check from glob source 1`] = `""`;

exports[`check from glob source with ignore 1`] = `""`;

exports[`check when all string are translated 1`] = `""`;
10 changes: 5 additions & 5 deletions tests/commands/__snapshots__/test_color.ts.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`colorize test file 1`] = `
"msgid \\"\\"
msgstr \\"\\"
"msgid ""
msgstr ""
Content-Type: text/plain; charset=utf-8
Plural-Forms: nplurals=2; plural=(n!=1);

#: tests/fixtures/checkTest/check-trans-exist.js:2
#, fuzzy
msgid \\"test_fuzzy_ref_check\\"
msgstr \\"ffff\\"
msgid "test_fuzzy_ref_check"
msgstr "ffff"

"
`;
Loading