Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- uses: actions/setup-node@v4
- uses: actions/setup-node@v6
with:
node-version: 24

Expand Down
29,194 changes: 13,401 additions & 15,793 deletions package-lock.json

Large diffs are not rendered by default.

71 changes: 41 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,68 +34,79 @@
"@types/babel__traverse": "^7.0.15",
"@types/chalk": "^2.2.0",
"@types/estree": "0.0.44",
"@types/jest": "21.1.6",
"@types/jest": "^30.0.0",
"@types/koa": "^2.0.49",
"@types/koa-router": "^7.0.42",
"@types/mkdirp": "^0.5.2",
"@types/node": "^12.12.6",
"@types/node": "^20.19.40",
"@types/node-fetch": "^1.6.7",
"@types/ora": "1.3.1",
"@types/readline-sync": "^1.4.2",
"@types/serialize-javascript": "^1.5.0",
"@types/tmp": "^0.0.33",
"@types/walk": "^2.3.0",
"@types/yargs": "8.0.2",
"@types/yargs": "^17.0.35",
"babel-core": "^7.0.0-bridge.0",
"babel-plugin-react-compiler": "^19.1.0-rc.2",
"husky": "^0.14.3",
"jest": "^24.9.0",
"lint-staged": "^5.0.0",
"jest": "^30.4.2",
"lint-staged": "^17.0.4",
"prettier": "^1.19.1",
"ts-jest": "^26.3.0",
"ts-node": "3.3.0",
"typescript": "^3.9.7"
"ts-jest": "^29.4.9",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"dependencies": {
"@babel/core": "^7.12.3",
"@babel/generator": "^7.12.5",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-decorators": "^7.12.1",
"@babel/plugin-proposal-export-default-from": "^7.12.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "7.6.0",
"@babel/core": "^7.29.0",
"@babel/generator": "^7.29.1",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.29.0",
"@babel/plugin-proposal-export-default-from": "^7.27.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.12.1",
"@babel/preset-flow": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/preset-typescript": "7.7.0",
"@babel/template": "^7.10.4",
"@babel/preset-env": "^7.29.5",
"@babel/preset-flow": "^7.27.1",
"@babel/preset-react": "^7.28.5",
"@babel/preset-typescript": "^7.28.5",
"@babel/template": "^7.28.6",
"babel-plugin-ttag": "1.8.16",
"babel-preset-const-enum": "^1.0.0",
"chalk": "^2.4.2",
"cross-spawn": "^5.1.0",
"cross-spawn": "^7.0.6",
"estree-walker": "^2.0.1",
"gettext-parser": "^6.0.0",
"hunspell-spellchecker": "^1.0.2",
"ignore": "^5.1.8",
"koa": "^2.13.0",
"koa-body": "^4.2.0",
"koa-router": "^9.1.0",
"koa": "^2.16.4",
"koa-body": "^7.0.1",
"koa-router": "^14.0.0",
"mkdirp": "^0.5.1",
"node-fetch": "^2.6.1",
"node-fetch": "^2.7.0",
"open": "^6.4.0",
"ora": "1.3.0",
"plural-forms": "0.5.3",
"readline-sync": "^1.4.7",
"serialize-javascript": "^4.0.0",
"svelte": "^3.20.1",
"tmp": "0.0.33",
"serialize-javascript": "^7.0.5",
"svelte": "^5.55.5",
"tmp": "^0.2.5",
"vue-sfc-parser": "^0.1.2",
"walk": "2.3.9",
"yargs": "^15.4.1"
"yargs": "^16.2.0"
},
"overrides": {
"@babel/runtime": "^7.29.1",
"ajv": "^6.15.0",
"brace-expansion": "^1.1.13",
"js-yaml": "^3.14.2",
"yaml": "^1.10.3"
},
"jest": {
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
},
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
Expand Down
2 changes: 1 addition & 1 deletion src/commands/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function replace(
progress.fail("Failed to replace");
return;
}
fs.writeFileSync(resultPath, result.code);
fs.writeFileSync(resultPath, result.code || "");
};

await pathsWalk([srcPath], progress, transformFn);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import openBrowser from "../lib/browser";
import * as Application from "koa";
import * as Router from "koa-router";
import * as koaBody from "koa-body";
import { koaBody } from "koa-body";
import * as fs from "fs";

async function editor(ctx: Application.Context) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export default function translate(path: string) {
}

async function save(ctx: Application.Context) {
const translatedData = ctx.request.body;
const translatedData = String(ctx.request.body || "");
fs.writeFileSync(path, translatedData);
ctx.body = "ok";
ctx.status = 200;
Expand Down
43 changes: 24 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ yargs
},
...getTtagOptsForYargs()
},
argv => {
(argv: any) => {
extract(
argv.output,
argv.src,
Expand All @@ -112,7 +112,7 @@ yargs
},
...getTtagOptsForYargs()
},
argv => {
(argv: any) => {
check(
argv.pofile,
argv.src,
Expand All @@ -127,7 +127,7 @@ yargs
"merge <path...>",
"will merge two or more po(t) files together using first non-empty msgstr and header from left-most file",
{},
argv => {
(argv: any) => {
merge(argv.path);
}
)
Expand All @@ -141,15 +141,15 @@ yargs
description: "result file with translations (.po)"
}
},
argv => {
(argv: any) => {
translate(argv.path, argv.output);
}
)
.command(
"stats <path>",
"will display various pofile statistics(encoding, plurals, translated, fuzzyness)",
{},
argv => {
(argv: any) => {
stats(argv.path);
}
)
Expand Down Expand Up @@ -187,7 +187,7 @@ yargs
default: ""
}
},
argv => {
(argv: any) => {
filter(
argv.path,
argv.fuzzy,
Expand All @@ -210,7 +210,7 @@ yargs
description: "path to the .po file"
}
},
argv => {
(argv: any) => {
init(argv.lang, argv.filename);
}
)
Expand All @@ -234,7 +234,7 @@ yargs
number: true
}
},
argv => {
(argv: any) => {
update(
argv.pofile,
argv.src,
Expand All @@ -251,7 +251,7 @@ yargs
"replace [options] <pofile> <out> <path>",
"will replace all strings with translations from the .po file",
{ ...getTtagOptsForYargs() },
argv => {
(argv: any) => {
replace(
argv.pofile,
argv.out,
Expand All @@ -264,7 +264,7 @@ yargs
"color <pofile>",
"will output po(t)file with pretty colors on, combine with | less -r",
{},
argv => {
(argv: any) => {
color(argv.pofile);
}
)
Expand All @@ -278,29 +278,34 @@ yargs
description: "result file with pseudo translations (.po)"
}
},
argv => {
(argv: any) => {
pseudo(argv.path, argv.output);
}
)
.command(
"spell <pofile> [locale]",
"will spellcheck po file messages with given locale, locale can be autodetected from pofile",
{},
argv => {
(argv: any) => {
spell(argv.pofile, argv.locale);
}
)
.command(
"validate <pofile>",
"will validate js template strings (`${x}`) in messages and translations and against each other",
{},
argv => {
(argv: any) => {
validate(argv.pofile);
}
)
.command("web <pofile>", "will open pofile in web editor", {}, argv => {
web(argv.pofile);
})
.command(
"web <pofile>",
"will open pofile in web editor",
{},
(argv: any) => {
web(argv.pofile);
}
)
.command(
"po2json <pofile> [args]",
"will parse and output po file as loadable JSON",
Expand All @@ -324,11 +329,11 @@ yargs
default: "verbose"
}
},
argv => {
(argv: any) => {
po2js(argv.pofile, argv.pretty, argv.nostrip, argv.format);
}
)
.command("doc", false, {}, _ => {
.command("doc", false, {}, (_: any) => {
const isIgnored = (c: string) =>
c == "doc" || c == "completion" || c == "$0";
const printOption = (name: string, option: Options) => {
Expand Down Expand Up @@ -370,7 +375,7 @@ yargs
);
}
})
.command("*", "", {}, argv => {
.command("*", "", {}, (argv: any) => {
const possibleCommand = commands.find(s => s.startsWith(argv._[0]));
if (possibleCommand) {
process.stdout.write(`Did you mean ${possibleCommand}? \n`);
Expand Down
10 changes: 6 additions & 4 deletions src/lib/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { parseComponent } from "vue-sfc-parser";
import { walk } from "estree-walker";
import { parse as parseSvelte } from "svelte/compiler";
import ignore from "ignore";
import { TemplateNode } from "svelte/types/compiler/interfaces";
import { makeBabelConf } from "../defaults";
import * as ttagTypes from "../types";
import { TransformFn, pathsWalk } from "./pathsWalk";
import { mergeOpts } from "./ttagPluginOverride";

type TemplateNode = any;

export async function extractAll(
paths: string[],
lang: string,
Expand Down Expand Up @@ -111,10 +112,11 @@ export async function extractAll(
babel.transformFileSync(filepath, babelOptions);
}
} catch (err) {
if (err.codeFrame) {
console.error(err.codeFrame);
const error = err as any;
if (error.codeFrame) {
console.error(error.codeFrame);
} else {
console.error(err);
console.error(error);
}
progress.fail("Failed to extract translations");
process.exit(1);
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
2 changes: 1 addition & 1 deletion src/lib/ttagPluginOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function parseTtagPluginOpts(
pluginOpts.forEach(opt => {
if (!argv[opt]) return;
if (opt === "discover") {
extendedOpts[opt] = parseDiscover(argv[opt]);
extendedOpts[opt] = parseDiscover(argv[opt] as string | string[]);
} else if (opt === "numberedExpressions") {
extendedOpts[opt] = Boolean(argv[opt]);
} else if (opt === "extractLocation") {
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_check.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

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

exports[`colorize test file 1`] = `
"msgid \\"\\"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_extract.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`extract base case 1`] = `
"msgid \\"\\"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_init.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`should init en locale 1`] = `
"msgid \\"\\"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_merge.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`merge two files together 1`] = `
"msgid \\"\\"
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_po2js.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`convert po to js 1`] = `"{\\"charset\\":\\"utf-8\\",\\"headers\\":{\\"Content-Type\\":\\"text/plain; charset=utf-8\\",\\"Plural-Forms\\":\\"nplurals=2; plural=(n!=1);\\"},\\"translations\\":{\\"\\":{\\"\\":{\\"msgid\\":\\"\\",\\"msgstr\\":[\\"Content-Type: text/plain; charset=utf-8\\\\nPlural-Forms: nplurals=2; plural=(n!=1);\\\\n\\"]},\\"test\\":{\\"msgid\\":\\"test\\",\\"msgstr\\":[\\"test translated\\"]}},\\"ctx1\\":{\\"test\\":{\\"msgid\\":\\"test\\",\\"msgctxt\\":\\"ctx1\\",\\"msgstr\\":[\\"test translated\\"]}},\\"ctx2\\":{\\"test\\":{\\"msgid\\":\\"test\\",\\"msgctxt\\":\\"ctx2\\",\\"msgstr\\":[\\"test translated\\"]}}}}"`;

Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_replace.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`replace translations 1`] = `
"\\"use strict\\";
Expand Down
2 changes: 1 addition & 1 deletion tests/commands/__snapshots__/test_spell.ts.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`find basic spelling error with locale autodetect 1`] = `
"msgid \\"test_incorrect_spelling\\"
Expand Down
Loading