Tool Sharing#
Auto-i18n is a tool that uses ChatGPT to automatically translate Markdown files into multiple languages.
Features#
Auto-i18n achieves complete automation of blog article i18n (Internationalization). By simply pushing the blog post to a GitHub repository, it can be automatically translated into multiple languages using GitHub Actions or by downloading the source code. Currently, it supports English, Spanish, and Arabic. Other languages can be supported by modifying the source code according to the specified format.
⚠️ Note: It is recommended to manually verify the accuracy of the translation before publishing.
⚠️ Another note: If the provided article is incomplete, there may be cases where ChatGPT translates and automatically completes the content. It is unknown whether this is a bug or a feature. (HaHaHa)
Supplement#
If the Markdown contains Front Matter, the original content of the Front Matter will be retained. The translation feature for the parameters in the Front Matter is currently under development.
Here, I have added some Prompts
that can translate the specified parameters in the Front Matter:
Prompts: "Suppose the following text is in JSON format. The value of the key for
{param}
translates into {target_lang}, and other keys remain unchanged. Maintain the original Markdown format.\n\n\n{text}\n\n\nTranslated into {target_lang}:"
The related function is translate_front_matter, which can be referred to in auto-translater.py.
To only translate the content of the parameter "title", while keeping the others in the original language, add front_matter_text = translate_front_matter(front_matter_text, lang, 'title')
in the translate_file
function.
⚠️Of course, handing it directly to ChatGPT for content recognition may result in errors, so manual verification is still required.
Deployment#
- Execution from Source Code
-
First, clone the repository to your local machine.
-
Rename
env_template.py
toenv.py
and fill in the ChatGPT API information. -
Run
pip install openai PyYAML
to install the necessary dependencies. -
Run the
auto-translater
program, which will automatically process all Markdown files in the test directorytestdir/to-translate
and translate them into English, Spanish, and Arabic.
- Execution with GitHub Actions
- You can create
.github/workflows/ci.yml
in your project repository, which will automatically translate the content and commit it back to the original repository when changes are detected in the GitHub repository. - The content of
ci.yml
can be referred to the template: ci_template.yml - Add two secrets,
CHATGPT_API_BASE
andCHATGPT_API_KEY
, in the repository'sSettings
-Secrets and variables
-Repository secrets
, and comment out theimport env
statement in theauto-translater.py
program.
Platform#
Supports all platforms
Github Actions
Disclaimer#
This article is only intended as a tool sharing record.
This article is synchronized with HBlog.