i18n-pro
Version:
An out-of-the-box, lightweight JavaScript i18n auto-translation solution
218 lines (217 loc) • 5.88 kB
TypeScript
/**
* 公共的翻译配置类型,适用于所有的翻译平台
*/
export declare type TranslatorConfig = {
from: string;
to: string[];
codeLocaleMap?: Record<string, string>;
delay?: number;
};
/**
* 可供选择的翻译器(翻译平台)
*/
export declare type Translator = 'baidu' | 'youdao' | 'tencent' | 'aliyun' | 'microsoft' | 'google' | 'googlex' | 'openai';
/**
* 公共的基础配置
*/
declare type BasicConfig = {
funcName: string;
entry?: string;
fileRegExp?: RegExp;
/** 通过 Glob 语法来过滤文件 */
input?: string | string[];
/**
* 语言包文件输出配置
*/
output: {
path: string;
/**
* 输出语言包的方式
*
* 假设有两个翻译的目标语言,分别为 en 和 jp
*
* single 只会生成一个聚合的语言包文件
* 对应一个文件:langs.json, 格式如下:
* {
* "en":{
* "xxx":"xxx"
* },
* "jp":{
* "xxx":"xxx"
* }
* }
*
* multiple 每个语言都会生成对应的语言包文件
* 对应两个文件:en.json, jp.json
* en.json 格式如下,jp.json 也是如此
* {
* "xxx":"xxx"
* }
*/
langType?: 'single' | 'multiple';
indentSize?: number;
};
/**
* 指定翻译平台,默认为【百度】
*/
translator?: Translator;
/**
* 允许其他任意属性
*/
[key: string]: unknown;
};
declare type DefineTranslatorConfig<T extends Translator, C extends object> = {
translator: T;
} & Record<`${T}Config`, C>;
/**
* 基础百度翻译的配置
*/
export declare type BasicBaiduConfig = {
appid: string;
key: string;
} & TranslatorConfig;
/**
* 完整的百度翻译的配置
*/
export declare type BaiduConfig = DefineTranslatorConfig<'baidu', BasicBaiduConfig>;
/**
* 有道翻译的配置
*/
export declare type BasicYoudaoConfig = {
appKey: string;
key: string;
} & TranslatorConfig;
/**
* 完整的有道翻译的配置
*/
export declare type YoudaoConfig = DefineTranslatorConfig<'youdao', BasicYoudaoConfig>;
/**
* 腾讯翻译的配置
*/
export declare type BasicTencentConfig = {
secretId: string;
secretKey: string;
region: string;
projectId?: string;
language?: string;
} & TranslatorConfig;
/**
* 完整的腾讯翻译的配置
*/
export declare type TencentConfig = DefineTranslatorConfig<'tencent', BasicTencentConfig>;
/**
* 阿里云翻译的配置
*/
export declare type BasicAliyunConfig = {
accessKeyId: string;
accessKeySecret: string;
scene?: string;
apiType?: string;
endpoint?: string;
} & TranslatorConfig;
/**
* 完整的阿里云翻译的配置
*/
export declare type AliyunConfig = DefineTranslatorConfig<'aliyun', BasicAliyunConfig>;
/**
* 微软翻译的配置
*/
export declare type BasicMicrosoftConfig = {
key: string;
location: string;
} & TranslatorConfig;
/**
* 完整的微软翻译的配置
*/
export declare type MicrosoftConfig = DefineTranslatorConfig<'microsoft', BasicMicrosoftConfig>;
/**
* 谷歌翻译的配置
*/
export declare type BasicGoogleConfig = {
projectId: string;
location?: string;
} & TranslatorConfig;
/**
* 完整的谷歌翻译的配置
*/
export declare type GoogleConfig = DefineTranslatorConfig<'google', BasicGoogleConfig>;
/**
* 谷歌翻译X的配置
*/
export declare type BasicGooglexConfig = {
proxy?: string;
} & TranslatorConfig;
/**
* 完整的谷歌X翻译的配置
*/
export declare type GooglexConfig = Omit<DefineTranslatorConfig<'googlex', BasicGooglexConfig>, 'translator'> & {
translator?: 'googlex';
};
/**
* OpenAI翻译的配置
*/
export declare type BasicOpenAIConfig = {
key: string;
model?: string;
proxy?: string;
} & TranslatorConfig;
/**
* 完整的OpenAI翻译的配置
*/
export declare type OpenAIConfig = DefineTranslatorConfig<'openai', BasicOpenAIConfig>;
/**
* 翻译器基础的联合类型
*/
export declare type UnionBasicTranslatorConfig = BasicBaiduConfig | BasicYoudaoConfig | BasicTencentConfig | BasicAliyunConfig | BasicMicrosoftConfig | BasicGoogleConfig | BasicGooglexConfig | BasicOpenAIConfig;
/**
* 翻译器的联合类型
*/
export declare type UnionTranslatorConfig = BaiduConfig | YoudaoConfig | TencentConfig | AliyunConfig | MicrosoftConfig | GoogleConfig | GooglexConfig | OpenAIConfig;
/**
* 模板配置文件
*/
export declare type Config = BasicConfig & UnionTranslatorConfig;
/**
* 单个语言包
*/
export declare type LangPack = Record<string, string>;
/**
* 语言包类型
*/
export declare type Langs = Record<string, LangPack>;
/**
* 最大字符数限制类型
*/
export declare type MaxLengthType = 'allStrLength' | 'strLengthAndArrLength' | 'allStrLengthAndArrLength' | 'allTokenLength';
/**
* 最大字符限制配置
*/
export declare type MaxLengthConfig = {
/**
* 限制类型
*/
maxLengthType: MaxLengthType;
/**
* 最大字符数,根据【限制类型】不同,用途不同
*/
maxLength: number;
/**
* 数组最大长度
*/
maxArrayLength?: number;
/**
* 以字符串形式传递时,不同文本间的分割符
*/
separator?: string;
};
/**
* 不同平台的最大字符限制配置
*/
export declare type MaxLengthConfigMap = Record<Config['translator'], MaxLengthConfig>;
/**
* 内部配置属性
*/
export declare type InnerConfig = {
maxLengthConfig: MaxLengthConfig;
};
export {};