Table of Contents
1. i18nrc.js
Configuration
Basic Configuration
Output
GooglexConfig
OpenAIConfig
GoogleConfig
MicrosoftConfig
BaiduConfig
YoudaoConfig
TencentConfig
AliyunConfig
2. Command
Command List
Command Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
funcName | string | no | t | The function name of the command line matches Translation Text If the t function is not renamed, it does not need to be adjusted here; otherwise, it is configured as the function name after renaming |
entry | string | no | - | Specify the translation file directory (absolute path) |
fileRegExp | RegExp | no | /.[jt]s$/ |
The regular expression that matching filename Used to filter files to be translated |
input | string | string[] | no | - | Files that need translation can be filtered using glob syntaxOnce this property is configured, entry and fileRegExp will no longer apply, so decide which approach makes sense for your use case |
output | Output | yes | - | The configuration associated with the output file |
translator | googlex openai google microsoft aliyun tencent youdao baidu |
no | googlex | Specify the translation platform, default is googlex After specifying translator , you need to cooperate with the corresponding configuration fileFor example, translator configuration to googlex , then you need to configure googlexConfig |
googlexConfig | GooglexConfig | no | - | Translation-related configuration for Google x |
openaiConfig | OpenaiConfig | no | - | Translation-related configuration for OpenAI |
googleConfig | GoogleConfig | no | - | Translation-related configuration for Google |
microsoftConfig | MicrosoftConfig | no | - | Translation-related configuration for Microsoft |
baiduConfig | BaiduConfig | no | - | Translation-related configuration for Baidu |
youdaoConfig | YoudaoConfig | no | - | Translation-related configuration for Youdao |
tencentConfig | TencentConfig | no | - | Translation-related configuration for Tencent |
aliyunConfig | AliyunConfig | no | - | Translation-related configuration for Alibaba Cloud |
Configuration of output files
Name | Type | Required | Default | Description |
---|---|---|---|---|
path | string | yes | - | The directory where the language pack is generated (absolute path) |
langType | 'single' 'multiple' |
no | 'multiple' | Format of output language pack file Assume the target language is ['en', 'jp'] single:Only one aggregated language pack file langs.json will be generated. The format is as follows:{"en":{"xxx":"xxx"},"jp":{"xxx":"xxx"}} multiple:Each target language will generate a corresponding language pack file, which corresponds to two files: en.json , jp.json . The format is as follows:{"xxx":"xxx"} |
indentSize | number | no | 2 | Number of indented spaces in the language pack file |
Google X translation configuration
Realization based on google-translate-api-x , no registration, free use
Name | Type | Required | Default | Description |
---|---|---|---|---|
proxy | string | no | - | Configuration proxy service Some countries and regions cannot access the Google service normally, and need to be configured with agentsFormat: protocol://hostname:port For example: http://127.0.0.1:8087 |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh-CN , English is en )Support language,Need to check the corresponding documentation |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
OPENAI translation configuration
Name | Type | Required | Default | Description |
---|---|---|---|---|
key | string | yes | - | Openai API Key, need Registered account application |
model | string | yes | gpt-3.5-turbo | Specify model version Use the model, the default is gpt-3.5-turbo , currently only compatible Chart model |
proxy | string | no | - | Configuration proxy service Some countries and regions cannot access the OpenAI service normally, and need to be configured with agents格式: protocol://hostname:port 例如: http://127.0.0.1:8087 |
from | string | yes | - | The language of Translation Text (for example, Chinese is Chinese , English is English )Special Instructions:Since OpenAI currently does not launch a pure text translation API, it can only be executed by customized Prompt . The translation language required here must be English |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Google Configuration of Translation
Note: The platform is relatively special, and additional key needs need to be provided in the local environment. For details, please refer to Documentation
Name | Type | Required | Default | Description |
---|---|---|---|---|
projectId | string | yes | - | Project ID, need Registered account application |
location | string | no | - | area |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh-CN , English is en )More languages |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Microsoft Configuration of Translation
Name | Type | Required | Default | Description |
---|---|---|---|---|
key | string | yes | - | Microsoft Translator-Key, you need Register azure account to apply |
location | string | no | - | area |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh-Hans , English is en )More languages |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Configuration of Baidu-Translation
Name | Type | Required | Default | Description |
---|---|---|---|---|
appid | string | yes | - | APPID, Registered account application is required |
key | string | yes | - | Key, as above |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh , English is en )More languages,Search 语种列表 |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Configuration of Youdao Translation
Name | Type | Required | Default | Description |
---|---|---|---|---|
appKey | string | yes | - | Application ID, requiring Registered account application |
key | string | yes | - | Application key, require the same as above |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh-CHS , English is en )More languages,Search 支持语言 |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Configuration of Tencent Translation
Name | Type | Required | Default | Description |
---|---|---|---|---|
secretId | string | yes | - | Used to identify the identity of the API call, you can simple analogy as the user name, you need Registered account to apply |
secretKey | string | yes | - | It is used to verify the identity of the API caller, and the simple analogy can be the password, which requires the same as above |
region | string | yes | - | Regional list Regional list,Search 地域列表 |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh , English is en )More languages,Search 源语言 |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Configuration of Alibaba Cloud Translation
Name | Type | Required | Default | Description |
---|---|---|---|---|
accessKeyId | string | yes | - | AccessKey ID, you need Registered account to apply |
accessKeySecret | string | yes | - | AccessKey Secret, requires the same as above |
scene | string | no | general | Scenes The specific optional value needs to be based on the type of the current API: Ordinary version: Reference Document,Search Scene Professional version: Reference Document,Search Scene |
from | string | yes | - | Translation Text Language code (for example, Chinese is zh , English is en )More languages,Search 语言代码列表 |
to | string[] | yes | - | The target language code for translation, with the same format as above 📢📢📢:If the target language is configured as ['en'] , the generated filename (output.langType=='multiple' ) is en.json . When setting the language, locale must also be 'en' . If locale needs to be set as 'en_US' , it needs to be used in conjunction with codeLocaleMap |
codeLocaleMap | Record<string, string> | no | {} | Set the mapping relationship between language code and locale For example, if the target language is ['en'] and you want to set the value of locale to 'en_US' , you need to configure codeLocaleMap to {"en":"en_US"} , and the final generated filename (output.langType=='multiple' ) will also become en_US.json |
delay | number | no | 0 | The time interval (in seconds) for subsequent interface requests when a single interface is requested in batches It is used to solve the QPS limit of the interface. If there is a related error, you can try to configure the attribute to solve |
Command | Shorthand | Usage | Description |
---|---|---|---|
init | - | npx i18n init |
Initialize the configuration file |
translate | t | npx i18n translate npx i18n t |
Extract Translation Text , automatically translate and generate a language package |
version | v | npx i18n version npx i18n v |
Display version information |
help | h | npx i18n help npx i18n h |
Display help information |
Parameter name | Shorthand | Parameter value | Applicable commands | Usage | Description |
---|---|---|---|---|---|
--locale | -L | en | zh |
ALL | npx i18n h -L en npx i18n h --locale en |
Specify the command line display language The available languages are Chinese (zh)/English (en). The default is English (en) |
--non-incremental | - | - | t translate |
npx i18n t --non-incremental |
Turn off incremental translation mode |
--path | -P | - | init t translate |
npx i18n init -P /xxx/xxx/xxx npx i18n t -P /xxx/xxx/xxx |
Specify the configuration file path (parameter is relative path) You only need to specify the path name. The default configuration filename is i18nrc.js |