@breadstone-tools/localizator-core 0.0.12-beta.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/Detectors/Abstracts/BaseDetector.d.ts +81 -0
- package/Detectors/Abstracts/BaseDetector.d.ts.map +1 -0
- package/Detectors/Abstracts/BaseDetector.js +137 -0
- package/Detectors/Abstracts/BaseDetector.js.map +1 -0
- package/Detectors/AngularHTMLDetector.d.ts +94 -0
- package/Detectors/AngularHTMLDetector.d.ts.map +1 -0
- package/Detectors/AngularHTMLDetector.js +123 -0
- package/Detectors/AngularHTMLDetector.js.map +1 -0
- package/Detectors/Interfaces/IDetector.d.ts +73 -0
- package/Detectors/Interfaces/IDetector.d.ts.map +1 -0
- package/Detectors/Interfaces/IDetector.js +12 -0
- package/Detectors/Interfaces/IDetector.js.map +1 -0
- package/Detectors/JSXDetector.d.ts +69 -0
- package/Detectors/JSXDetector.d.ts.map +1 -0
- package/Detectors/JSXDetector.js +101 -0
- package/Detectors/JSXDetector.js.map +1 -0
- package/Detectors/JavaScriptDetector.d.ts +74 -0
- package/Detectors/JavaScriptDetector.d.ts.map +1 -0
- package/Detectors/JavaScriptDetector.js +106 -0
- package/Detectors/JavaScriptDetector.js.map +1 -0
- package/Detectors/TSXDetector.d.ts +76 -0
- package/Detectors/TSXDetector.d.ts.map +1 -0
- package/Detectors/TSXDetector.js +101 -0
- package/Detectors/TSXDetector.js.map +1 -0
- package/Detectors/TypeScriptDetector.d.ts +76 -0
- package/Detectors/TypeScriptDetector.d.ts.map +1 -0
- package/Detectors/TypeScriptDetector.js +102 -0
- package/Detectors/TypeScriptDetector.js.map +1 -0
- package/Detectors/Utils.d.ts +41 -0
- package/Detectors/Utils.d.ts.map +1 -0
- package/Detectors/Utils.js +62 -0
- package/Detectors/Utils.js.map +1 -0
- package/Detectors/VueDetector.d.ts +60 -0
- package/Detectors/VueDetector.d.ts.map +1 -0
- package/Detectors/VueDetector.js +108 -0
- package/Detectors/VueDetector.js.map +1 -0
- package/Formatters/Formatters.d.ts +15 -0
- package/Formatters/Formatters.d.ts.map +1 -0
- package/Formatters/Formatters.js +34 -0
- package/Formatters/Formatters.js.map +1 -0
- package/Formatters/Interfaces/IFormatter.d.ts +24 -0
- package/Formatters/Interfaces/IFormatter.d.ts.map +1 -0
- package/Formatters/Interfaces/IFormatter.js +3 -0
- package/Formatters/Interfaces/IFormatter.js.map +1 -0
- package/Formatters/JsonFormatter.d.ts +26 -0
- package/Formatters/JsonFormatter.d.ts.map +1 -0
- package/Formatters/JsonFormatter.js +42 -0
- package/Formatters/JsonFormatter.js.map +1 -0
- package/Formatters/ResxFormatter.d.ts +26 -0
- package/Formatters/ResxFormatter.d.ts.map +1 -0
- package/Formatters/ResxFormatter.js +53 -0
- package/Formatters/ResxFormatter.js.map +1 -0
- package/Index.d.ts +57 -0
- package/Index.d.ts.map +1 -0
- package/Index.js +86 -0
- package/Index.js.map +1 -0
- package/LICENSE +21 -0
- package/Presets/AngularPreset.d.ts +38 -0
- package/Presets/AngularPreset.d.ts.map +1 -0
- package/Presets/AngularPreset.js +59 -0
- package/Presets/AngularPreset.js.map +1 -0
- package/Presets/Interfaces/IFrameworkPreset.d.ts +28 -0
- package/Presets/Interfaces/IFrameworkPreset.d.ts.map +1 -0
- package/Presets/Interfaces/IFrameworkPreset.js +4 -0
- package/Presets/Interfaces/IFrameworkPreset.js.map +1 -0
- package/Presets/LitPreset.d.ts +38 -0
- package/Presets/LitPreset.d.ts.map +1 -0
- package/Presets/LitPreset.js +57 -0
- package/Presets/LitPreset.js.map +1 -0
- package/Presets/Presets.d.ts +25 -0
- package/Presets/Presets.d.ts.map +1 -0
- package/Presets/Presets.js +50 -0
- package/Presets/Presets.js.map +1 -0
- package/Presets/ReactPreset.d.ts +38 -0
- package/Presets/ReactPreset.d.ts.map +1 -0
- package/Presets/ReactPreset.js +61 -0
- package/Presets/ReactPreset.js.map +1 -0
- package/Presets/StencilPreset.d.ts +38 -0
- package/Presets/StencilPreset.d.ts.map +1 -0
- package/Presets/StencilPreset.js +59 -0
- package/Presets/StencilPreset.js.map +1 -0
- package/Presets/VuePreset.d.ts +38 -0
- package/Presets/VuePreset.d.ts.map +1 -0
- package/Presets/VuePreset.js +60 -0
- package/Presets/VuePreset.js.map +1 -0
- package/Resources/Analyzers/ResourceAnalyzer.d.ts +58 -0
- package/Resources/Analyzers/ResourceAnalyzer.d.ts.map +1 -0
- package/Resources/Analyzers/ResourceAnalyzer.js +119 -0
- package/Resources/Analyzers/ResourceAnalyzer.js.map +1 -0
- package/Resources/Analyzers/Tasks/DuplicateKeysTask.d.ts +31 -0
- package/Resources/Analyzers/Tasks/DuplicateKeysTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/DuplicateKeysTask.js +40 -0
- package/Resources/Analyzers/Tasks/DuplicateKeysTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/EmptyValuesTask.d.ts +31 -0
- package/Resources/Analyzers/Tasks/EmptyValuesTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/EmptyValuesTask.js +41 -0
- package/Resources/Analyzers/Tasks/EmptyValuesTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/Interfaces/IAnalyzerTask.d.ts +36 -0
- package/Resources/Analyzers/Tasks/Interfaces/IAnalyzerTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/Interfaces/IAnalyzerTask.js +4 -0
- package/Resources/Analyzers/Tasks/Interfaces/IAnalyzerTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/KeyConsistencyTask.d.ts +35 -0
- package/Resources/Analyzers/Tasks/KeyConsistencyTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/KeyConsistencyTask.js +67 -0
- package/Resources/Analyzers/Tasks/KeyConsistencyTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/MissingTranslationsTask.d.ts +31 -0
- package/Resources/Analyzers/Tasks/MissingTranslationsTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/MissingTranslationsTask.js +44 -0
- package/Resources/Analyzers/Tasks/MissingTranslationsTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/MultipleKeyUsageTask.d.ts +31 -0
- package/Resources/Analyzers/Tasks/MultipleKeyUsageTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/MultipleKeyUsageTask.js +48 -0
- package/Resources/Analyzers/Tasks/MultipleKeyUsageTask.js.map +1 -0
- package/Resources/Analyzers/Tasks/UnusedKeysTask.d.ts +31 -0
- package/Resources/Analyzers/Tasks/UnusedKeysTask.d.ts.map +1 -0
- package/Resources/Analyzers/Tasks/UnusedKeysTask.js +49 -0
- package/Resources/Analyzers/Tasks/UnusedKeysTask.js.map +1 -0
- package/Resources/Models/Interfaces/IJsonResourceInfo.d.ts +12 -0
- package/Resources/Models/Interfaces/IJsonResourceInfo.d.ts.map +1 -0
- package/Resources/Models/Interfaces/IJsonResourceInfo.js +4 -0
- package/Resources/Models/Interfaces/IJsonResourceInfo.js.map +1 -0
- package/Resources/Models/Interfaces/IResourceInfo.d.ts +71 -0
- package/Resources/Models/Interfaces/IResourceInfo.d.ts.map +1 -0
- package/Resources/Models/Interfaces/IResourceInfo.js +4 -0
- package/Resources/Models/Interfaces/IResourceInfo.js.map +1 -0
- package/Resources/Models/Interfaces/IResourceModel.d.ts +41 -0
- package/Resources/Models/Interfaces/IResourceModel.d.ts.map +1 -0
- package/Resources/Models/Interfaces/IResourceModel.js +25 -0
- package/Resources/Models/Interfaces/IResourceModel.js.map +1 -0
- package/Resources/Models/Interfaces/IResxResourceInfo.d.ts +12 -0
- package/Resources/Models/Interfaces/IResxResourceInfo.d.ts.map +1 -0
- package/Resources/Models/Interfaces/IResxResourceInfo.js +4 -0
- package/Resources/Models/Interfaces/IResxResourceInfo.js.map +1 -0
- package/Resources/Models/Interfaces/ITypeScriptResourceInfo.d.ts +11 -0
- package/Resources/Models/Interfaces/ITypeScriptResourceInfo.d.ts.map +1 -0
- package/Resources/Models/Interfaces/ITypeScriptResourceInfo.js +4 -0
- package/Resources/Models/Interfaces/ITypeScriptResourceInfo.js.map +1 -0
- package/Resources/Models/Interfaces/ResourceType.d.ts +29 -0
- package/Resources/Models/Interfaces/ResourceType.d.ts.map +1 -0
- package/Resources/Models/Interfaces/ResourceType.js +45 -0
- package/Resources/Models/Interfaces/ResourceType.js.map +1 -0
- package/Resources/Models/JsonResourceInfo.d.ts +111 -0
- package/Resources/Models/JsonResourceInfo.d.ts.map +1 -0
- package/Resources/Models/JsonResourceInfo.js +184 -0
- package/Resources/Models/JsonResourceInfo.js.map +1 -0
- package/Resources/Models/ResxResourceInfo.d.ts +110 -0
- package/Resources/Models/ResxResourceInfo.d.ts.map +1 -0
- package/Resources/Models/ResxResourceInfo.js +171 -0
- package/Resources/Models/ResxResourceInfo.js.map +1 -0
- package/Resources/Models/TypeScriptResourceInfo.d.ts +109 -0
- package/Resources/Models/TypeScriptResourceInfo.d.ts.map +1 -0
- package/Resources/Models/TypeScriptResourceInfo.js +244 -0
- package/Resources/Models/TypeScriptResourceInfo.js.map +1 -0
- package/Resources/ResourceFactory.d.ts +39 -0
- package/Resources/ResourceFactory.d.ts.map +1 -0
- package/Resources/ResourceFactory.js +102 -0
- package/Resources/ResourceFactory.js.map +1 -0
- package/Resources/ResourceMode.d.ts +14 -0
- package/Resources/ResourceMode.d.ts.map +1 -0
- package/Resources/ResourceMode.js +18 -0
- package/Resources/ResourceMode.js.map +1 -0
- package/Resources/ResourceProcessor.d.ts +66 -0
- package/Resources/ResourceProcessor.d.ts.map +1 -0
- package/Resources/ResourceProcessor.js +90 -0
- package/Resources/ResourceProcessor.js.map +1 -0
- package/Resources/Scanners/Adapter/Interfaces/IScannerAdapter.d.ts +17 -0
- package/Resources/Scanners/Adapter/Interfaces/IScannerAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/Interfaces/IScannerAdapter.js +4 -0
- package/Resources/Scanners/Adapter/Interfaces/IScannerAdapter.js.map +1 -0
- package/Resources/Scanners/Adapter/JsonScannerAdapter.d.ts +28 -0
- package/Resources/Scanners/Adapter/JsonScannerAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/JsonScannerAdapter.js +62 -0
- package/Resources/Scanners/Adapter/JsonScannerAdapter.js.map +1 -0
- package/Resources/Scanners/Adapter/ResxScannerAdapter.d.ts +28 -0
- package/Resources/Scanners/Adapter/ResxScannerAdapter.d.ts.map +1 -0
- package/Resources/Scanners/Adapter/ResxScannerAdapter.js +62 -0
- package/Resources/Scanners/Adapter/ResxScannerAdapter.js.map +1 -0
- package/Resources/Scanners/ResourceScanner.d.ts +32 -0
- package/Resources/Scanners/ResourceScanner.d.ts.map +1 -0
- package/Resources/Scanners/ResourceScanner.js +59 -0
- package/Resources/Scanners/ResourceScanner.js.map +1 -0
- package/Resources/Sorting/ResourceSorter.d.ts +46 -0
- package/Resources/Sorting/ResourceSorter.d.ts.map +1 -0
- package/Resources/Sorting/ResourceSorter.js +82 -0
- package/Resources/Sorting/ResourceSorter.js.map +1 -0
- package/Resources/Transformers/Adapters/Abstracts/BaseResourceTransformerAdapter.d.ts +20 -0
- package/Resources/Transformers/Adapters/Abstracts/BaseResourceTransformerAdapter.d.ts.map +1 -0
- package/Resources/Transformers/Adapters/Abstracts/BaseResourceTransformerAdapter.js +15 -0
- package/Resources/Transformers/Adapters/Abstracts/BaseResourceTransformerAdapter.js.map +1 -0
- package/Resources/Transformers/Adapters/Interfaces/IResourceTransformerAdapter.d.ts +11 -0
- package/Resources/Transformers/Adapters/Interfaces/IResourceTransformerAdapter.d.ts.map +1 -0
- package/Resources/Transformers/Adapters/Interfaces/IResourceTransformerAdapter.js +4 -0
- package/Resources/Transformers/Adapters/Interfaces/IResourceTransformerAdapter.js.map +1 -0
- package/Resources/Transformers/Adapters/JsonResourceTransformerAdapter.d.ts +26 -0
- package/Resources/Transformers/Adapters/JsonResourceTransformerAdapter.d.ts.map +1 -0
- package/Resources/Transformers/Adapters/JsonResourceTransformerAdapter.js +64 -0
- package/Resources/Transformers/Adapters/JsonResourceTransformerAdapter.js.map +1 -0
- package/Resources/Transformers/Adapters/ResxResourceTransformerAdapter.d.ts +19 -0
- package/Resources/Transformers/Adapters/ResxResourceTransformerAdapter.d.ts.map +1 -0
- package/Resources/Transformers/Adapters/ResxResourceTransformerAdapter.js +30 -0
- package/Resources/Transformers/Adapters/ResxResourceTransformerAdapter.js.map +1 -0
- package/Resources/Transformers/Interfaces/IResourceTransformerResult.d.ts +11 -0
- package/Resources/Transformers/Interfaces/IResourceTransformerResult.d.ts.map +1 -0
- package/Resources/Transformers/Interfaces/IResourceTransformerResult.js +4 -0
- package/Resources/Transformers/Interfaces/IResourceTransformerResult.js.map +1 -0
- package/Resources/Transformers/ResourceTransformer.d.ts +74 -0
- package/Resources/Transformers/ResourceTransformer.d.ts.map +1 -0
- package/Resources/Transformers/ResourceTransformer.js +112 -0
- package/Resources/Transformers/ResourceTransformer.js.map +1 -0
- package/Resources/Transformers/Serializers/Interfaces/IResourceSerializer.d.ts +9 -0
- package/Resources/Transformers/Serializers/Interfaces/IResourceSerializer.d.ts.map +1 -0
- package/Resources/Transformers/Serializers/Interfaces/IResourceSerializer.js +4 -0
- package/Resources/Transformers/Serializers/Interfaces/IResourceSerializer.js.map +1 -0
- package/Resources/Transformers/Serializers/JsonResourceSerializer.d.ts +20 -0
- package/Resources/Transformers/Serializers/JsonResourceSerializer.d.ts.map +1 -0
- package/Resources/Transformers/Serializers/JsonResourceSerializer.js +47 -0
- package/Resources/Transformers/Serializers/JsonResourceSerializer.js.map +1 -0
- package/Resources/Transformers/Serializers/ResxResourceSerializer.d.ts +20 -0
- package/Resources/Transformers/Serializers/ResxResourceSerializer.d.ts.map +1 -0
- package/Resources/Transformers/Serializers/ResxResourceSerializer.js +36 -0
- package/Resources/Transformers/Serializers/ResxResourceSerializer.js.map +1 -0
- package/Resources/Transformers/Serializers/TypescriptResourceSerializer.d.ts +20 -0
- package/Resources/Transformers/Serializers/TypescriptResourceSerializer.d.ts.map +1 -0
- package/Resources/Transformers/Serializers/TypescriptResourceSerializer.js +36 -0
- package/Resources/Transformers/Serializers/TypescriptResourceSerializer.js.map +1 -0
- package/Services/DiffService.d.ts +1 -0
- package/Services/DiffService.d.ts.map +1 -0
- package/Services/DiffService.js +86 -0
- package/Services/DiffService.js.map +1 -0
- package/Services/KeyGenerator.d.ts +21 -0
- package/Services/KeyGenerator.d.ts.map +1 -0
- package/Services/KeyGenerator.js +34 -0
- package/Services/KeyGenerator.js.map +1 -0
- package/Services/LocalizationProcessor.d.ts +83 -0
- package/Services/LocalizationProcessor.d.ts.map +1 -0
- package/Services/LocalizationProcessor.js +90 -0
- package/Services/LocalizationProcessor.js.map +1 -0
- package/package.json +19 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.JSXDetector = void 0;
|
|
5
|
+
const BaseDetector_js_1 = require("./Abstracts/BaseDetector.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Detector for extracting translatable strings from JSX files.
|
|
9
|
+
*
|
|
10
|
+
* This detector supports the following scenarios:
|
|
11
|
+
* - **Simple Function Calls**:
|
|
12
|
+
* ```jsx
|
|
13
|
+
* t("This is a translatable string");
|
|
14
|
+
* translate("Another translatable string");
|
|
15
|
+
* ```
|
|
16
|
+
* - **With Context**:
|
|
17
|
+
* ```jsx
|
|
18
|
+
* t("This is translatable", { context: "example" });
|
|
19
|
+
* ```
|
|
20
|
+
* - **Template Literals**:
|
|
21
|
+
* ```jsx
|
|
22
|
+
* t(`This is a template literal`);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
class JSXDetector extends BaseDetector_js_1.BaseDetector {
|
|
28
|
+
// #region Fields
|
|
29
|
+
_marker;
|
|
30
|
+
// #endregion
|
|
31
|
+
// #region Constructor
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new instance of the `JSXDetector` class.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @param logger - The logger.
|
|
37
|
+
* @param options - Configuration options for the detector.
|
|
38
|
+
*/
|
|
39
|
+
constructor(logger, options) {
|
|
40
|
+
super(logger, options);
|
|
41
|
+
this._marker = options?.marker ?? /t|translate/;
|
|
42
|
+
}
|
|
43
|
+
// #endregion
|
|
44
|
+
// #region Methods
|
|
45
|
+
/**
|
|
46
|
+
* Provides the regex patterns for extracting strings from JSX content.
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
* @returns A RegExp for extracting strings.
|
|
50
|
+
*/
|
|
51
|
+
getRegexes() {
|
|
52
|
+
const functionPattern = this._marker instanceof RegExp
|
|
53
|
+
? this._marker.source
|
|
54
|
+
: (0, Utils_js_1.escapeRegExp)(this._marker);
|
|
55
|
+
return [
|
|
56
|
+
new RegExp(`(?<function>${functionPattern})` + // Function name
|
|
57
|
+
'\\(' + // Opening parenthesis
|
|
58
|
+
'\\s*' + // Optional whitespace
|
|
59
|
+
"(?<quote>['\"`])" + // Quote type
|
|
60
|
+
'(?<value>(?:\\\\.|[^\\\\])*?)' + // Content inside quotes
|
|
61
|
+
'\\k<quote>' + // Match the same quote type
|
|
62
|
+
'(?:,\\s*(?<context>\\{.*?\\}))?' + // Optional context object
|
|
63
|
+
'\\)', // Closing parenthesis
|
|
64
|
+
'gs')
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Pre-processes content before applying regex matching.
|
|
69
|
+
*
|
|
70
|
+
* @protected
|
|
71
|
+
* @param content - The raw content.
|
|
72
|
+
* @returns The processed content.
|
|
73
|
+
*/
|
|
74
|
+
preProcessContent(content) {
|
|
75
|
+
this.log('Pre-processing JSX content.');
|
|
76
|
+
return content.replace(/\r?\n/g, ' '); // Normalize multiline strings
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Post-processes results after regex matching.
|
|
80
|
+
*
|
|
81
|
+
* @protected
|
|
82
|
+
* @param results - The raw results from regex matching.
|
|
83
|
+
* @returns The processed results.
|
|
84
|
+
*/
|
|
85
|
+
postProcessResults(results) {
|
|
86
|
+
this.log(`Post-processing JSX results: ${JSON.stringify(results)}`);
|
|
87
|
+
return results
|
|
88
|
+
.filter((result) => result.match.value !== undefined)
|
|
89
|
+
.map((result) => {
|
|
90
|
+
if (result.match.value !== undefined) {
|
|
91
|
+
result.match.value = result.match.value
|
|
92
|
+
.replace(/\\"/g, '"') // Unescape double quotes
|
|
93
|
+
.replace(/\\'/g, "'") // Unescape single quotes
|
|
94
|
+
.trim(); // Remove extra whitespace
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.JSXDetector = JSXDetector;
|
|
101
|
+
//# sourceMappingURL=JSXDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSXDetector.js","sourceRoot":"","sources":["../../src/Detectors/JSXDetector.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,iEAAsF;AAEtF,yCAA0C;AAkB1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,WAAY,SAAQ,8BAAY;IAEzC,iBAAiB;IAEA,OAAO,CAAkB;IAE1C,aAAa;IAEb,sBAAsB;IAEtB;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,OAA6B;QAC7D,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEvB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,IAAI,aAAa,CAAC;IACpD,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACgB,UAAU;QACzB,MAAM,eAAe,GACjB,IAAI,CAAC,OAAO,YAAY,MAAM;YAC1B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;YACrB,CAAC,CAAC,IAAA,uBAAY,EAA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+1,74 @@
|
|
|
1
|
+
import type { ILogger } from '@breadstone-infrastructure/utilities';
|
|
2
|
+
import { BaseDetector, type IBaseDetectorOptions } from './Abstracts/BaseDetector.js';
|
|
3
|
+
import type { IDetectorResult } from './Interfaces/IDetector.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring the `JavaScriptDetector`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface IJavaScriptDetectorOptions extends IBaseDetectorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The function name or regex used for translation (default: `/t|translate/`).
|
|
12
|
+
*/
|
|
13
|
+
marker?: string | RegExp;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Detector for extracting translatable strings from JavaScript files.
|
|
17
|
+
*
|
|
18
|
+
* This detector supports the following scenarios:
|
|
19
|
+
* - **Simple Function Calls**:
|
|
20
|
+
* ```javascript
|
|
21
|
+
* t("This is a translatable string");
|
|
22
|
+
* translate("Another translatable string");
|
|
23
|
+
* ```
|
|
24
|
+
* - **Multiline Strings**:
|
|
25
|
+
* ```javascript
|
|
26
|
+
* t("This is a \
|
|
27
|
+
* multiline string");
|
|
28
|
+
* ```
|
|
29
|
+
* - **Template Literals**:
|
|
30
|
+
* ```javascript
|
|
31
|
+
* translate(`This is a translatable template literal`);
|
|
32
|
+
* ```
|
|
33
|
+
* - **Function Calls with Context**:
|
|
34
|
+
* ```javascript
|
|
35
|
+
* t("This is translatable", { context: "example" });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export declare class JavaScriptDetector extends BaseDetector {
|
|
41
|
+
private readonly _marker;
|
|
42
|
+
/**
|
|
43
|
+
* Constructs a new instance of the `JavaScriptDetector` class.
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
* @param logger - The logger.
|
|
47
|
+
* @param options - Configuration options for the detector.
|
|
48
|
+
*/
|
|
49
|
+
constructor(logger: ILogger, options?: IJavaScriptDetectorOptions);
|
|
50
|
+
/**
|
|
51
|
+
* Provides the regex patterns for extracting strings from JavaScript content.
|
|
52
|
+
*
|
|
53
|
+
* @protected
|
|
54
|
+
* @returns A RegExp for extracting strings.
|
|
55
|
+
*/
|
|
56
|
+
protected getRegexes(): Array<RegExp>;
|
|
57
|
+
/**
|
|
58
|
+
* Pre-processes content before applying regex matching.
|
|
59
|
+
*
|
|
60
|
+
* @protected
|
|
61
|
+
* @param content - The raw content.
|
|
62
|
+
* @returns The processed content.
|
|
63
|
+
*/
|
|
64
|
+
protected preProcessContent(content: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Post-processes results after regex matching.
|
|
67
|
+
*
|
|
68
|
+
* @protected
|
|
69
|
+
* @param results - The raw results from regex matching.
|
|
70
|
+
* @returns The processed results.
|
|
71
|
+
*/
|
|
72
|
+
protected postProcessResults(results: Array<IDetectorResult>): Array<IDetectorResult>;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=JavaScriptDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JavaScriptDetector.d.ts","sourceRoot":"","sources":["../../src/Detectors/JavaScriptDetector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IAEpE;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAE5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAIhD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAM1C;;;;;;OAMG;gBACgB,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,0BAA0B;IAUxE;;;;;OAKG;cACgB,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;IAqB9C;;;;;;OAMG;cACgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAK7D;;;;;;OAMG;cACgB,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC;CAmBjG"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.JavaScriptDetector = void 0;
|
|
5
|
+
const BaseDetector_js_1 = require("./Abstracts/BaseDetector.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Detector for extracting translatable strings from JavaScript files.
|
|
9
|
+
*
|
|
10
|
+
* This detector supports the following scenarios:
|
|
11
|
+
* - **Simple Function Calls**:
|
|
12
|
+
* ```javascript
|
|
13
|
+
* t("This is a translatable string");
|
|
14
|
+
* translate("Another translatable string");
|
|
15
|
+
* ```
|
|
16
|
+
* - **Multiline Strings**:
|
|
17
|
+
* ```javascript
|
|
18
|
+
* t("This is a \
|
|
19
|
+
* multiline string");
|
|
20
|
+
* ```
|
|
21
|
+
* - **Template Literals**:
|
|
22
|
+
* ```javascript
|
|
23
|
+
* translate(`This is a translatable template literal`);
|
|
24
|
+
* ```
|
|
25
|
+
* - **Function Calls with Context**:
|
|
26
|
+
* ```javascript
|
|
27
|
+
* t("This is translatable", { context: "example" });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
class JavaScriptDetector extends BaseDetector_js_1.BaseDetector {
|
|
33
|
+
// #region Fields
|
|
34
|
+
_marker;
|
|
35
|
+
// #endregion
|
|
36
|
+
// #region Constructor
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a new instance of the `JavaScriptDetector` class.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
* @param logger - The logger.
|
|
42
|
+
* @param options - Configuration options for the detector.
|
|
43
|
+
*/
|
|
44
|
+
constructor(logger, options) {
|
|
45
|
+
super(logger, options);
|
|
46
|
+
this._marker = options?.marker ?? /t|translate/;
|
|
47
|
+
}
|
|
48
|
+
// #endregion
|
|
49
|
+
// #region Methods
|
|
50
|
+
/**
|
|
51
|
+
* Provides the regex patterns for extracting strings from JavaScript content.
|
|
52
|
+
*
|
|
53
|
+
* @protected
|
|
54
|
+
* @returns A RegExp for extracting strings.
|
|
55
|
+
*/
|
|
56
|
+
getRegexes() {
|
|
57
|
+
const functionPattern = this._marker instanceof RegExp
|
|
58
|
+
? this._marker.source
|
|
59
|
+
: (0, Utils_js_1.escapeRegExp)(this._marker);
|
|
60
|
+
return [
|
|
61
|
+
new RegExp(`(?<function>${functionPattern})` + // Function name
|
|
62
|
+
'\\(' + // Opening parenthesis
|
|
63
|
+
'\\s*' + // Optional whitespace
|
|
64
|
+
"(?<quote>['\"`])" + // Quote type
|
|
65
|
+
'(?<value>(?:\\\\.|[^\\\\])*?)' + // Content inside quotes, including escaped quotes
|
|
66
|
+
'\\k<quote>' + // Match the same quote type
|
|
67
|
+
'(?:,\\s*(?<context>\\{.*?\\}))?' + // Optional context object
|
|
68
|
+
'\\)', // Closing parenthesis
|
|
69
|
+
'gs')
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Pre-processes content before applying regex matching.
|
|
74
|
+
*
|
|
75
|
+
* @protected
|
|
76
|
+
* @param content - The raw content.
|
|
77
|
+
* @returns The processed content.
|
|
78
|
+
*/
|
|
79
|
+
preProcessContent(content) {
|
|
80
|
+
this.log('Pre-processing JavaScript content.');
|
|
81
|
+
return content.replace(/\r?\n/g, ' '); // Normalize multiline strings
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Post-processes results after regex matching.
|
|
85
|
+
*
|
|
86
|
+
* @protected
|
|
87
|
+
* @param results - The raw results from regex matching.
|
|
88
|
+
* @returns The processed results.
|
|
89
|
+
*/
|
|
90
|
+
postProcessResults(results) {
|
|
91
|
+
this.log(`Post-processing results: ${JSON.stringify(results)}`);
|
|
92
|
+
return results
|
|
93
|
+
.filter((result) => result.match.value !== undefined)
|
|
94
|
+
.map((result) => {
|
|
95
|
+
if (result.match.value !== undefined) {
|
|
96
|
+
result.match.value = result.match.value
|
|
97
|
+
.replace(/\\"/g, '"') // Unescape double quotes
|
|
98
|
+
.replace(/\\'/g, "'") // Unescape single quotes
|
|
99
|
+
.trim(); // Remove extra whitespace
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.JavaScriptDetector = JavaScriptDetector;
|
|
106
|
+
//# sourceMappingURL=JavaScriptDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JavaScriptDetector.js","sourceRoot":"","sources":["../../src/Detectors/JavaScriptDetector.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,iEAAsF;AAEtF,yCAA0C;AAkB1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,kBAAmB,SAAQ,8BAAY;IAEhD,iBAAiB;IAEA,OAAO,CAAkB;IAE1C,aAAa;IAEb,sBAAsB;IAEtB;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,OAAoC;QACpE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEvB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,IAAI,aAAa,CAAC;IACpD,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACgB,UAAU;QACzB,MAAM,eAAe,GACjB,IAAI,CAAC,OAAO,YAAY,MAAM;YAC1B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;YACrB,CA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,gDA4FC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ILogger } from '@breadstone-infrastructure/utilities';
|
|
2
|
+
import { BaseDetector, type IBaseDetectorOptions } from './Abstracts/BaseDetector.js';
|
|
3
|
+
import type { IDetectorResult } from './Interfaces/IDetector.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring the `TSXDetector`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ITSXDetectorOptions extends IBaseDetectorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The function name or regex used for translation (default: `/t|translate/`).
|
|
12
|
+
*/
|
|
13
|
+
marker?: string | RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* The resource key check configuration for the detector.
|
|
16
|
+
*/
|
|
17
|
+
resourceKey?: {
|
|
18
|
+
prefix?: string;
|
|
19
|
+
suffix?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Detector for extracting translatable strings from TSX files.
|
|
24
|
+
*
|
|
25
|
+
* This detector supports the following scenarios:
|
|
26
|
+
* - **Simple Function Calls**:
|
|
27
|
+
* ```tsx
|
|
28
|
+
* t("This is a translatable string");
|
|
29
|
+
* translate("Another translatable string");
|
|
30
|
+
* ```
|
|
31
|
+
* - **With Context**:
|
|
32
|
+
* ```tsx
|
|
33
|
+
* t("This is translatable", { context: "example" });
|
|
34
|
+
* ```
|
|
35
|
+
* - **Template Literals**:
|
|
36
|
+
* ```tsx
|
|
37
|
+
* t(`This is a template literal`);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare class TSXDetector extends BaseDetector {
|
|
43
|
+
private readonly _marker;
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a new instance of the `TSXDetector` class.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @param logger - The logger.
|
|
49
|
+
* @param options - Configuration options for the detector.
|
|
50
|
+
*/
|
|
51
|
+
constructor(logger: ILogger, options?: ITSXDetectorOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Provides the regex patterns for extracting strings from TSX content.
|
|
54
|
+
*
|
|
55
|
+
* @protected
|
|
56
|
+
* @returns A RegExp for extracting strings.
|
|
57
|
+
*/
|
|
58
|
+
protected getRegexes(): Array<RegExp>;
|
|
59
|
+
/**
|
|
60
|
+
* Pre-processes content before applying regex matching.
|
|
61
|
+
*
|
|
62
|
+
* @protected
|
|
63
|
+
* @param content - The raw content.
|
|
64
|
+
* @returns The processed content.
|
|
65
|
+
*/
|
|
66
|
+
protected preProcessContent(content: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Post-processes results after regex matching.
|
|
69
|
+
*
|
|
70
|
+
* @protected
|
|
71
|
+
* @param results - The raw results from regex matching.
|
|
72
|
+
* @returns The processed results.
|
|
73
|
+
*/
|
|
74
|
+
protected postProcessResults(results: Array<IDetectorResult>): Array<IDetectorResult>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=TSXDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TSXDetector.d.ts","sourceRoot":"","sources":["../../src/Detectors/TSXDetector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAE7D;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzB;;MAEE;IACF,WAAW,CAAC,EAAE;QACV,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CAEL;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAIzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAM1C;;;;;;OAMG;gBACgB,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB;IAUjE;;;;;OAKG;cACgB,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;IAqB9C;;;;;;OAMG;cACgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAK7D;;;;;;OAMG;cACgB,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC;CAmBjG"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TSXDetector = void 0;
|
|
5
|
+
const BaseDetector_js_1 = require("./Abstracts/BaseDetector.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Detector for extracting translatable strings from TSX files.
|
|
9
|
+
*
|
|
10
|
+
* This detector supports the following scenarios:
|
|
11
|
+
* - **Simple Function Calls**:
|
|
12
|
+
* ```tsx
|
|
13
|
+
* t("This is a translatable string");
|
|
14
|
+
* translate("Another translatable string");
|
|
15
|
+
* ```
|
|
16
|
+
* - **With Context**:
|
|
17
|
+
* ```tsx
|
|
18
|
+
* t("This is translatable", { context: "example" });
|
|
19
|
+
* ```
|
|
20
|
+
* - **Template Literals**:
|
|
21
|
+
* ```tsx
|
|
22
|
+
* t(`This is a template literal`);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
class TSXDetector extends BaseDetector_js_1.BaseDetector {
|
|
28
|
+
// #region Fields
|
|
29
|
+
_marker;
|
|
30
|
+
// #endregion
|
|
31
|
+
// #region Constructor
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new instance of the `TSXDetector` class.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @param logger - The logger.
|
|
37
|
+
* @param options - Configuration options for the detector.
|
|
38
|
+
*/
|
|
39
|
+
constructor(logger, options) {
|
|
40
|
+
super(logger, options);
|
|
41
|
+
this._marker = options?.marker ?? /t|translate/;
|
|
42
|
+
}
|
|
43
|
+
// #endregion
|
|
44
|
+
// #region Methods
|
|
45
|
+
/**
|
|
46
|
+
* Provides the regex patterns for extracting strings from TSX content.
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
* @returns A RegExp for extracting strings.
|
|
50
|
+
*/
|
|
51
|
+
getRegexes() {
|
|
52
|
+
const functionPattern = this._marker instanceof RegExp
|
|
53
|
+
? this._marker.source
|
|
54
|
+
: (0, Utils_js_1.escapeRegExp)(this._marker);
|
|
55
|
+
return [
|
|
56
|
+
new RegExp(`(?<function>${functionPattern})` + // Function name
|
|
57
|
+
'\\(' + // Opening parenthesis
|
|
58
|
+
'\\s*' + // Optional whitespace
|
|
59
|
+
"(?<quote>['\"`])" + // Quote type
|
|
60
|
+
'(?<value>(?:\\\\.|[^\\\\])*?)' + // Content inside quotes
|
|
61
|
+
'\\k<quote>' + // Match the same quote type
|
|
62
|
+
'(?:,\\s*(?<context>\\{.*?\\}))?' + // Optional context object
|
|
63
|
+
'\\)', // Closing parenthesis
|
|
64
|
+
'gs')
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Pre-processes content before applying regex matching.
|
|
69
|
+
*
|
|
70
|
+
* @protected
|
|
71
|
+
* @param content - The raw content.
|
|
72
|
+
* @returns The processed content.
|
|
73
|
+
*/
|
|
74
|
+
preProcessContent(content) {
|
|
75
|
+
this.log('Pre-processing TSX content.');
|
|
76
|
+
return content.replace(/\r?\n/g, ' '); // Normalize multiline strings
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Post-processes results after regex matching.
|
|
80
|
+
*
|
|
81
|
+
* @protected
|
|
82
|
+
* @param results - The raw results from regex matching.
|
|
83
|
+
* @returns The processed results.
|
|
84
|
+
*/
|
|
85
|
+
postProcessResults(results) {
|
|
86
|
+
this.log(`Post-processing TSX results: ${JSON.stringify(results)}`);
|
|
87
|
+
return results
|
|
88
|
+
.filter((result) => result.match.value !== undefined)
|
|
89
|
+
.map((result) => {
|
|
90
|
+
if (result.match.value !== undefined) {
|
|
91
|
+
result.match.value = result.match.value
|
|
92
|
+
.replace(/\\"/g, '"') // Unescape double quotes
|
|
93
|
+
.replace(/\\'/g, "'") // Unescape single quotes
|
|
94
|
+
.trim(); // Remove extra whitespace
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.TSXDetector = TSXDetector;
|
|
101
|
+
//# sourceMappingURL=TSXDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TSXDetector.js","sourceRoot":"","sources":["../../src/Detectors/TSXDetector.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,iEAAsF;AAEtF,yCAA0C;AA0B1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,WAAY,SAAQ,8BAAY;IAEzC,iBAAiB;IAEA,OAAO,CAAkB;IAE1C,aAAa;IAEb,sBAAsB;IAEtB;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,OAA6B;QAC7D,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEvB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,IAAI,aAAa,CAAC;IACpD,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACgB,UAAU;QACzB,MAAM,eAAe,GACjB,IAAI,CAAC,OAAO,YAAY,MAAM;YAC1B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM;YACrB,CAAC,CAAC,IAAA,uBAAY,EAAC,IAAI,CAAC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
|
1
|
+
import type { ILogger } from '@breadstone-infrastructure/utilities';
|
|
2
|
+
import { BaseDetector, type IBaseDetectorOptions } from './Abstracts/BaseDetector.js';
|
|
3
|
+
import type { IDetectorResult } from './Interfaces/IDetector.js';
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring the `TypeScriptDetector`.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export interface ITypeScriptDetectorOptions extends IBaseDetectorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The function name or regex used for translation (default: `/t|translate/`).
|
|
12
|
+
*/
|
|
13
|
+
marker?: string | RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* The resource key check configuration for the detector.
|
|
16
|
+
*/
|
|
17
|
+
resourceKey?: {
|
|
18
|
+
prefix?: string;
|
|
19
|
+
suffix?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Detector for extracting translatable strings from TypeScript files.
|
|
24
|
+
*
|
|
25
|
+
* This detector supports the following scenarios:
|
|
26
|
+
* - **Simple Function Calls**:
|
|
27
|
+
* ```typescript
|
|
28
|
+
* t("This is a translatable string");
|
|
29
|
+
* translate("Another translatable string");
|
|
30
|
+
* ```
|
|
31
|
+
* - **With Context**:
|
|
32
|
+
* ```typescript
|
|
33
|
+
* t("This is translatable", { context: "example" });
|
|
34
|
+
* ```
|
|
35
|
+
* - **Template Literals**:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* t(`This is a template literal`);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare class TypeScriptDetector extends BaseDetector {
|
|
43
|
+
private readonly _marker;
|
|
44
|
+
/**
|
|
45
|
+
* Constructs a new instance of the `TypeScriptDetector` class.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @param logger - The logger instance.
|
|
49
|
+
* @param options - Configuration options for the detector.
|
|
50
|
+
*/
|
|
51
|
+
constructor(logger: ILogger, options?: ITypeScriptDetectorOptions);
|
|
52
|
+
/**
|
|
53
|
+
* Provides the regex patterns for extracting strings from TypeScript content.
|
|
54
|
+
*
|
|
55
|
+
* @protected
|
|
56
|
+
* @returns A RegExp for extracting strings.
|
|
57
|
+
*/
|
|
58
|
+
protected getRegexes(): Array<RegExp>;
|
|
59
|
+
/**
|
|
60
|
+
* Pre-processes content before applying regex matching.
|
|
61
|
+
*
|
|
62
|
+
* @protected
|
|
63
|
+
* @param content - The raw content.
|
|
64
|
+
* @returns The processed content.
|
|
65
|
+
*/
|
|
66
|
+
protected preProcessContent(content: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* Post-processes results after regex matching.
|
|
69
|
+
*
|
|
70
|
+
* @protected
|
|
71
|
+
* @param results - The raw results from regex matching.
|
|
72
|
+
* @returns The processed results.
|
|
73
|
+
*/
|
|
74
|
+
protected postProcessResults(results: Array<IDetectorResult>): Array<IDetectorResult>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=TypeScriptDetector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptDetector.d.ts","sourceRoot":"","sources":["../../src/Detectors/TypeScriptDetector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAKjE;;;;GAIG;AACH,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IAEpE;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,WAAW,CAAC,EAAE;QACV,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CAEL;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAIhD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAM1C;;;;;;OAMG;gBACgB,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,0BAA0B;IAUxE;;;;;OAKG;cACgB,UAAU,IAAI,KAAK,CAAC,MAAM,CAAC;IAsB9C;;;;;;OAMG;cACgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAK7D;;;;;;OAMG;cACgB,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,eAAe,CAAC;CAmBjG"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.TypeScriptDetector = void 0;
|
|
5
|
+
const BaseDetector_js_1 = require("./Abstracts/BaseDetector.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
7
|
+
/**
|
|
8
|
+
* Detector for extracting translatable strings from TypeScript files.
|
|
9
|
+
*
|
|
10
|
+
* This detector supports the following scenarios:
|
|
11
|
+
* - **Simple Function Calls**:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* t("This is a translatable string");
|
|
14
|
+
* translate("Another translatable string");
|
|
15
|
+
* ```
|
|
16
|
+
* - **With Context**:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* t("This is translatable", { context: "example" });
|
|
19
|
+
* ```
|
|
20
|
+
* - **Template Literals**:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* t(`This is a template literal`);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
class TypeScriptDetector extends BaseDetector_js_1.BaseDetector {
|
|
28
|
+
// #region Fields
|
|
29
|
+
_marker;
|
|
30
|
+
// #endregion
|
|
31
|
+
// #region Constructor
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new instance of the `TypeScriptDetector` class.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @param logger - The logger instance.
|
|
37
|
+
* @param options - Configuration options for the detector.
|
|
38
|
+
*/
|
|
39
|
+
constructor(logger, options) {
|
|
40
|
+
super(logger, options);
|
|
41
|
+
this._marker = options?.marker ?? /t|translate/;
|
|
42
|
+
}
|
|
43
|
+
// #endregion
|
|
44
|
+
// #region Methods
|
|
45
|
+
/**
|
|
46
|
+
* Provides the regex patterns for extracting strings from TypeScript content.
|
|
47
|
+
*
|
|
48
|
+
* @protected
|
|
49
|
+
* @returns A RegExp for extracting strings.
|
|
50
|
+
*/
|
|
51
|
+
getRegexes() {
|
|
52
|
+
const functionPattern = this._marker instanceof RegExp
|
|
53
|
+
? this._marker.source
|
|
54
|
+
: (0, Utils_js_1.escapeRegExp)(this._marker);
|
|
55
|
+
return [
|
|
56
|
+
new RegExp('(?<!\\w)' + // Ensure the match is not preceded by any word character
|
|
57
|
+
`(?<function>${functionPattern})` + // Match function name (e.g., t or translate)
|
|
58
|
+
'\\(' + // Match opening parenthesis
|
|
59
|
+
'\\s*' + // Optional whitespace
|
|
60
|
+
"(?<quote>['\"`])" + // Match opening quote type
|
|
61
|
+
'(?<value>[^\\1]*?)' + // Match string value (non-greedy)
|
|
62
|
+
'\\k<quote>' + // Match closing quote of the same type
|
|
63
|
+
'\\s*(?:,\\s*.*?)?' + // Allow optional additional arguments
|
|
64
|
+
'\\)', // Match closing parenthesis
|
|
65
|
+
'g')
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Pre-processes content before applying regex matching.
|
|
70
|
+
*
|
|
71
|
+
* @protected
|
|
72
|
+
* @param content - The raw content.
|
|
73
|
+
* @returns The processed content.
|
|
74
|
+
*/
|
|
75
|
+
preProcessContent(content) {
|
|
76
|
+
this.log('Pre-processing TypeScript content.');
|
|
77
|
+
return content.replace(/\r?\n/g, ' '); // Normalize multiline strings
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Post-processes results after regex matching.
|
|
81
|
+
*
|
|
82
|
+
* @protected
|
|
83
|
+
* @param results - The raw results from regex matching.
|
|
84
|
+
* @returns The processed results.
|
|
85
|
+
*/
|
|
86
|
+
postProcessResults(results) {
|
|
87
|
+
this.log(`Post-processing results: ${JSON.stringify(results)}`);
|
|
88
|
+
return results
|
|
89
|
+
.filter((result) => result.match.value !== undefined)
|
|
90
|
+
.map((result) => {
|
|
91
|
+
if (result.match.value !== undefined) {
|
|
92
|
+
result.match.value = result.match.value
|
|
93
|
+
.replace(/\\"/g, '"') // Unescape double quotes
|
|
94
|
+
.replace(/\\'/g, "'") // Unescape single quotes
|
|
95
|
+
.trim(); // Remove extra whitespace
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TypeScriptDetector = TypeScriptDetector;
|
|
102
|
+
//# sourceMappingURL=TypeScriptDetector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptDetector.js","sourceRoot":"","sources":["../../src/Detectors/TypeScriptDetector.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAGlB,iEAAsF;AAEtF,yCAA0C;AA0B1C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,kBAAmB,SAAQ,8BAAY;IAEhD,iBAAiB;IAEA,OAAO,CAAkB;IAE1C,aAAa;IAEb,sBAAsB;IAEtB;;;;;;OAMG;IACH,YAAmB,MAAe,EAAE,OAAoC;QACpE,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAEvB,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,MAAM,IAAI,aAAa,CAAC;IACpD,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;OAKG;IACgB,UAAU;QACzB,MAAM,eAAe,GACjB,IAAI,CAAC,OAAO,YAAY,MAAM;YAC1B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