Internationalization Processing

Why is Internationalization Needed?

I firmly believe that every thoughtfully written article deserves to be seen by more people and to transcend language barriers, reaching readers all over the world. It is precisely this belief that drives Kecare to thoughtfully provide internationalization support for you, enabling your content to effortlessly reach a global audience.

How to Configure Translation Functionality

1. Enable Translation

Add a field translate in the front-matter of the article that needs translation, and fill in the language code you want to translate into, for example: en-US (English-United States), ja-JP (Japanese-Japan), etc. Please try to adhere to the country language code reference table.

The first field must be the current language field

translate: ['zh-CN','en-US', 'ja-JP']

That's good then

Here are some commonly used language codes:

Language Code
English en-US
Japanese ja-JP
Korean ko-KR
French fr-FR
German de-DE
Russian ru-RU
Portuguese pt-BR

2. Create Configuration File

You only need to create a configuration file kecare.config.ts in the .kecare directory.

3. Configure Translation Parameters

Export the TranslationConfig configuration object in the file, as shown in the following example:

export async function kecareConfig() {
    return {
        llm: {
            model: 'deepseek-chat',
            apiKey: 'sk-',
            apiBaseUrl: 'https://api.deepseek.com/v1',
            prompt: '' //额外的提示词 可选
        }
    };
}

Built-in a system prompt

你是一个很好用的翻译助手,请帮我将下面的文章翻译成英语,
注意:千万不要增删任何 HTML标签/属性和markdown标签/属性,你如果看到markdown标签,
如果是代码块的内容,请不要翻译,只翻译文本节点。
如果是代码内容,请不要翻译,原样放回。保留链接 href、图片 src、id、class 不动。
注意:代码块占位符(如 __CODE_BLOCK_0__)不要翻译,原样保留。

token

We are well aware that the token cost for AI translation can be significant. Therefore, we have specifically designed multiple optimization measures to help you maximize savings on token consumption:

  • Segmented Translation: Intelligently segments the Markdown article and submits each segment to AI for translation.
  • Caching Mechanism: Translation results are automatically cached in the .kecare/.tmp directory.
  • Incremental Updates: During the next build, the system automatically detects which paragraphs have been modified and only retranslates the changed parts.
  • Efficiency Improvement: Not only saves token costs but also significantly improves build efficiency.
文章作者:
文章链接:kecare.me/articles/
版权声明: 博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源