auto-i18n-plugin-core 0.0.14

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.
@@ -0,0 +1,324 @@
1
+ import { Node } from '@babel/types';
2
+ import tunnel from 'tunnel';
3
+ import { AxiosProxyConfig } from 'axios';
4
+
5
+ declare enum OriginLangKeyEnum {
6
+ ZH = "zh-cn",
7
+ EN = "en"
8
+ }
9
+
10
+ interface TranslatorOption {
11
+ /** 实际的请求方法 */
12
+ fetchMethod: (text: string, fromKey: string, toKey: string) => Promise<string>;
13
+ name?: string;
14
+ /** 执行间隔(默认不开启) */
15
+ interval?: number;
16
+ }
17
+ declare class Translator {
18
+ protected option: TranslatorOption;
19
+ constructor(option: TranslatorOption);
20
+ protected getErrorMessage(error: unknown): string;
21
+ translate(text: string, fromKey: string, toKey: string): Promise<string>;
22
+ }
23
+
24
+ interface GoogleTranslatorOption {
25
+ proxyOption: tunnel.ProxyOptions;
26
+ }
27
+ declare class GoogleTranslator extends Translator {
28
+ constructor(option: GoogleTranslatorOption);
29
+ }
30
+
31
+ interface YoudaoTranslatorOption {
32
+ appId: string;
33
+ appKey: string;
34
+ proxy?: AxiosProxyConfig;
35
+ /** 翻译api执行间隔,默认为1000 */
36
+ interval?: number;
37
+ }
38
+ declare class YoudaoTranslator extends Translator {
39
+ /** 有道的语言类型映射不标准,需要手动控制 */
40
+ private readonly YOUDAO_TRANSLATE_KEY_CONVERT_MAP;
41
+ private truncate;
42
+ private getTranslateKey;
43
+ constructor(option: YoudaoTranslatorOption);
44
+ }
45
+
46
+ type index$1_GoogleTranslator = GoogleTranslator;
47
+ declare const index$1_GoogleTranslator: typeof GoogleTranslator;
48
+ type index$1_GoogleTranslatorOption = GoogleTranslatorOption;
49
+ type index$1_Translator = Translator;
50
+ declare const index$1_Translator: typeof Translator;
51
+ type index$1_TranslatorOption = TranslatorOption;
52
+ type index$1_YoudaoTranslator = YoudaoTranslator;
53
+ declare const index$1_YoudaoTranslator: typeof YoudaoTranslator;
54
+ type index$1_YoudaoTranslatorOption = YoudaoTranslatorOption;
55
+ declare namespace index$1 {
56
+ export { index$1_GoogleTranslator as GoogleTranslator, type index$1_GoogleTranslatorOption as GoogleTranslatorOption, index$1_Translator as Translator, type index$1_TranslatorOption as TranslatorOption, index$1_YoudaoTranslator as YoudaoTranslator, type index$1_YoudaoTranslatorOption as YoudaoTranslatorOption };
57
+ }
58
+
59
+ /**
60
+ * 默认插件配置选项
61
+ */
62
+ declare const DEFAULT_OPTION: {
63
+ /** 翻译调用函数,默认为 $t */
64
+ translateKey: string;
65
+ /** 标记不翻译调用函数列表,避免某些调用被错误翻译 */
66
+ excludedCall: string[];
67
+ /** 标记不用翻译的字符串模式数组,默认是匹配文件扩展名 */
68
+ excludedPattern: RegExp[];
69
+ /** 排查不需要翻译的目录下的文件路径(白名单) */
70
+ excludedPath: string[];
71
+ /** 指定需要翻译文件的目录路径正则(黑名单) */
72
+ includePath: RegExp[];
73
+ /** 配置文件生成位置,默认为 './lang' */
74
+ globalPath: string;
75
+ /** 打包后生成文件的位置,例如 './dist/assets' */
76
+ distPath: string;
77
+ /** 打包后生成文件的主文件名称,默认是 'index' */
78
+ distKey: string;
79
+ /** 来源语言,默认是中文 */
80
+ originLang: OriginLangKeyEnum | string;
81
+ /** 翻译目标语言列表,默认包含英文 */
82
+ targetLangList: string[];
83
+ /** 语言key,用于请求谷歌api和生成配置文件下对应语言的内容文件 */
84
+ langKey: string[];
85
+ /** 命名空间,防止全局命名冲突 */
86
+ namespace: string;
87
+ /** 是否在构建结束之后将最新的翻译重新打包到主包中,默认不打包 */
88
+ buildToDist: boolean;
89
+ /** 默认使用 Google 翻译器 */
90
+ translator: Translator;
91
+ /** 翻译器配置选项,优先级低于translator */
92
+ translatorOption: TranslatorOption | undefined;
93
+ };
94
+ /**
95
+ * 类型定义:插件配置选项类型
96
+ */
97
+ type OptionType = typeof DEFAULT_OPTION;
98
+ /**
99
+ * 全局插件配置实例,复制自默认配置
100
+ */
101
+ declare let option: OptionType;
102
+ /**
103
+ * 类型定义:用户传入的配置选项
104
+ */
105
+ type OptionInfo = {
106
+ option: Partial<OptionType>;
107
+ };
108
+ /**
109
+ * 初始化插件配置选项
110
+ * @param optionInfo 用户提供的配置选项
111
+ */
112
+ declare function initOption(optionInfo: OptionInfo): void;
113
+ /**
114
+ * 校验插件配置选项是否完整有效
115
+ * @returns {boolean} 校验结果,完整返回 true,否则返回 false
116
+ */
117
+ declare function checkOption(): boolean;
118
+
119
+ /**
120
+ * @description: 是否包含来源语言字符
121
+ * @param {string} code
122
+ * @return {*}
123
+ */
124
+ declare function hasOriginSymbols(code: string): boolean;
125
+ /**
126
+ * @description: 过滤注释
127
+ * @param {string} code
128
+ * @return {*}
129
+ */
130
+ declare const removeComments: (code: string) => string;
131
+ /**
132
+ * @description: 用于判断提供的值是否符合正则表达式数组中的任一规则,符合则跳过
133
+ * @param {*} value
134
+ * @param {*} regexArray
135
+ * @return {*}
136
+ */
137
+ declare function checkAgainstRegexArray(value: string, regexArray: string[] | RegExp[]): boolean;
138
+ /**
139
+ * @description: 用于解析抽象语法树中的调用表达式,并提取出调用的名称,如a.b.c() 取 c。
140
+ * @param {any} node
141
+ * @return {*}
142
+ */
143
+ declare function extractFunctionName(node: Node): string;
144
+ /**
145
+ * @description: 提取文件的中文部分
146
+ * @param {string} fileContent
147
+ * @return {*}
148
+ */
149
+ declare const extractCnStrings: (fileContent: string) => string[];
150
+ /**
151
+ * @description: 提取文件指定部分内容
152
+ * @param {string} fileContent
153
+ * @param {any} regex
154
+ * @return {*}
155
+ */
156
+ declare function extractStrings(fileContent: string, regex: any): string[];
157
+ /**
158
+ * @description: 生成i8n翻译函数
159
+ * @param {string} value
160
+ * @param {boolean} isExpression
161
+ * @param {string} key
162
+ * @return {*}
163
+ */
164
+ declare function createI18nTranslator(value: string, isExpression?: boolean, key?: string): any;
165
+ /**
166
+ * @description: 生成唯一id
167
+ * @param {string} key
168
+ * @return {*}
169
+ */
170
+ declare function generateId(key: string): string;
171
+ /**
172
+ * @description: unicode转中文
173
+ * @param {string} str
174
+ * @return {*}
175
+ */
176
+ declare const unicodeToChinese: (str: string) => string;
177
+ /**
178
+ * @description: 有道翻译 标识截取
179
+ * @param {string} q
180
+ * @return {*}
181
+ */
182
+ declare function truncate(q: string): string;
183
+
184
+ declare const base_checkAgainstRegexArray: typeof checkAgainstRegexArray;
185
+ declare const base_createI18nTranslator: typeof createI18nTranslator;
186
+ declare const base_extractCnStrings: typeof extractCnStrings;
187
+ declare const base_extractFunctionName: typeof extractFunctionName;
188
+ declare const base_extractStrings: typeof extractStrings;
189
+ declare const base_generateId: typeof generateId;
190
+ declare const base_hasOriginSymbols: typeof hasOriginSymbols;
191
+ declare const base_removeComments: typeof removeComments;
192
+ declare const base_truncate: typeof truncate;
193
+ declare const base_unicodeToChinese: typeof unicodeToChinese;
194
+ declare namespace base {
195
+ export { base_checkAgainstRegexArray as checkAgainstRegexArray, base_createI18nTranslator as createI18nTranslator, base_extractCnStrings as extractCnStrings, base_extractFunctionName as extractFunctionName, base_extractStrings as extractStrings, base_generateId as generateId, base_hasOriginSymbols as hasOriginSymbols, base_removeComments as removeComments, base_truncate as truncate, base_unicodeToChinese as unicodeToChinese };
196
+ }
197
+
198
+ /**
199
+ * @description: 新建国际化配置文件夹
200
+ * @return {*}
201
+ */
202
+ declare function initLangFile(): void;
203
+ /**
204
+ * @description: 生成国际化基础调用函数文件
205
+ * @return {*}
206
+ */
207
+ declare function initTranslateBasicFnFile(): void;
208
+ /**
209
+ * @description: 生成国际化JSON文件
210
+ * @return {*}
211
+ */
212
+ declare function initLangTranslateJSONFile(): void;
213
+ /**
214
+ * @description: 读取国际化JSON文件
215
+ * @return {*}
216
+ */
217
+ declare function getLangTranslateJSONFile(): string;
218
+ /**
219
+ * @description: 基于langKey获取JSON配置文件中对应语言对象
220
+ * @param {string} key
221
+ * @return {*}
222
+ */
223
+ declare function getLangObjByJSONFileWithLangKey(key: string, insertJSONObj?: object | undefined): any;
224
+ /**
225
+ * @description: 设置国际化JSON文件
226
+ * @return {*}
227
+ */
228
+ declare function setLangTranslateJSONFile(obj: object): void;
229
+ /**
230
+ * @description: 构建时把lang配置文件设置到打包后到主文件中
231
+ * @return {*}
232
+ */
233
+ declare function buildSetLangConfigToIndexFile(): void;
234
+
235
+ declare const file_buildSetLangConfigToIndexFile: typeof buildSetLangConfigToIndexFile;
236
+ declare const file_getLangObjByJSONFileWithLangKey: typeof getLangObjByJSONFileWithLangKey;
237
+ declare const file_getLangTranslateJSONFile: typeof getLangTranslateJSONFile;
238
+ declare const file_initLangFile: typeof initLangFile;
239
+ declare const file_initLangTranslateJSONFile: typeof initLangTranslateJSONFile;
240
+ declare const file_initTranslateBasicFnFile: typeof initTranslateBasicFnFile;
241
+ declare const file_setLangTranslateJSONFile: typeof setLangTranslateJSONFile;
242
+ declare namespace file {
243
+ export { file_buildSetLangConfigToIndexFile as buildSetLangConfigToIndexFile, file_getLangObjByJSONFileWithLangKey as getLangObjByJSONFileWithLangKey, file_getLangTranslateJSONFile as getLangTranslateJSONFile, file_initLangFile as initLangFile, file_initLangTranslateJSONFile as initLangTranslateJSONFile, file_initTranslateBasicFnFile as initTranslateBasicFnFile, file_setLangTranslateJSONFile as setLangTranslateJSONFile };
244
+ }
245
+
246
+ type langObj = {
247
+ [key: string]: string;
248
+ };
249
+ declare let langObj: langObj;
250
+ /**
251
+ * @description: 设置翻译对象属性
252
+ * @param {string} key
253
+ * @param {string} value
254
+ * @return {*}
255
+ */
256
+ declare function setLangObj(key: string, value: string): void;
257
+ /**
258
+ * @description: 读取翻译对象
259
+ * @return {*}
260
+ */
261
+ declare function getLangObj(): langObj;
262
+ /**
263
+ * @description: 初始化翻译对象
264
+ * @param {langObj} obj
265
+ * @return {*}
266
+ */
267
+ declare function initLangObj(obj: langObj): void;
268
+ /**
269
+ * @description: 生成国际化配置文件
270
+ * @return {*}
271
+ */
272
+ declare function autoTranslate(): Promise<void>;
273
+ /**
274
+ * @description: 新增语言类型配置补全
275
+ * @param {any} obj
276
+ * @return {*}
277
+ */
278
+ declare function languageConfigCompletion(obj: any): void;
279
+ /**
280
+ * @description: 补全新增语言翻译写入函数
281
+ * @param {any} langObj
282
+ * @param {any} curLangObj
283
+ * @param {string} translateKey
284
+ * @return {*}
285
+ */
286
+ declare function completionTranslateAndWriteConfigFile(langObj: any, curLangObj: any, translateKey: string): Promise<void>;
287
+
288
+ declare const translate_autoTranslate: typeof autoTranslate;
289
+ declare const translate_completionTranslateAndWriteConfigFile: typeof completionTranslateAndWriteConfigFile;
290
+ declare const translate_getLangObj: typeof getLangObj;
291
+ declare const translate_initLangObj: typeof initLangObj;
292
+ declare const translate_langObj: typeof langObj;
293
+ declare const translate_languageConfigCompletion: typeof languageConfigCompletion;
294
+ declare const translate_setLangObj: typeof setLangObj;
295
+ declare namespace translate {
296
+ export { translate_autoTranslate as autoTranslate, translate_completionTranslateAndWriteConfigFile as completionTranslateAndWriteConfigFile, translate_getLangObj as getLangObj, translate_initLangObj as initLangObj, translate_langObj as langObj, translate_languageConfigCompletion as languageConfigCompletion, translate_setLangObj as setLangObj };
297
+ }
298
+
299
+ declare class FunctionFactoryOption {
300
+ static originLang: string;
301
+ }
302
+
303
+ declare function export_default$4(path: any): void;
304
+
305
+ declare function export_default$3(path: any): void;
306
+
307
+ declare function export_default$2(path: any): void;
308
+
309
+ declare function export_default$1(path: any): void;
310
+
311
+ declare function export_default(): {
312
+ visitor: {
313
+ StringLiteral: typeof export_default$4;
314
+ JSXText: typeof export_default$1;
315
+ TemplateElement: typeof export_default$2;
316
+ CallExpression: typeof export_default$3;
317
+ };
318
+ };
319
+
320
+ declare namespace index {
321
+ export { export_default as default };
322
+ }
323
+
324
+ export { FunctionFactoryOption, GoogleTranslator, type OptionInfo, Translator, type TranslatorOption, YoudaoTranslator, base as baseUtils, checkOption, file as fileUtils, index as filter, initOption, option, translate as translateUtils, index$1 as translator };