i18next-cli 0.9.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/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +489 -0
- package/dist/cjs/cli.js +2 -0
- package/dist/cjs/config.js +1 -0
- package/dist/cjs/extractor/core/extractor.js +1 -0
- package/dist/cjs/extractor/core/key-finder.js +1 -0
- package/dist/cjs/extractor/core/translation-manager.js +1 -0
- package/dist/cjs/extractor/parsers/ast-visitors.js +1 -0
- package/dist/cjs/extractor/parsers/comment-parser.js +1 -0
- package/dist/cjs/extractor/parsers/jsx-parser.js +1 -0
- package/dist/cjs/extractor/plugin-manager.js +1 -0
- package/dist/cjs/heuristic-config.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/init.js +1 -0
- package/dist/cjs/linter.js +1 -0
- package/dist/cjs/locize.js +1 -0
- package/dist/cjs/migrator.js +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/status.js +1 -0
- package/dist/cjs/syncer.js +1 -0
- package/dist/cjs/types-generator.js +1 -0
- package/dist/cjs/utils/file-utils.js +1 -0
- package/dist/cjs/utils/logger.js +1 -0
- package/dist/cjs/utils/nested-object.js +1 -0
- package/dist/cjs/utils/validation.js +1 -0
- package/dist/esm/cli.js +2 -0
- package/dist/esm/config.js +1 -0
- package/dist/esm/extractor/core/extractor.js +1 -0
- package/dist/esm/extractor/core/key-finder.js +1 -0
- package/dist/esm/extractor/core/translation-manager.js +1 -0
- package/dist/esm/extractor/parsers/ast-visitors.js +1 -0
- package/dist/esm/extractor/parsers/comment-parser.js +1 -0
- package/dist/esm/extractor/parsers/jsx-parser.js +1 -0
- package/dist/esm/extractor/plugin-manager.js +1 -0
- package/dist/esm/heuristic-config.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/init.js +1 -0
- package/dist/esm/linter.js +1 -0
- package/dist/esm/locize.js +1 -0
- package/dist/esm/migrator.js +1 -0
- package/dist/esm/status.js +1 -0
- package/dist/esm/syncer.js +1 -0
- package/dist/esm/types-generator.js +1 -0
- package/dist/esm/utils/file-utils.js +1 -0
- package/dist/esm/utils/logger.js +1 -0
- package/dist/esm/utils/nested-object.js +1 -0
- package/dist/esm/utils/validation.js +1 -0
- package/package.json +81 -0
- package/src/cli.ts +166 -0
- package/src/config.ts +158 -0
- package/src/extractor/core/extractor.ts +195 -0
- package/src/extractor/core/key-finder.ts +70 -0
- package/src/extractor/core/translation-manager.ts +115 -0
- package/src/extractor/index.ts +7 -0
- package/src/extractor/parsers/ast-visitors.ts +637 -0
- package/src/extractor/parsers/comment-parser.ts +125 -0
- package/src/extractor/parsers/jsx-parser.ts +166 -0
- package/src/extractor/plugin-manager.ts +54 -0
- package/src/extractor.ts +15 -0
- package/src/heuristic-config.ts +64 -0
- package/src/index.ts +12 -0
- package/src/init.ts +156 -0
- package/src/linter.ts +191 -0
- package/src/locize.ts +251 -0
- package/src/migrator.ts +139 -0
- package/src/status.ts +192 -0
- package/src/syncer.ts +114 -0
- package/src/types-generator.ts +116 -0
- package/src/types.ts +312 -0
- package/src/utils/file-utils.ts +81 -0
- package/src/utils/logger.ts +36 -0
- package/src/utils/nested-object.ts +113 -0
- package/src/utils/validation.ts +69 -0
- package/tryme.js +8 -0
- package/tsconfig.json +71 -0
- package/types/cli.d.ts +3 -0
- package/types/cli.d.ts.map +1 -0
- package/types/config.d.ts +50 -0
- package/types/config.d.ts.map +1 -0
- package/types/extractor/core/extractor.d.ts +66 -0
- package/types/extractor/core/extractor.d.ts.map +1 -0
- package/types/extractor/core/key-finder.d.ts +31 -0
- package/types/extractor/core/key-finder.d.ts.map +1 -0
- package/types/extractor/core/translation-manager.d.ts +31 -0
- package/types/extractor/core/translation-manager.d.ts.map +1 -0
- package/types/extractor/index.d.ts +8 -0
- package/types/extractor/index.d.ts.map +1 -0
- package/types/extractor/parsers/ast-visitors.d.ts +235 -0
- package/types/extractor/parsers/ast-visitors.d.ts.map +1 -0
- package/types/extractor/parsers/comment-parser.d.ts +24 -0
- package/types/extractor/parsers/comment-parser.d.ts.map +1 -0
- package/types/extractor/parsers/jsx-parser.d.ts +35 -0
- package/types/extractor/parsers/jsx-parser.d.ts.map +1 -0
- package/types/extractor/plugin-manager.d.ts +37 -0
- package/types/extractor/plugin-manager.d.ts.map +1 -0
- package/types/extractor.d.ts +7 -0
- package/types/extractor.d.ts.map +1 -0
- package/types/heuristic-config.d.ts +10 -0
- package/types/heuristic-config.d.ts.map +1 -0
- package/types/index.d.ts +4 -0
- package/types/index.d.ts.map +1 -0
- package/types/init.d.ts +29 -0
- package/types/init.d.ts.map +1 -0
- package/types/linter.d.ts +33 -0
- package/types/linter.d.ts.map +1 -0
- package/types/locize.d.ts +5 -0
- package/types/locize.d.ts.map +1 -0
- package/types/migrator.d.ts +37 -0
- package/types/migrator.d.ts.map +1 -0
- package/types/status.d.ts +20 -0
- package/types/status.d.ts.map +1 -0
- package/types/syncer.d.ts +33 -0
- package/types/syncer.d.ts.map +1 -0
- package/types/types-generator.d.ts +29 -0
- package/types/types-generator.d.ts.map +1 -0
- package/types/types.d.ts +268 -0
- package/types/types.d.ts.map +1 -0
- package/types/utils/file-utils.d.ts +61 -0
- package/types/utils/file-utils.d.ts.map +1 -0
- package/types/utils/logger.d.ts +34 -0
- package/types/utils/logger.d.ts.map +1 -0
- package/types/utils/nested-object.d.ts +71 -0
- package/types/utils/nested-object.d.ts.map +1 -0
- package/types/utils/validation.d.ts +47 -0
- package/types/utils/validation.d.ts.map +1 -0
- package/vitest.config.ts +13 -0
package/tsconfig.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Basic Options */
|
|
6
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
7
|
+
"target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
8
|
+
"module": "ES2022", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
9
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
10
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
11
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
12
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
13
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
14
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
15
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
16
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
17
|
+
// "outDir": "./", /* Redirect output structure to the directory. */
|
|
18
|
+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
19
|
+
// "composite": true, /* Enable project compilation */
|
|
20
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
21
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
22
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
23
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
24
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
25
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
26
|
+
|
|
27
|
+
/* Strict Type-Checking Options */
|
|
28
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
29
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
30
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
31
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
32
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
33
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
34
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
35
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
36
|
+
|
|
37
|
+
/* Additional Checks */
|
|
38
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
39
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
40
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
41
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
42
|
+
|
|
43
|
+
/* Module Resolution Options */
|
|
44
|
+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
45
|
+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
46
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
47
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
48
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
49
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
50
|
+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
51
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
52
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
53
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
54
|
+
|
|
55
|
+
/* Source Map Options */
|
|
56
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
57
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
58
|
+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
59
|
+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
60
|
+
|
|
61
|
+
/* Experimental Options */
|
|
62
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
63
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
64
|
+
|
|
65
|
+
/* Advanced Options */
|
|
66
|
+
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
67
|
+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
68
|
+
},
|
|
69
|
+
"include": ["src"],
|
|
70
|
+
"exclude": ["node_modules", "test/**/*.ts"]
|
|
71
|
+
}
|
package/types/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { I18nextToolkitConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A helper function for defining the i18next-cli config with type-safety.
|
|
4
|
+
*
|
|
5
|
+
* @param config - The configuration object to define
|
|
6
|
+
* @returns The same configuration object with type safety
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* locales: ['en', 'de'],
|
|
12
|
+
* extract: {
|
|
13
|
+
* input: 'src',
|
|
14
|
+
* output: 'locales/{{language}}/{{namespace}}.json'
|
|
15
|
+
* }
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function defineConfig(config: I18nextToolkitConfig): I18nextToolkitConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Loads and validates the i18next toolkit configuration from the project root.
|
|
22
|
+
*
|
|
23
|
+
* This function:
|
|
24
|
+
* 1. Searches for a config file using findConfigFile()
|
|
25
|
+
* 2. Dynamically imports the config file using ESM import()
|
|
26
|
+
* 3. Validates the configuration structure
|
|
27
|
+
* 4. Sets default values for sync options
|
|
28
|
+
* 5. Adds cache busting for watch mode
|
|
29
|
+
*
|
|
30
|
+
* @returns Promise that resolves to the loaded configuration object, or null if loading failed
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const config = await loadConfig()
|
|
35
|
+
* if (!config) {
|
|
36
|
+
* console.error('Failed to load configuration')
|
|
37
|
+
* process.exit(1)
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function loadConfig(): Promise<I18nextToolkitConfig | null>;
|
|
42
|
+
/**
|
|
43
|
+
* NEW: Ensures a configuration exists, prompting the user to create one if necessary.
|
|
44
|
+
* This function is a wrapper around loadConfig that provides an interactive fallback.
|
|
45
|
+
*
|
|
46
|
+
* @returns A promise that resolves to a valid configuration object.
|
|
47
|
+
* @throws Exits the process if the user declines to create a config or if loading fails after creation.
|
|
48
|
+
*/
|
|
49
|
+
export declare function ensureConfig(): Promise<I18nextToolkitConfig>;
|
|
50
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAanD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,UAAU,IAAK,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAsCxE;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,oBAAoB,CAAC,CA8BnE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Logger, ExtractedKey, I18nextToolkitConfig } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Main extractor function that runs the complete key extraction and file generation process.
|
|
4
|
+
*
|
|
5
|
+
* This is the primary entry point that:
|
|
6
|
+
* 1. Validates configuration
|
|
7
|
+
* 2. Sets up default sync options
|
|
8
|
+
* 3. Finds all translation keys across source files
|
|
9
|
+
* 4. Generates/updates translation files for all locales
|
|
10
|
+
* 5. Provides progress feedback via spinner
|
|
11
|
+
* 6. Returns whether any files were updated
|
|
12
|
+
*
|
|
13
|
+
* @param config - The i18next toolkit configuration object
|
|
14
|
+
* @param logger - Logger instance for output (defaults to ConsoleLogger)
|
|
15
|
+
* @returns Promise resolving to boolean indicating if any files were updated
|
|
16
|
+
*
|
|
17
|
+
* @throws {ExtractorError} When configuration validation fails or extraction process encounters errors
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const config = await loadConfig()
|
|
22
|
+
* const updated = await runExtractor(config)
|
|
23
|
+
* if (updated) {
|
|
24
|
+
* console.log('Translation files were updated')
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function runExtractor(config: I18nextToolkitConfig, logger?: Logger): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Processes an individual source file for translation key extraction.
|
|
31
|
+
*
|
|
32
|
+
* This function:
|
|
33
|
+
* 1. Reads the source file
|
|
34
|
+
* 2. Runs plugin onLoad hooks for code transformation
|
|
35
|
+
* 3. Parses the code into an Abstract Syntax Tree (AST) using SWC
|
|
36
|
+
* 4. Extracts keys from comments using regex patterns
|
|
37
|
+
* 5. Traverses the AST using visitors to find translation calls
|
|
38
|
+
* 6. Runs plugin onVisitNode hooks for custom extraction logic
|
|
39
|
+
*
|
|
40
|
+
* @param file - Path to the source file to process
|
|
41
|
+
* @param config - The i18next toolkit configuration object
|
|
42
|
+
* @param logger - Logger instance for output
|
|
43
|
+
* @param allKeys - Map to accumulate found translation keys
|
|
44
|
+
*
|
|
45
|
+
* @throws {ExtractorError} When file processing fails
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare function processFile(file: string, config: I18nextToolkitConfig, logger: Logger, allKeys: Map<string, ExtractedKey>): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Simplified extraction function that returns translation results without file writing.
|
|
52
|
+
* Used primarily for testing and programmatic access.
|
|
53
|
+
*
|
|
54
|
+
* @param config - The i18next toolkit configuration object
|
|
55
|
+
* @returns Promise resolving to array of translation results
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const results = await extract(config)
|
|
60
|
+
* for (const result of results) {
|
|
61
|
+
* console.log(`${result.path}: ${result.updated ? 'Updated' : 'No changes'}`)
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function extract(config: I18nextToolkitConfig): Promise<import("../../types").TranslationResult[]>;
|
|
66
|
+
//# sourceMappingURL=extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAiB,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAS5F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,OAAO,CAAC,CA+BlB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC,CAoCf;AAmCD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,OAAO,CAAE,MAAM,EAAE,oBAAoB,sDAO1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ExtractedKey, Logger, I18nextToolkitConfig } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Main function for finding translation keys across all source files in a project.
|
|
4
|
+
*
|
|
5
|
+
* This function orchestrates the key extraction process:
|
|
6
|
+
* 1. Processes source files based on input patterns
|
|
7
|
+
* 2. Initializes and manages plugins
|
|
8
|
+
* 3. Processes each file through AST parsing and key extraction
|
|
9
|
+
* 4. Runs plugin lifecycle hooks
|
|
10
|
+
* 5. Returns a deduplicated map of all found keys
|
|
11
|
+
*
|
|
12
|
+
* @param config - The i18next toolkit configuration object
|
|
13
|
+
* @param logger - Logger instance for output (defaults to ConsoleLogger)
|
|
14
|
+
* @returns Promise resolving to a Map of unique translation keys with metadata
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const config = {
|
|
19
|
+
* extract: {
|
|
20
|
+
* input: ['src/**\/*.{ts,tsx}'],
|
|
21
|
+
* functions: ['t'],
|
|
22
|
+
* transComponents: ['Trans']
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* const keys = await findKeys(config)
|
|
27
|
+
* console.log(`Found ${keys.size} unique translation keys`)
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function findKeys(config: I18nextToolkitConfig, logger?: Logger): Promise<Map<string, ExtractedKey>>;
|
|
31
|
+
//# sourceMappingURL=key-finder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-finder.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/key-finder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAK7E;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,oBAAoB,EAC5B,MAAM,GAAE,MAA4B,GACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAgBpC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TranslationResult, ExtractedKey, I18nextToolkitConfig } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Processes extracted translation keys and generates translation files for all configured locales.
|
|
4
|
+
*
|
|
5
|
+
* This function:
|
|
6
|
+
* 1. Groups keys by namespace
|
|
7
|
+
* 2. For each locale and namespace combination:
|
|
8
|
+
* - Reads existing translation files
|
|
9
|
+
* - Preserves keys matching `preservePatterns`
|
|
10
|
+
* - Merges in newly extracted keys
|
|
11
|
+
* - Uses primary language defaults or empty strings for secondary languages
|
|
12
|
+
* - Maintains key sorting based on configuration
|
|
13
|
+
* 3. Determines if files need updating by comparing content
|
|
14
|
+
*
|
|
15
|
+
* @param keys - Map of extracted translation keys with metadata
|
|
16
|
+
* @param config - The i18next toolkit configuration object
|
|
17
|
+
* @returns Promise resolving to array of translation results with update status
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const keys = new Map([
|
|
22
|
+
* ['translation:welcome', { key: 'welcome', defaultValue: 'Welcome!', ns: 'translation' }],
|
|
23
|
+
* ['common:button.save', { key: 'button.save', defaultValue: 'Save', ns: 'common' }]
|
|
24
|
+
* ])
|
|
25
|
+
*
|
|
26
|
+
* const results = await getTranslations(keys, config)
|
|
27
|
+
* // Results contain update status and new/existing translations for each locale
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getTranslations(keys: Map<string, ExtractedKey>, config: I18nextToolkitConfig): Promise<TranslationResult[]>;
|
|
31
|
+
//# sourceMappingURL=translation-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-manager.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/translation-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAiBnF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAkE9B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './core/extractor';
|
|
2
|
+
export * from './core/key-finder';
|
|
3
|
+
export * from './core/translation-manager';
|
|
4
|
+
export * from './parsers/ast-visitors';
|
|
5
|
+
export * from './parsers/comment-parser';
|
|
6
|
+
export * from './parsers/jsx-parser';
|
|
7
|
+
export * from './plugin-manager';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extractor/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,mBAAmB,CAAA;AACjC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { Module } from '@swc/core';
|
|
2
|
+
import type { PluginContext, I18nextToolkitConfig, Logger } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* AST visitor class that traverses JavaScript/TypeScript syntax trees to extract translation keys.
|
|
5
|
+
*
|
|
6
|
+
* This class implements a manual recursive walker that:
|
|
7
|
+
* - Maintains scope information for tracking useTranslation and getFixedT calls
|
|
8
|
+
* - Extracts keys from t() function calls with various argument patterns
|
|
9
|
+
* - Handles JSX Trans components with complex children serialization
|
|
10
|
+
* - Supports both string literals and selector API for type-safe keys
|
|
11
|
+
* - Processes pluralization and context variants
|
|
12
|
+
* - Manages namespace resolution from multiple sources
|
|
13
|
+
*
|
|
14
|
+
* The visitor respects configuration options for separators, function names,
|
|
15
|
+
* component names, and other extraction settings.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const visitors = new ASTVisitors(config, pluginContext, logger)
|
|
20
|
+
* visitors.visit(parsedAST)
|
|
21
|
+
*
|
|
22
|
+
* // The pluginContext will now contain all extracted keys
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class ASTVisitors {
|
|
26
|
+
private readonly pluginContext;
|
|
27
|
+
private readonly config;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private scopeStack;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new AST visitor instance.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Toolkit configuration with extraction settings
|
|
34
|
+
* @param pluginContext - Context for adding discovered translation keys
|
|
35
|
+
* @param logger - Logger for warnings and debug information
|
|
36
|
+
*/
|
|
37
|
+
constructor(config: I18nextToolkitConfig, pluginContext: PluginContext, logger: Logger);
|
|
38
|
+
/**
|
|
39
|
+
* Main entry point for AST traversal.
|
|
40
|
+
* Creates a root scope and begins the recursive walk through the syntax tree.
|
|
41
|
+
*
|
|
42
|
+
* @param node - The root module node to traverse
|
|
43
|
+
*/
|
|
44
|
+
visit(node: Module): void;
|
|
45
|
+
/**
|
|
46
|
+
* Recursively walks through AST nodes, handling scoping and visiting logic.
|
|
47
|
+
*
|
|
48
|
+
* This is the core traversal method that:
|
|
49
|
+
* 1. Manages function scopes (enter/exit)
|
|
50
|
+
* 2. Dispatches to specific handlers based on node type
|
|
51
|
+
* 3. Recursively processes child nodes
|
|
52
|
+
* 4. Maintains proper scope cleanup
|
|
53
|
+
*
|
|
54
|
+
* @param node - The current AST node to process
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private walk;
|
|
59
|
+
/**
|
|
60
|
+
* Enters a new variable scope by pushing a new scope map onto the stack.
|
|
61
|
+
* Used when entering functions to isolate variable declarations.
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
private enterScope;
|
|
66
|
+
/**
|
|
67
|
+
* Exits the current variable scope by popping the top scope map.
|
|
68
|
+
* Used when leaving functions to clean up variable tracking.
|
|
69
|
+
*
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private exitScope;
|
|
73
|
+
/**
|
|
74
|
+
* Stores variable information in the current scope.
|
|
75
|
+
* Used to track translation functions and their configuration.
|
|
76
|
+
*
|
|
77
|
+
* @param name - Variable name to store
|
|
78
|
+
* @param info - Scope information about the variable
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private setVarInScope;
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves variable information from the scope chain.
|
|
85
|
+
* Searches from innermost to outermost scope.
|
|
86
|
+
*
|
|
87
|
+
* @param name - Variable name to look up
|
|
88
|
+
* @returns Scope information if found, undefined otherwise
|
|
89
|
+
*
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
private getVarFromScope;
|
|
93
|
+
/**
|
|
94
|
+
* Handles variable declarations that might define translation functions.
|
|
95
|
+
*
|
|
96
|
+
* Processes two patterns:
|
|
97
|
+
* 1. `const { t } = useTranslation(...)` - React i18next pattern
|
|
98
|
+
* 2. `const t = i18next.getFixedT(...)` - Core i18next pattern
|
|
99
|
+
*
|
|
100
|
+
* Extracts namespace and key prefix information for later use.
|
|
101
|
+
*
|
|
102
|
+
* @param node - Variable declarator node to process
|
|
103
|
+
*
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
private handleVariableDeclarator;
|
|
107
|
+
/**
|
|
108
|
+
* Processes useTranslation hook declarations to extract scope information.
|
|
109
|
+
*
|
|
110
|
+
* Handles various destructuring patterns:
|
|
111
|
+
* - `const [t] = useTranslation('ns')` - Array destructuring
|
|
112
|
+
* - `const { t } = useTranslation('ns')` - Object destructuring
|
|
113
|
+
* - `const { t: myT } = useTranslation('ns')` - Aliased destructuring
|
|
114
|
+
*
|
|
115
|
+
* Extracts namespace from the first argument and keyPrefix from options.
|
|
116
|
+
*
|
|
117
|
+
* @param node - Variable declarator with useTranslation call
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
private handleUseTranslationDeclarator;
|
|
122
|
+
/**
|
|
123
|
+
* Processes getFixedT function declarations to extract scope information.
|
|
124
|
+
*
|
|
125
|
+
* Handles the pattern: `const t = i18next.getFixedT(lng, ns, keyPrefix)`
|
|
126
|
+
* - Ignores the first argument (language)
|
|
127
|
+
* - Extracts namespace from the second argument
|
|
128
|
+
* - Extracts key prefix from the third argument
|
|
129
|
+
*
|
|
130
|
+
* @param node - Variable declarator with getFixedT call
|
|
131
|
+
*
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
private handleGetFixedTDeclarator;
|
|
135
|
+
/**
|
|
136
|
+
* Processes function call expressions to extract translation keys.
|
|
137
|
+
*
|
|
138
|
+
* This is the core extraction method that handles:
|
|
139
|
+
* - Standard t() calls with string literals
|
|
140
|
+
* - Selector API calls with arrow functions: `t($ => $.path.to.key)`
|
|
141
|
+
* - Namespace resolution from multiple sources
|
|
142
|
+
* - Default value extraction from various argument patterns
|
|
143
|
+
* - Pluralization and context handling
|
|
144
|
+
* - Key prefix application from scope
|
|
145
|
+
*
|
|
146
|
+
* @param node - Call expression node to process
|
|
147
|
+
*
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
private handleCallExpression;
|
|
151
|
+
/**
|
|
152
|
+
* Generates plural form keys based on the primary language's plural rules.
|
|
153
|
+
*
|
|
154
|
+
* Uses Intl.PluralRules to determine the correct plural categories
|
|
155
|
+
* for the configured primary language and generates suffixed keys
|
|
156
|
+
* for each category (e.g., 'item_one', 'item_other').
|
|
157
|
+
*
|
|
158
|
+
* @param key - Base key name for pluralization
|
|
159
|
+
* @param defaultValue - Default value to use for all plural forms
|
|
160
|
+
* @param ns - Namespace for the keys
|
|
161
|
+
*
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
164
|
+
private handlePluralKeys;
|
|
165
|
+
/**
|
|
166
|
+
* Extracts default value from translation function call arguments.
|
|
167
|
+
*
|
|
168
|
+
* Supports multiple patterns:
|
|
169
|
+
* - String as second argument: `t('key', 'Default')`
|
|
170
|
+
* - Object with defaultValue: `t('key', { defaultValue: 'Default' })`
|
|
171
|
+
* - Falls back to the key itself if no default found
|
|
172
|
+
*
|
|
173
|
+
* @param node - Call expression node
|
|
174
|
+
* @param fallback - Fallback value if no default found
|
|
175
|
+
* @returns Extracted default value
|
|
176
|
+
*
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
private getDefaultValue;
|
|
180
|
+
/**
|
|
181
|
+
* Processes JSX elements to extract translation keys from Trans components.
|
|
182
|
+
*
|
|
183
|
+
* Identifies configured Trans components and delegates to the JSX parser
|
|
184
|
+
* for complex children serialization and attribute extraction.
|
|
185
|
+
*
|
|
186
|
+
* @param node - JSX element node to process
|
|
187
|
+
*
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
private handleJSXElement;
|
|
191
|
+
/**
|
|
192
|
+
* Extracts element name from JSX opening tag.
|
|
193
|
+
*
|
|
194
|
+
* Handles both simple identifiers and member expressions:
|
|
195
|
+
* - `<Trans>` → 'Trans'
|
|
196
|
+
* - `<React.Trans>` → 'React.Trans'
|
|
197
|
+
*
|
|
198
|
+
* @param node - JSX element node
|
|
199
|
+
* @returns Element name or undefined if not extractable
|
|
200
|
+
*
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
private getElementName;
|
|
204
|
+
/**
|
|
205
|
+
* Extracts string value from object property.
|
|
206
|
+
*
|
|
207
|
+
* Looks for properties by name and returns their string values.
|
|
208
|
+
* Used for extracting options like 'ns', 'defaultValue', 'context', etc.
|
|
209
|
+
*
|
|
210
|
+
* @param object - Object expression to search
|
|
211
|
+
* @param propName - Property name to find
|
|
212
|
+
* @returns String value if found, empty string if property exists but isn't a string, undefined if not found
|
|
213
|
+
*
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
private getObjectPropValue;
|
|
217
|
+
/**
|
|
218
|
+
* Extracts translation key from selector API arrow function.
|
|
219
|
+
*
|
|
220
|
+
* Processes selector expressions like:
|
|
221
|
+
* - `$ => $.path.to.key` → 'path.to.key'
|
|
222
|
+
* - `$ => $.app['title'].main` → 'app.title.main'
|
|
223
|
+
* - `$ => { return $.nested.key; }` → 'nested.key'
|
|
224
|
+
*
|
|
225
|
+
* Handles both dot notation and bracket notation, respecting
|
|
226
|
+
* the configured key separator or flat key structure.
|
|
227
|
+
*
|
|
228
|
+
* @param node - Arrow function expression from selector call
|
|
229
|
+
* @returns Extracted key path or null if not statically analyzable
|
|
230
|
+
*
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
233
|
+
private extractKeyFromSelector;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=ast-visitors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-visitors.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/ast-visitors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAmG,MAAM,WAAW,CAAA;AACxI,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAc9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,UAAU,CAAoC;IAEtD;;;;;;OAMG;gBAED,MAAM,EAAE,oBAAoB,EAC5B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM;IAOhB;;;;;OAKG;IACI,KAAK,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAMjC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,IAAI;IAiDZ;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IASvB;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,wBAAwB;IAqBhC;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,8BAA8B;IAiDtC;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,yBAAyB;IAoBjC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,oBAAoB;IAkE5B;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,eAAe;IAgBvB;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IA8CxB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,kBAAkB;IAuB1B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,sBAAsB;CA0C/B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PluginContext, I18nextToolkitConfig } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts translation keys from comments in source code using regex patterns.
|
|
4
|
+
* Supports extraction from single-line (//) and multi-line comments.
|
|
5
|
+
*
|
|
6
|
+
* @param code - The source code to analyze
|
|
7
|
+
* @param functionNames - Array of function names to look for (e.g., ['t', 'i18n.t'])
|
|
8
|
+
* @param pluginContext - Context object with helper methods to add found keys
|
|
9
|
+
* @param config - Configuration object containing extraction settings
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const code = `
|
|
14
|
+
* // t('user.name', 'User Name')
|
|
15
|
+
* /* t('app.title', { defaultValue: 'My App', ns: 'common' }) *\/
|
|
16
|
+
* `
|
|
17
|
+
*
|
|
18
|
+
* const context = createPluginContext(allKeys)
|
|
19
|
+
* extractKeysFromComments(code, ['t'], context, config)
|
|
20
|
+
* // Extracts: user.name and app.title with their respective settings
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractKeysFromComments(code: string, functionNames: string[], pluginContext: PluginContext, config: I18nextToolkitConfig): void;
|
|
24
|
+
//# sourceMappingURL=comment-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/comment-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EAAE,EACvB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,oBAAoB,GAC3B,IAAI,CA+BN"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JSXElement } from '@swc/core';
|
|
2
|
+
import type { ExtractedKey, I18nextToolkitConfig } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts translation keys from JSX Trans components.
|
|
5
|
+
*
|
|
6
|
+
* This function handles various Trans component patterns:
|
|
7
|
+
* - Explicit i18nKey prop: `<Trans i18nKey="my.key">content</Trans>`
|
|
8
|
+
* - Implicit keys from children: `<Trans>Hello World</Trans>`
|
|
9
|
+
* - Namespace specification: `<Trans ns="common">content</Trans>`
|
|
10
|
+
* - Default values: `<Trans defaults="Default text">content</Trans>`
|
|
11
|
+
* - Pluralization: `<Trans count={count}>content</Trans>`
|
|
12
|
+
* - HTML preservation: `<Trans>Hello <strong>world</strong></Trans>`
|
|
13
|
+
*
|
|
14
|
+
* @param node - The JSX element node to process
|
|
15
|
+
* @param config - The toolkit configuration containing extraction settings
|
|
16
|
+
* @returns Extracted key information or null if no valid key found
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Input JSX:
|
|
21
|
+
* // <Trans i18nKey="welcome.title" ns="home" defaults="Welcome!">
|
|
22
|
+
* // Welcome to our <strong>amazing</strong> app!
|
|
23
|
+
* // </Trans>
|
|
24
|
+
*
|
|
25
|
+
* const result = extractFromTransComponent(jsxNode, config)
|
|
26
|
+
* // Returns: {
|
|
27
|
+
* // key: 'welcome.title',
|
|
28
|
+
* // ns: 'home',
|
|
29
|
+
* // defaultValue: 'Welcome!',
|
|
30
|
+
* // hasCount: false
|
|
31
|
+
* // }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function extractFromTransComponent(node: JSXElement, config: I18nextToolkitConfig): ExtractedKey | null;
|
|
35
|
+
//# sourceMappingURL=jsx-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-parser.d.ts","sourceRoot":"","sources":["../../../src/extractor/parsers/jsx-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,yBAAyB,CAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,oBAAoB,GAAG,YAAY,GAAG,IAAI,CAkD9G"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ExtractedKey, PluginContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Initializes an array of plugins by calling their setup hooks.
|
|
4
|
+
* This function should be called before starting the extraction process.
|
|
5
|
+
*
|
|
6
|
+
* @param plugins - Array of plugin objects to initialize
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const plugins = [customPlugin(), anotherPlugin()]
|
|
11
|
+
* await initializePlugins(plugins)
|
|
12
|
+
* // All plugin setup hooks have been called
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function initializePlugins(plugins: any[]): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a plugin context object that provides helper methods for plugins.
|
|
18
|
+
* The context allows plugins to add extracted keys to the main collection.
|
|
19
|
+
*
|
|
20
|
+
* @param allKeys - The main map where extracted keys are stored
|
|
21
|
+
* @returns A context object with helper methods for plugins
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const allKeys = new Map()
|
|
26
|
+
* const context = createPluginContext(allKeys)
|
|
27
|
+
*
|
|
28
|
+
* // Plugin can now add keys
|
|
29
|
+
* context.addKey({
|
|
30
|
+
* key: 'my.custom.key',
|
|
31
|
+
* defaultValue: 'Default Value',
|
|
32
|
+
* ns: 'common'
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPluginContext(allKeys: Map<string, ExtractedKey>): PluginContext;
|
|
37
|
+
//# sourceMappingURL=plugin-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-manager.d.ts","sourceRoot":"","sources":["../../src/extractor/plugin-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE3D;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAItE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,aAAa,CAYtF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { runExtractor, extract } from './extractor/core/extractor';
|
|
2
|
+
import { findKeys } from './extractor/core/key-finder';
|
|
3
|
+
import { getTranslations } from './extractor/core/translation-manager';
|
|
4
|
+
import { ASTVisitors } from './extractor/parsers/ast-visitors';
|
|
5
|
+
import type { PluginContext } from './types';
|
|
6
|
+
export { runExtractor, extract, findKeys, getTranslations, ASTVisitors, PluginContext, };
|
|
7
|
+
//# sourceMappingURL=extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../src/extractor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,OAAO,EACP,QAAQ,EACR,eAAe,EACf,WAAW,EACX,aAAa,GACd,CAAA"}
|