@formatjs/cli-lib 7.0.2 → 7.1.0
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/lib_esnext/src/cli.js +21 -0
- package/lib_esnext/src/verify/checkMissingKeys.d.ts +1 -0
- package/lib_esnext/src/verify/checkMissingKeys.js +37 -0
- package/lib_esnext/src/verify/checkStructuralEquality.d.ts +1 -0
- package/lib_esnext/src/verify/checkStructuralEquality.js +56 -0
- package/lib_esnext/src/verify/index.d.ts +6 -0
- package/lib_esnext/src/verify/index.js +24 -0
- package/package.json +4 -4
- package/index.d.ts +0 -7
- package/index.js +0 -10
- package/main.d.ts +0 -2
- package/main.js +0 -4
- package/src/cli.d.ts +0 -2
- package/src/cli.js +0 -156
- package/src/compile.d.ts +0 -54
- package/src/compile.js +0 -95
- package/src/compile_folder.d.ts +0 -2
- package/src/compile_folder.js +0 -11
- package/src/console_utils.d.ts +0 -7
- package/src/console_utils.js +0 -76
- package/src/extract.d.ts +0 -74
- package/src/extract.js +0 -197
- package/src/formatters/crowdin.d.ts +0 -7
- package/src/formatters/crowdin.js +0 -27
- package/src/formatters/default.d.ts +0 -6
- package/src/formatters/default.js +0 -13
- package/src/formatters/index.d.ts +0 -9
- package/src/formatters/index.js +0 -40
- package/src/formatters/lokalise.d.ts +0 -9
- package/src/formatters/lokalise.js +0 -24
- package/src/formatters/simple.d.ts +0 -4
- package/src/formatters/simple.js +0 -12
- package/src/formatters/smartling.d.ts +0 -23
- package/src/formatters/smartling.js +0 -50
- package/src/formatters/transifex.d.ts +0 -9
- package/src/formatters/transifex.js +0 -24
- package/src/gts_extractor.d.ts +0 -1
- package/src/gts_extractor.js +0 -17
- package/src/hbs_extractor.d.ts +0 -1
- package/src/hbs_extractor.js +0 -48
- package/src/parse_script.d.ts +0 -7
- package/src/parse_script.js +0 -50
- package/src/pseudo_locale.d.ts +0 -22
- package/src/pseudo_locale.js +0 -122
- package/src/vue_extractor.d.ts +0 -2
- package/src/vue_extractor.js +0 -71
package/src/extract.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { MessageDescriptor, Opts } from '@formatjs/ts-transformer';
|
|
2
|
-
import { Formatter } from './formatters';
|
|
3
|
-
export interface ExtractionResult<M = Record<string, string>> {
|
|
4
|
-
/**
|
|
5
|
-
* List of extracted messages
|
|
6
|
-
*/
|
|
7
|
-
messages: MessageDescriptor[];
|
|
8
|
-
/**
|
|
9
|
-
* Metadata extracted w/ `pragma`
|
|
10
|
-
*/
|
|
11
|
-
meta?: M;
|
|
12
|
-
}
|
|
13
|
-
export interface ExtractedMessageDescriptor extends MessageDescriptor {
|
|
14
|
-
/**
|
|
15
|
-
* Line number
|
|
16
|
-
*/
|
|
17
|
-
line?: number;
|
|
18
|
-
/**
|
|
19
|
-
* Column number
|
|
20
|
-
*/
|
|
21
|
-
col?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Metadata extracted from pragma
|
|
24
|
-
*/
|
|
25
|
-
meta?: Record<string, string>;
|
|
26
|
-
}
|
|
27
|
-
export type ExtractCLIOptions = Omit<ExtractOpts, 'overrideIdFn' | 'onMsgExtracted' | 'onMetaExtracted'> & {
|
|
28
|
-
/**
|
|
29
|
-
* Output File
|
|
30
|
-
*/
|
|
31
|
-
outFile?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Ignore file glob pattern
|
|
34
|
-
*/
|
|
35
|
-
ignore?: string[];
|
|
36
|
-
};
|
|
37
|
-
export type ExtractOpts = Opts & {
|
|
38
|
-
/**
|
|
39
|
-
* Whether to throw an error if we had any issues with
|
|
40
|
-
* 1 of the source files
|
|
41
|
-
*/
|
|
42
|
-
throws?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Message ID interpolation pattern
|
|
45
|
-
*/
|
|
46
|
-
idInterpolationPattern?: string;
|
|
47
|
-
/**
|
|
48
|
-
* Whether we read from stdin instead of a file
|
|
49
|
-
*/
|
|
50
|
-
readFromStdin?: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Path to a formatter file that controls the shape of JSON file from `outFile`.
|
|
53
|
-
*/
|
|
54
|
-
format?: string | Formatter<unknown>;
|
|
55
|
-
/**
|
|
56
|
-
* Whether to hoist selectors & flatten sentences
|
|
57
|
-
*/
|
|
58
|
-
flatten?: boolean;
|
|
59
|
-
} & Pick<Opts, 'onMsgExtracted' | 'onMetaExtracted'>;
|
|
60
|
-
/**
|
|
61
|
-
* Extract strings from source files
|
|
62
|
-
* @param files list of files
|
|
63
|
-
* @param extractOpts extract options
|
|
64
|
-
* @returns messages serialized as JSON string since key order
|
|
65
|
-
* matters for some `format`
|
|
66
|
-
*/
|
|
67
|
-
export declare function extract(files: readonly string[], extractOpts: ExtractOpts): Promise<string>;
|
|
68
|
-
/**
|
|
69
|
-
* Extract strings from source files, also writes to a file.
|
|
70
|
-
* @param files list of files
|
|
71
|
-
* @param extractOpts extract options
|
|
72
|
-
* @returns A Promise that resolves if output file was written successfully
|
|
73
|
-
*/
|
|
74
|
-
export default function extractAndWrite(files: readonly string[], extractOpts: ExtractCLIOptions): Promise<void>;
|
package/src/extract.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extract = extract;
|
|
4
|
-
exports.default = extractAndWrite;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
7
|
-
const fs_extra_1 = require("fs-extra");
|
|
8
|
-
const console_utils_1 = require("./console_utils");
|
|
9
|
-
const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
10
|
-
const manipulator_1 = require("@formatjs/icu-messageformat-parser/manipulator");
|
|
11
|
-
const printer_1 = require("@formatjs/icu-messageformat-parser/printer");
|
|
12
|
-
const json_stable_stringify_1 = tslib_1.__importDefault(require("json-stable-stringify"));
|
|
13
|
-
const formatters_1 = require("./formatters");
|
|
14
|
-
const parse_script_1 = require("./parse_script");
|
|
15
|
-
function calculateLineColFromOffset(text, start) {
|
|
16
|
-
if (!start) {
|
|
17
|
-
return { line: 1, col: 1 };
|
|
18
|
-
}
|
|
19
|
-
const chunk = text.slice(0, start);
|
|
20
|
-
const lines = chunk.split('\n');
|
|
21
|
-
const lastLine = lines[lines.length - 1];
|
|
22
|
-
return { line: lines.length, col: lastLine.length };
|
|
23
|
-
}
|
|
24
|
-
async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
|
|
25
|
-
let messages = [];
|
|
26
|
-
let meta;
|
|
27
|
-
const onMsgExtracted = opts.onMsgExtracted;
|
|
28
|
-
const onMetaExtracted = opts.onMetaExtracted;
|
|
29
|
-
opts = {
|
|
30
|
-
...opts,
|
|
31
|
-
additionalComponentNames: [
|
|
32
|
-
'$formatMessage',
|
|
33
|
-
...(opts.additionalComponentNames || []),
|
|
34
|
-
],
|
|
35
|
-
onMsgExtracted(filePath, msgs) {
|
|
36
|
-
if (opts.extractSourceLocation) {
|
|
37
|
-
msgs = msgs.map(msg => ({
|
|
38
|
-
...msg,
|
|
39
|
-
...calculateLineColFromOffset(source, msg.start),
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
messages = messages.concat(msgs);
|
|
43
|
-
if (onMsgExtracted) {
|
|
44
|
-
onMsgExtracted(filePath, msgs);
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
onMetaExtracted(filePath, m) {
|
|
48
|
-
meta = m;
|
|
49
|
-
if (onMetaExtracted) {
|
|
50
|
-
onMetaExtracted(filePath, m);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
if (!opts.overrideIdFn && idInterpolationPattern) {
|
|
55
|
-
opts = {
|
|
56
|
-
...opts,
|
|
57
|
-
overrideIdFn: (id, defaultMessage, description, fileName) => id ||
|
|
58
|
-
(0, ts_transformer_1.interpolateName)({
|
|
59
|
-
resourcePath: fileName,
|
|
60
|
-
}, idInterpolationPattern, {
|
|
61
|
-
content: description
|
|
62
|
-
? `${defaultMessage}#${typeof description === 'string'
|
|
63
|
-
? description
|
|
64
|
-
: (0, json_stable_stringify_1.default)(description)}`
|
|
65
|
-
: defaultMessage,
|
|
66
|
-
}),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
(0, console_utils_1.debug)('Processing opts for %s: %s', fn, opts);
|
|
70
|
-
const scriptParseFn = (0, parse_script_1.parseScript)(opts, fn);
|
|
71
|
-
if (fn.endsWith('.vue')) {
|
|
72
|
-
(0, console_utils_1.debug)('Processing %s using vue extractor', fn);
|
|
73
|
-
const { parseFile } = await import('./vue_extractor.js');
|
|
74
|
-
parseFile(source, fn, scriptParseFn);
|
|
75
|
-
}
|
|
76
|
-
else if (fn.endsWith('.hbs')) {
|
|
77
|
-
(0, console_utils_1.debug)('Processing %s using hbs extractor', fn);
|
|
78
|
-
const { parseFile } = await import('./hbs_extractor.js');
|
|
79
|
-
parseFile(source, fn, opts);
|
|
80
|
-
}
|
|
81
|
-
else if (fn.endsWith('.gts') || fn.endsWith('.gjs')) {
|
|
82
|
-
(0, console_utils_1.debug)('Processing %s as gts/gjs file', fn);
|
|
83
|
-
const { parseFile } = await import('./gts_extractor.js');
|
|
84
|
-
parseFile(source, fn, opts);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
(0, console_utils_1.debug)('Processing %s using typescript extractor', fn);
|
|
88
|
-
scriptParseFn(source);
|
|
89
|
-
}
|
|
90
|
-
(0, console_utils_1.debug)('Done extracting %s messages: %s', fn, messages);
|
|
91
|
-
if (meta) {
|
|
92
|
-
(0, console_utils_1.debug)('Extracted meta:', meta);
|
|
93
|
-
messages.forEach(m => (m.meta = meta));
|
|
94
|
-
}
|
|
95
|
-
return { messages, meta };
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Extract strings from source files
|
|
99
|
-
* @param files list of files
|
|
100
|
-
* @param extractOpts extract options
|
|
101
|
-
* @returns messages serialized as JSON string since key order
|
|
102
|
-
* matters for some `format`
|
|
103
|
-
*/
|
|
104
|
-
async function extract(files, extractOpts) {
|
|
105
|
-
const { throws, readFromStdin, flatten, ...opts } = extractOpts;
|
|
106
|
-
let rawResults = [];
|
|
107
|
-
try {
|
|
108
|
-
if (readFromStdin) {
|
|
109
|
-
(0, console_utils_1.debug)(`Reading input from stdin`);
|
|
110
|
-
// Read from stdin
|
|
111
|
-
if (process.stdin.isTTY) {
|
|
112
|
-
(0, console_utils_1.warn)('Reading source file from TTY.');
|
|
113
|
-
}
|
|
114
|
-
const stdinSource = await (0, console_utils_1.getStdinAsString)();
|
|
115
|
-
rawResults = [await processFile(stdinSource, 'dummy', opts)];
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
rawResults = await Promise.all(files.map(async (fn) => {
|
|
119
|
-
(0, console_utils_1.debug)('Extracting file:', fn);
|
|
120
|
-
const source = await (0, fs_extra_1.readFile)(fn, 'utf8');
|
|
121
|
-
return processFile(source, fn, opts);
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
if (throws) {
|
|
127
|
-
throw e;
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
(0, console_utils_1.warn)(String(e));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const formatter = await (0, formatters_1.resolveBuiltinFormatter)(opts.format);
|
|
134
|
-
const extractionResults = rawResults.filter((r) => !!r);
|
|
135
|
-
const extractedMessages = new Map();
|
|
136
|
-
for (const { messages } of extractionResults) {
|
|
137
|
-
for (const message of messages) {
|
|
138
|
-
const { id, description, defaultMessage } = message;
|
|
139
|
-
if (!id) {
|
|
140
|
-
const error = new Error(`[FormatJS CLI] Missing message id for message:
|
|
141
|
-
${JSON.stringify(message, undefined, 2)}`);
|
|
142
|
-
if (throws) {
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
(0, console_utils_1.warn)(error.message);
|
|
147
|
-
}
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
if (extractedMessages.has(id)) {
|
|
151
|
-
const existing = extractedMessages.get(id);
|
|
152
|
-
if ((0, json_stable_stringify_1.default)(description) !== (0, json_stable_stringify_1.default)(existing.description) ||
|
|
153
|
-
defaultMessage !== existing.defaultMessage) {
|
|
154
|
-
const error = new Error(`[FormatJS CLI] Duplicate message id: "${id}", ` +
|
|
155
|
-
'but the `description` and/or `defaultMessage` are different.');
|
|
156
|
-
if (throws) {
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
(0, console_utils_1.warn)(error.message);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
extractedMessages.set(id, message);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const results = {};
|
|
168
|
-
const messages = Array.from(extractedMessages.values());
|
|
169
|
-
for (const { id, ...msg } of messages) {
|
|
170
|
-
if (flatten && msg.defaultMessage) {
|
|
171
|
-
msg.defaultMessage = (0, printer_1.printAST)((0, manipulator_1.hoistSelectors)((0, icu_messageformat_parser_1.parse)(msg.defaultMessage)));
|
|
172
|
-
}
|
|
173
|
-
results[id] = msg;
|
|
174
|
-
}
|
|
175
|
-
if (typeof formatter.serialize === 'function') {
|
|
176
|
-
return formatter.serialize(formatter.format(results));
|
|
177
|
-
}
|
|
178
|
-
return (0, json_stable_stringify_1.default)(formatter.format(results), {
|
|
179
|
-
space: 2,
|
|
180
|
-
cmp: formatter.compareMessages || undefined,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Extract strings from source files, also writes to a file.
|
|
185
|
-
* @param files list of files
|
|
186
|
-
* @param extractOpts extract options
|
|
187
|
-
* @returns A Promise that resolves if output file was written successfully
|
|
188
|
-
*/
|
|
189
|
-
async function extractAndWrite(files, extractOpts) {
|
|
190
|
-
const { outFile, ...opts } = extractOpts;
|
|
191
|
-
const serializedResult = (await extract(files, opts)) + '\n';
|
|
192
|
-
if (outFile) {
|
|
193
|
-
(0, console_utils_1.debug)('Writing output file:', outFile);
|
|
194
|
-
return (0, fs_extra_1.outputFile)(outFile, serializedResult);
|
|
195
|
-
}
|
|
196
|
-
await (0, console_utils_1.writeStdout)(serializedResult);
|
|
197
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.format = void 0;
|
|
4
|
-
const format = msgs => {
|
|
5
|
-
const results = {};
|
|
6
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
7
|
-
results[id] = {
|
|
8
|
-
message: msg.defaultMessage,
|
|
9
|
-
description: typeof msg.description === 'string'
|
|
10
|
-
? msg.description
|
|
11
|
-
: JSON.stringify(msg.description),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
return results;
|
|
15
|
-
};
|
|
16
|
-
exports.format = format;
|
|
17
|
-
const compile = msgs => {
|
|
18
|
-
const results = {};
|
|
19
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
20
|
-
if (id === 'smartling') {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
results[id] = msg.message;
|
|
24
|
-
}
|
|
25
|
-
return results;
|
|
26
|
-
};
|
|
27
|
-
exports.compile = compile;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { MessageDescriptor } from '@formatjs/ts-transformer';
|
|
2
|
-
export type FormatFn<T = Record<string, MessageDescriptor>> = (msgs: Record<string, MessageDescriptor>) => T;
|
|
3
|
-
export type CompileFn<T = Record<string, MessageDescriptor>> = (msgs: T) => Record<string, string>;
|
|
4
|
-
export type SerializeFn<T = Record<string, MessageDescriptor>> = (msgs: T) => string;
|
|
5
|
-
export declare const format: FormatFn;
|
|
6
|
-
export declare const compile: CompileFn;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.format = void 0;
|
|
4
|
-
const format = msgs => msgs;
|
|
5
|
-
exports.format = format;
|
|
6
|
-
const compile = msgs => {
|
|
7
|
-
const results = {};
|
|
8
|
-
for (const k in msgs) {
|
|
9
|
-
results[k] = msgs[k].defaultMessage;
|
|
10
|
-
}
|
|
11
|
-
return results;
|
|
12
|
-
};
|
|
13
|
-
exports.compile = compile;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Comparator } from 'json-stable-stringify';
|
|
2
|
-
import { CompileFn, FormatFn, SerializeFn } from './default';
|
|
3
|
-
export interface Formatter<T> {
|
|
4
|
-
serialize?: SerializeFn<T>;
|
|
5
|
-
format: FormatFn<T>;
|
|
6
|
-
compile: CompileFn<T>;
|
|
7
|
-
compareMessages?: Comparator;
|
|
8
|
-
}
|
|
9
|
-
export declare function resolveBuiltinFormatter(format?: string | Formatter<unknown>): Promise<any>;
|
package/src/formatters/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveBuiltinFormatter = resolveBuiltinFormatter;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const url_1 = require("url");
|
|
7
|
-
const crowdin = tslib_1.__importStar(require("./crowdin"));
|
|
8
|
-
const defaultFormatter = tslib_1.__importStar(require("./default"));
|
|
9
|
-
const lokalise = tslib_1.__importStar(require("./lokalise"));
|
|
10
|
-
const simple = tslib_1.__importStar(require("./simple"));
|
|
11
|
-
const smartling = tslib_1.__importStar(require("./smartling"));
|
|
12
|
-
const transifex = tslib_1.__importStar(require("./transifex"));
|
|
13
|
-
async function resolveBuiltinFormatter(format) {
|
|
14
|
-
if (!format) {
|
|
15
|
-
return defaultFormatter;
|
|
16
|
-
}
|
|
17
|
-
if (typeof format !== 'string') {
|
|
18
|
-
return format;
|
|
19
|
-
}
|
|
20
|
-
switch (format) {
|
|
21
|
-
case 'transifex':
|
|
22
|
-
return transifex;
|
|
23
|
-
case 'smartling':
|
|
24
|
-
return smartling;
|
|
25
|
-
case 'simple':
|
|
26
|
-
return simple;
|
|
27
|
-
case 'lokalise':
|
|
28
|
-
return lokalise;
|
|
29
|
-
case 'crowdin':
|
|
30
|
-
return crowdin;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
// eslint-disable-next-line import/dynamic-import-chunkname
|
|
34
|
-
return import((0, url_1.pathToFileURL)((0, path_1.resolve)(process.cwd(), format)).href);
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
console.error(`Cannot resolve formatter ${format}`);
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CompileFn, FormatFn } from './default';
|
|
2
|
-
export type StructuredJson = Record<string, {
|
|
3
|
-
translation: string;
|
|
4
|
-
notes?: string;
|
|
5
|
-
context?: string;
|
|
6
|
-
limit?: string;
|
|
7
|
-
}>;
|
|
8
|
-
export declare const format: FormatFn<StructuredJson>;
|
|
9
|
-
export declare const compile: CompileFn<StructuredJson>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.format = void 0;
|
|
4
|
-
const format = msgs => {
|
|
5
|
-
const results = {};
|
|
6
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
7
|
-
results[id] = {
|
|
8
|
-
translation: msg.defaultMessage,
|
|
9
|
-
notes: typeof msg.description === 'string'
|
|
10
|
-
? msg.description
|
|
11
|
-
: JSON.stringify(msg.description),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
return results;
|
|
15
|
-
};
|
|
16
|
-
exports.format = format;
|
|
17
|
-
const compile = msgs => {
|
|
18
|
-
const results = {};
|
|
19
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
20
|
-
results[id] = msg.translation;
|
|
21
|
-
}
|
|
22
|
-
return results;
|
|
23
|
-
};
|
|
24
|
-
exports.compile = compile;
|
package/src/formatters/simple.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.format = void 0;
|
|
4
|
-
const format = msgs => {
|
|
5
|
-
return Object.keys(msgs).reduce((all, k) => {
|
|
6
|
-
all[k] = msgs[k].defaultMessage;
|
|
7
|
-
return all;
|
|
8
|
-
}, {});
|
|
9
|
-
};
|
|
10
|
-
exports.format = format;
|
|
11
|
-
const compile = msgs => msgs;
|
|
12
|
-
exports.compile = compile;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Comparator } from 'json-stable-stringify';
|
|
2
|
-
import { CompileFn, FormatFn } from './default';
|
|
3
|
-
export interface SmartlingDirectives {
|
|
4
|
-
translate_paths: [
|
|
5
|
-
{
|
|
6
|
-
path: string;
|
|
7
|
-
key: string;
|
|
8
|
-
instruction: string;
|
|
9
|
-
}
|
|
10
|
-
];
|
|
11
|
-
variants_enabled: boolean;
|
|
12
|
-
string_format: string;
|
|
13
|
-
[k: string]: any;
|
|
14
|
-
}
|
|
15
|
-
export type SmartlingJson = {
|
|
16
|
-
smartling: SmartlingDirectives;
|
|
17
|
-
} & Record<string, {
|
|
18
|
-
message: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
}>;
|
|
21
|
-
export declare const format: FormatFn<SmartlingJson>;
|
|
22
|
-
export declare const compareMessages: Comparator;
|
|
23
|
-
export declare const compile: CompileFn<SmartlingJson>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.compareMessages = exports.format = void 0;
|
|
4
|
-
const format = msgs => {
|
|
5
|
-
const results = {
|
|
6
|
-
smartling: {
|
|
7
|
-
translate_paths: [
|
|
8
|
-
{
|
|
9
|
-
path: '*/message',
|
|
10
|
-
key: '{*}/message',
|
|
11
|
-
instruction: '*/description',
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
variants_enabled: true,
|
|
15
|
-
string_format: 'icu',
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
19
|
-
results[id] = {
|
|
20
|
-
message: msg.defaultMessage,
|
|
21
|
-
description: typeof msg.description === 'string'
|
|
22
|
-
? msg.description
|
|
23
|
-
: JSON.stringify(msg.description),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return results;
|
|
27
|
-
};
|
|
28
|
-
exports.format = format;
|
|
29
|
-
const compareMessages = (el1, el2) => {
|
|
30
|
-
// `smartling` has to be the 1st key
|
|
31
|
-
if (el1.key === 'smartling') {
|
|
32
|
-
return -1;
|
|
33
|
-
}
|
|
34
|
-
if (el2.key === 'smartling') {
|
|
35
|
-
return 1;
|
|
36
|
-
}
|
|
37
|
-
return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1;
|
|
38
|
-
};
|
|
39
|
-
exports.compareMessages = compareMessages;
|
|
40
|
-
const compile = msgs => {
|
|
41
|
-
const results = {};
|
|
42
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
43
|
-
if (id === 'smartling') {
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
results[id] = msg.message;
|
|
47
|
-
}
|
|
48
|
-
return results;
|
|
49
|
-
};
|
|
50
|
-
exports.compile = compile;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CompileFn, FormatFn } from './default';
|
|
2
|
-
export type StructuredJson = Record<string, {
|
|
3
|
-
string: string;
|
|
4
|
-
developer_comment?: string;
|
|
5
|
-
context?: string;
|
|
6
|
-
character_limit?: string;
|
|
7
|
-
}>;
|
|
8
|
-
export declare const format: FormatFn<StructuredJson>;
|
|
9
|
-
export declare const compile: CompileFn<StructuredJson>;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile = exports.format = void 0;
|
|
4
|
-
const format = msgs => {
|
|
5
|
-
const results = {};
|
|
6
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
7
|
-
results[id] = {
|
|
8
|
-
string: msg.defaultMessage,
|
|
9
|
-
developer_comment: typeof msg.description === 'string'
|
|
10
|
-
? msg.description
|
|
11
|
-
: JSON.stringify(msg.description),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
return results;
|
|
15
|
-
};
|
|
16
|
-
exports.format = format;
|
|
17
|
-
const compile = msgs => {
|
|
18
|
-
const results = {};
|
|
19
|
-
for (const [id, msg] of Object.entries(msgs)) {
|
|
20
|
-
results[id] = msg.string;
|
|
21
|
-
}
|
|
22
|
-
return results;
|
|
23
|
-
};
|
|
24
|
-
exports.compile = compile;
|
package/src/gts_extractor.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseFile(source: string, fileName: string, options: any): void;
|
package/src/gts_extractor.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFile = parseFile;
|
|
4
|
-
const content_tag_1 = require("content-tag");
|
|
5
|
-
const hbs_extractor_1 = require("./hbs_extractor");
|
|
6
|
-
const parse_script_1 = require("./parse_script");
|
|
7
|
-
let p = new content_tag_1.Preprocessor();
|
|
8
|
-
function parseFile(source, fileName, options) {
|
|
9
|
-
const scriptParseFn = (0, parse_script_1.parseScript)(options, fileName);
|
|
10
|
-
const transformedSource = p.process(source, { filename: fileName });
|
|
11
|
-
scriptParseFn(transformedSource);
|
|
12
|
-
// extract template from transformed source to then run through hbs processor
|
|
13
|
-
const parseResult = p.parse(source, { filename: fileName });
|
|
14
|
-
for (let parsed of parseResult) {
|
|
15
|
-
(0, hbs_extractor_1.parseFile)(parsed.contents, fileName, options);
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/hbs_extractor.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseFile(source: string, fileName: string, options: any): void;
|
package/src/hbs_extractor.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFile = parseFile;
|
|
4
|
-
const ember_template_recast_1 = require("ember-template-recast");
|
|
5
|
-
function extractText(node, fileName, options) {
|
|
6
|
-
if (!options.onMsgExtracted)
|
|
7
|
-
return;
|
|
8
|
-
if (!options.overrideIdFn)
|
|
9
|
-
return;
|
|
10
|
-
if (node.path.type !== 'PathExpression')
|
|
11
|
-
return;
|
|
12
|
-
if (['format-message', 'formatMessage'].includes(node.path.original)) {
|
|
13
|
-
let [first, second] = node.params;
|
|
14
|
-
if (first.type !== 'StringLiteral')
|
|
15
|
-
return;
|
|
16
|
-
let message = first?.value;
|
|
17
|
-
let desc;
|
|
18
|
-
if (second?.type === 'StringLiteral') {
|
|
19
|
-
desc = second.value?.trim().replace(/\s+/gm, ' ');
|
|
20
|
-
}
|
|
21
|
-
let defaultMessage = message?.trim().replace(/\s+/gm, ' ');
|
|
22
|
-
let id = typeof options.overrideIdFn === 'string'
|
|
23
|
-
? options.overrideIdFn
|
|
24
|
-
: options.overrideIdFn(undefined, defaultMessage, desc, fileName);
|
|
25
|
-
options.onMsgExtracted(fileName, [
|
|
26
|
-
{
|
|
27
|
-
id: id,
|
|
28
|
-
defaultMessage: defaultMessage,
|
|
29
|
-
description: desc,
|
|
30
|
-
},
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function parseFile(source, fileName, options) {
|
|
35
|
-
let visitor = function () {
|
|
36
|
-
return {
|
|
37
|
-
MustacheStatement(node) {
|
|
38
|
-
extractText(node, fileName, options);
|
|
39
|
-
},
|
|
40
|
-
SubExpression(node) {
|
|
41
|
-
extractText(node, fileName, options);
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
// SAFETY: ember-template-recast's types are out of date,
|
|
46
|
-
// but it does not affect runtime
|
|
47
|
-
(0, ember_template_recast_1.transform)(source, visitor);
|
|
48
|
-
}
|
package/src/parse_script.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Opts } from '@formatjs/ts-transformer';
|
|
2
|
-
/**
|
|
3
|
-
* Invoid TypeScript module transpilation with our TS transformer
|
|
4
|
-
* @param opts Formatjs TS Transformer opt
|
|
5
|
-
* @param fn filename
|
|
6
|
-
*/
|
|
7
|
-
export declare function parseScript(opts: Opts, fn?: string): (source: string) => void;
|