@formatjs/cli-lib 8.0.8 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +7 -7
- package/index.js +2 -2
- package/main.d.ts +0 -1
- package/main.js +1 -1
- package/package.json +5 -5
- package/src/cli.js +99 -153
- package/src/compile.d.ts +45 -45
- package/src/compile.js +79 -80
- package/src/compile_folder.d.ts +1 -1
- package/src/compile_folder.js +6 -6
- package/src/console_utils.d.ts +3 -1
- package/src/console_utils.js +44 -46
- package/src/extract.d.ts +68 -68
- package/src/extract.js +165 -182
- package/src/formatters/crowdin.d.ts +3 -3
- package/src/formatters/crowdin.js +19 -20
- package/src/formatters/default.d.ts +1 -1
- package/src/formatters/default.js +8 -7
- package/src/formatters/index.d.ts +6 -6
- package/src/formatters/index.js +29 -34
- package/src/formatters/lokalise.d.ts +5 -5
- package/src/formatters/lokalise.js +16 -17
- package/src/formatters/simple.d.ts +1 -1
- package/src/formatters/simple.js +7 -6
- package/src/formatters/smartling.d.ts +13 -15
- package/src/formatters/smartling.js +35 -40
- package/src/formatters/transifex.d.ts +5 -5
- package/src/formatters/transifex.js +16 -17
- package/src/gts_extractor.js +11 -11
- package/src/hbs_extractor.js +34 -41
- package/src/parse_script.d.ts +5 -5
- package/src/parse_script.js +40 -43
- package/src/pseudo_locale.d.ts +15 -15
- package/src/pseudo_locale.js +210 -94
- package/src/verify/checkExtraKeys.js +28 -32
- package/src/verify/checkMissingKeys.js +29 -33
- package/src/verify/checkStructuralEquality.js +67 -71
- package/src/verify/index.d.ts +5 -5
- package/src/verify/index.js +24 -27
- package/src/vue_extractor.js +52 -62
|
@@ -1,44 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
? msg.description
|
|
20
|
-
: JSON.stringify(msg.description),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return results;
|
|
1
|
+
import "./default.js";
|
|
2
|
+
export const format = (msgs) => {
|
|
3
|
+
const results = { smartling: {
|
|
4
|
+
translate_paths: [{
|
|
5
|
+
path: "*/message",
|
|
6
|
+
key: "{*}/message",
|
|
7
|
+
instruction: "*/description"
|
|
8
|
+
}],
|
|
9
|
+
variants_enabled: true,
|
|
10
|
+
string_format: "icu"
|
|
11
|
+
} };
|
|
12
|
+
for (const [id, msg] of Object.entries(msgs)) {
|
|
13
|
+
results[id] = {
|
|
14
|
+
message: msg.defaultMessage,
|
|
15
|
+
description: typeof msg.description === "string" ? msg.description : JSON.stringify(msg.description)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return results;
|
|
24
19
|
};
|
|
25
20
|
export const compareMessages = (el1, el2) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
// `smartling` has to be the 1st key
|
|
22
|
+
if (el1.key === "smartling") {
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
if (el2.key === "smartling") {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
|
|
34
29
|
};
|
|
35
|
-
export const compile = msgs => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
export const compile = (msgs) => {
|
|
31
|
+
const results = {};
|
|
32
|
+
for (const [id, msg] of Object.entries(msgs)) {
|
|
33
|
+
if (id === "smartling") {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
results[id] = msg.message;
|
|
37
|
+
}
|
|
38
|
+
return results;
|
|
44
39
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CompileFn, FormatFn } from
|
|
1
|
+
import { type CompileFn, type FormatFn } from "./default.js";
|
|
2
2
|
export type StructuredJson = Record<string, {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
string: string;
|
|
4
|
+
developer_comment?: string;
|
|
5
|
+
context?: string;
|
|
6
|
+
character_limit?: string;
|
|
7
7
|
}>;
|
|
8
8
|
export declare const format: FormatFn<StructuredJson>;
|
|
9
9
|
export declare const compile: CompileFn<StructuredJson>;
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return results;
|
|
1
|
+
import "./default.js";
|
|
2
|
+
export const format = (msgs) => {
|
|
3
|
+
const results = {};
|
|
4
|
+
for (const [id, msg] of Object.entries(msgs)) {
|
|
5
|
+
results[id] = {
|
|
6
|
+
string: msg.defaultMessage,
|
|
7
|
+
developer_comment: typeof msg.description === "string" ? msg.description : JSON.stringify(msg.description)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
return results;
|
|
12
11
|
};
|
|
13
|
-
export const compile = msgs => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
export const compile = (msgs) => {
|
|
13
|
+
const results = {};
|
|
14
|
+
for (const [id, msg] of Object.entries(msgs)) {
|
|
15
|
+
results[id] = msg.string;
|
|
16
|
+
}
|
|
17
|
+
return results;
|
|
19
18
|
};
|
package/src/gts_extractor.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Preprocessor } from
|
|
2
|
-
import { parseFile as parseHbsFile } from
|
|
3
|
-
import { parseScript } from
|
|
1
|
+
import { Preprocessor } from "content-tag";
|
|
2
|
+
import { parseFile as parseHbsFile } from "./hbs_extractor.js";
|
|
3
|
+
import { parseScript } from "./parse_script.js";
|
|
4
4
|
let p = new Preprocessor();
|
|
5
5
|
export function parseFile(source, fileName, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const scriptParseFn = parseScript(options, fileName);
|
|
7
|
+
const transformedSource = p.process(source, { filename: fileName });
|
|
8
|
+
scriptParseFn(transformedSource.code);
|
|
9
|
+
// extract template from transformed source to then run through hbs processor
|
|
10
|
+
const parseResult = p.parse(source, { filename: fileName });
|
|
11
|
+
for (let parsed of parseResult) {
|
|
12
|
+
parseHbsFile(parsed.contents, fileName, options);
|
|
13
|
+
}
|
|
14
14
|
}
|
package/src/hbs_extractor.js
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "@formatjs/ts-transformer";
|
|
2
|
+
import { transform } from "ember-template-recast";
|
|
2
3
|
function extractText(node, fileName, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
options.onMsgExtracted(fileName, [
|
|
23
|
-
{
|
|
24
|
-
id: id,
|
|
25
|
-
defaultMessage: defaultMessage,
|
|
26
|
-
description: desc,
|
|
27
|
-
},
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
4
|
+
if (!options.onMsgExtracted) return;
|
|
5
|
+
if (!options.overrideIdFn) return;
|
|
6
|
+
if (node.path.type !== "PathExpression") return;
|
|
7
|
+
if (["format-message", "formatMessage"].includes(node.path.original)) {
|
|
8
|
+
let [first, second] = node.params;
|
|
9
|
+
if (first.type !== "StringLiteral") return;
|
|
10
|
+
let message = first?.value;
|
|
11
|
+
let desc;
|
|
12
|
+
if (second?.type === "StringLiteral") {
|
|
13
|
+
desc = second.value?.trim().replace(/\s+/gm, " ");
|
|
14
|
+
}
|
|
15
|
+
let defaultMessage = message?.trim().replace(/\s+/gm, " ");
|
|
16
|
+
let id = typeof options.overrideIdFn === "string" ? options.overrideIdFn : options.overrideIdFn(undefined, defaultMessage, desc, fileName);
|
|
17
|
+
options.onMsgExtracted(fileName, [{
|
|
18
|
+
id,
|
|
19
|
+
defaultMessage,
|
|
20
|
+
description: desc
|
|
21
|
+
}]);
|
|
22
|
+
}
|
|
30
23
|
}
|
|
31
24
|
export function parseFile(source, fileName, options) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
let visitor = function() {
|
|
26
|
+
return {
|
|
27
|
+
MustacheStatement(node) {
|
|
28
|
+
extractText(node, fileName, options);
|
|
29
|
+
},
|
|
30
|
+
SubExpression(node) {
|
|
31
|
+
extractText(node, fileName, options);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
// SAFETY: ember-template-recast's types are out of date,
|
|
36
|
+
// but it does not affect runtime
|
|
37
|
+
transform(source, visitor);
|
|
45
38
|
}
|
package/src/parse_script.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Opts } from
|
|
1
|
+
import { type Opts } from "@formatjs/ts-transformer";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* Invoid TypeScript module transpilation with our TS transformer
|
|
4
|
+
* @param opts Formatjs TS Transformer opt
|
|
5
|
+
* @param fn filename
|
|
6
|
+
*/
|
|
7
7
|
export declare function parseScript(opts: Opts, fn?: string): (source: string) => void;
|
package/src/parse_script.js
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
import { transformWithTs } from
|
|
2
|
-
import * as ts from
|
|
3
|
-
import { debug } from
|
|
1
|
+
import { transformWithTs } from "@formatjs/ts-transformer";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import { debug } from "./console_utils.js";
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
* Invoid TypeScript module transpilation with our TS transformer
|
|
6
|
+
* @param opts Formatjs TS Transformer opt
|
|
7
|
+
* @param fn filename
|
|
8
|
+
*/
|
|
9
9
|
export function parseScript(opts, fn) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
10
|
+
return (source) => {
|
|
11
|
+
let output;
|
|
12
|
+
try {
|
|
13
|
+
debug("Using TS compiler to process file", fn);
|
|
14
|
+
output = ts.transpileModule(source, {
|
|
15
|
+
compilerOptions: {
|
|
16
|
+
allowJs: true,
|
|
17
|
+
target: ts.ScriptTarget.ESNext,
|
|
18
|
+
noEmit: true,
|
|
19
|
+
experimentalDecorators: true
|
|
20
|
+
},
|
|
21
|
+
reportDiagnostics: true,
|
|
22
|
+
fileName: fn,
|
|
23
|
+
transformers: { before: [transformWithTs(ts, opts)] }
|
|
24
|
+
});
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if (e instanceof Error) {
|
|
27
|
+
e.message = `Error processing file ${fn}
|
|
28
|
+
${e.message || ""}`;
|
|
29
|
+
}
|
|
30
|
+
throw e;
|
|
31
|
+
}
|
|
32
|
+
if (output.diagnostics) {
|
|
33
|
+
const errs = output.diagnostics.filter((d) => d.category === ts.DiagnosticCategory.Error);
|
|
34
|
+
if (errs.length) {
|
|
35
|
+
throw new Error(ts.formatDiagnosticsWithColorAndContext(errs, {
|
|
36
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
37
|
+
getCurrentDirectory: () => process.cwd(),
|
|
38
|
+
getNewLine: () => ts.sys.newLine
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
46
43
|
}
|
package/src/pseudo_locale.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { MessageFormatElement } from
|
|
1
|
+
import { type MessageFormatElement } from "@formatjs/icu-messageformat-parser";
|
|
2
2
|
export declare function generateXXLS(msg: string | MessageFormatElement[]): MessageFormatElement[];
|
|
3
3
|
export declare function generateXXAC(msg: string | MessageFormatElement[]): MessageFormatElement[];
|
|
4
4
|
export declare function generateXXHA(msg: string | MessageFormatElement[]): MessageFormatElement[];
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
* accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
|
|
7
|
+
* --------------------------------
|
|
8
|
+
*
|
|
9
|
+
* This locale replaces all Latin characters with their accented equivalents, and duplicates some
|
|
10
|
+
* vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
|
|
11
|
+
* which help with detecting truncation.
|
|
12
|
+
*/
|
|
13
13
|
export declare function generateENXA(msg: string | MessageFormatElement[]): MessageFormatElement[];
|
|
14
14
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
* bidi - ɥsıʅƃuƎ ıpıԐ
|
|
16
|
+
* -------------------
|
|
17
|
+
*
|
|
18
|
+
* This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
|
|
19
|
+
* right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
|
|
20
|
+
* directionality will also be set to right-to-left.
|
|
21
|
+
*/
|
|
22
22
|
export declare function generateENXB(msg: string | MessageFormatElement[]): MessageFormatElement[];
|