i18next-cli 1.75.2 → 1.76.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/README.md +43 -1
- package/dist/cjs/cli.js +5 -3
- package/dist/cjs/extractor/core/ast-visitors.js +1 -0
- package/dist/cjs/extractor/core/extractor.js +4 -0
- package/dist/cjs/extractor/core/translation-manager.js +4 -0
- package/dist/cjs/extractor/parsers/call-expression-handler.js +12 -9
- package/dist/cjs/extractor/parsers/comment-parser.js +6 -1
- package/dist/cjs/extractor/parsers/expression-resolver.js +26 -5
- package/dist/cjs/extractor/parsers/jsx-handler.js +60 -4
- package/dist/cjs/extractor/parsers/jsx-parser.js +161 -1
- package/dist/cjs/index.js +7 -1
- package/dist/cjs/instrumenter/core/instrumenter.js +38 -0
- package/dist/cjs/linter.js +35 -6
- package/dist/cjs/localize/localize.js +4 -2
- package/dist/cjs/status.js +5 -0
- package/dist/cjs/types-generator.js +7 -1
- package/dist/cjs/utils/message-format.js +284 -0
- package/dist/esm/cli.js +5 -3
- package/dist/esm/extractor/core/ast-visitors.js +1 -0
- package/dist/esm/extractor/core/extractor.js +4 -0
- package/dist/esm/extractor/core/translation-manager.js +4 -0
- package/dist/esm/extractor/parsers/call-expression-handler.js +12 -9
- package/dist/esm/extractor/parsers/comment-parser.js +6 -1
- package/dist/esm/extractor/parsers/expression-resolver.js +26 -5
- package/dist/esm/extractor/parsers/jsx-handler.js +61 -5
- package/dist/esm/extractor/parsers/jsx-parser.js +160 -2
- package/dist/esm/index.js +7 -1
- package/dist/esm/instrumenter/core/instrumenter.js +38 -0
- package/dist/esm/linter.js +35 -6
- package/dist/esm/localize/localize.js +4 -2
- package/dist/esm/status.js +5 -0
- package/dist/esm/types-generator.js +7 -1
- package/dist/esm/utils/message-format.js +278 -0
- package/package.json +3 -1
- package/types/extractor/core/ast-visitors.d.ts.map +1 -1
- package/types/extractor/core/extractor.d.ts.map +1 -1
- package/types/extractor/core/translation-manager.d.ts.map +1 -1
- package/types/extractor/parsers/call-expression-handler.d.ts.map +1 -1
- package/types/extractor/parsers/comment-parser.d.ts.map +1 -1
- package/types/extractor/parsers/expression-resolver.d.ts +5 -1
- package/types/extractor/parsers/expression-resolver.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-handler.d.ts +13 -1
- package/types/extractor/parsers/jsx-handler.d.ts.map +1 -1
- package/types/extractor/parsers/jsx-parser.d.ts +16 -0
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -1
- package/types/instrumenter/core/instrumenter.d.ts.map +1 -1
- package/types/linter.d.ts.map +1 -1
- package/types/status.d.ts.map +1 -1
- package/types/types-generator.d.ts.map +1 -1
- package/types/types.d.ts +16 -3
- package/types/types.d.ts.map +1 -1
- package/types/utils/message-format.d.ts +55 -0
- package/types/utils/message-format.d.ts.map +1 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { I18nextToolkitConfig, LintIssue } from '../types.js';
|
|
2
|
+
/** What an ICU or MF2 message uses. */
|
|
3
|
+
export interface MessageShape {
|
|
4
|
+
/** Argument names (`{name}` in ICU, `{$name}` in MF2). `#` and markup are not arguments. */
|
|
5
|
+
args: Set<string>;
|
|
6
|
+
/** Plural selections: their CLDR category selectors and the numbers of their exact selectors (`=0` in ICU, `0` in MF2). */
|
|
7
|
+
plurals: Array<{
|
|
8
|
+
arg: string;
|
|
9
|
+
type: 'cardinal' | 'ordinal';
|
|
10
|
+
categories: string[];
|
|
11
|
+
exact: number[];
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
/** Parses an ICU or MF2 message. Throws an Error with the parser's message on a syntax error. */
|
|
15
|
+
export type MessageAnalyzer = (message: string) => MessageShape;
|
|
16
|
+
/**
|
|
17
|
+
* True for `extract.messageFormat` `'icu'` and `'mf2'`. These formats put plurals and selects into the
|
|
18
|
+
* message itself and have no `$t()` nesting, so the CLI writes no plural or context suffix keys for them.
|
|
19
|
+
*/
|
|
20
|
+
export declare const usesMessageFormat: (config: Pick<I18nextToolkitConfig, "extract">) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites an i18next-format text (`Hello {{name}}`, `{{total, number}}`) into the configured message format:
|
|
23
|
+
* `{name}` / `{total, number}` for ICU, `{$name}` / `{$total :number}` for MF2, and escapes the text around the
|
|
24
|
+
* placeholders. Values of the i18next format are returned as is.
|
|
25
|
+
* ponytail: `#` is not quoted inside ICU plurals, and an MF2 text starting with `.` is left to `lint` to report.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toMessageFormatPlaceholders(value: string, config: Pick<I18nextToolkitConfig, 'extract'>): string;
|
|
28
|
+
/**
|
|
29
|
+
* Loads the parser for `messageFormat` lazily, so projects in the i18next format never load it.
|
|
30
|
+
*/
|
|
31
|
+
export declare function loadMessageAnalyzer(format: 'icu' | 'mf2'): Promise<MessageAnalyzer>;
|
|
32
|
+
interface PluralCategories {
|
|
33
|
+
/** the locale's CLDR categories */
|
|
34
|
+
allowed: string[];
|
|
35
|
+
/** `other` plus every category a whole number from 0 to 1000 selects */
|
|
36
|
+
required: string[];
|
|
37
|
+
/** per required category, the whole numbers from 0 to 1000 it is selected for */
|
|
38
|
+
numbers: Map<string, number[]>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The plural categories a message for `lng` may and must have: allowed are the locale's CLDR
|
|
42
|
+
* categories, required are `other` plus every category a whole number from 0 to 1000 selects.
|
|
43
|
+
* So ru needs one/few/many, while fr, es, it and pt may leave out `many` (from 1,000,000 only)
|
|
44
|
+
* and cs/lt `many` (fractions only). Undefined when Intl does not know the locale.
|
|
45
|
+
* Same rule as the Locize AI-review guard and MCP server.
|
|
46
|
+
*/
|
|
47
|
+
export declare function pluralCategories(lng: string, type: 'cardinal' | 'ordinal'): PluralCategories | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Checks every translation value of every locale for `extract.messageFormat` `'icu'` or `'mf2'`:
|
|
50
|
+
* syntax, argument names against the primary language, and plural categories per locale.
|
|
51
|
+
* Returns the issues per translation file.
|
|
52
|
+
*/
|
|
53
|
+
export declare function lintMessageFormatResources(config: I18nextToolkitConfig, analyze: MessageAnalyzer): Promise<Map<string, LintIssue[]>>;
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=message-format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-format.d.ts","sourceRoot":"","sources":["../../src/utils/message-format.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGlE,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,4FAA4F;IAC5F,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACjB,2HAA2H;IAC3H,OAAO,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CACrG;AAED,iGAAiG;AACjG,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,YAAY,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,KAAG,OACA,CAAA;AAElF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,GAAG,MAAM,CAkBjH;AAMD;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,OAAO,CAAC,eAAe,CAAC,CA4D1F;AAqBD,UAAU,gBAAgB;IACxB,mCAAmC;IACnC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,iFAAiF;IACjF,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;CAC/B;AAID;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAqBzG;AAmCD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAE,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,CAwE3I"}
|