๐ค ATi18n - An Autonomous Translator Agent for projects with i18n module ๐
โญ Description
ATi18n is an autonomous translator agent designed for projects that utilize the i18n (internationalization) module. Its primary function is to search for combinations of key
, key/namespace
, and key/default_text/namespace
, and then translate the extracted default_text
or the value corresponding to the key from the project's default language source translation file using the selected translation service. ATi18n has various parameters and is able to process the entire project to extract the raw texts and modify the source files to make it compatible with the i18n module. In addition, it is also able to recognize the project and make suggestions and guide the user through the integration process if the i18n module is missing. It is also able to create a new or modify and configure properly the essential (next)-i18n(ext).config.js file based on the project's directory structure.
๐ฅ ATi18n Translated Projects
One of the most amazing open-source autonomous task creator and executor AI Agent
An other amazing open-source autonomous AI Agent which can write from the right to the left
โจ Features
ATi18n has the ability to collect raw texts from the source files's code.
Extracts the following functions:
i18n?.t
t
translate
Accepts the '
and "
in the functions for the key
, default_text
, namespace
values.
Extracts translations by the following syntaxes:
translate|t|i18n?.t("{key}")
translate|t|i18n?.t("{key}", "{namespace}")
translate|t|i18n?.t("{key}", { ns: {"{namespace}" })
translate|t|i18n?.t("{key}", "{default_text"}, "{namespace}")
Important note: for the translate|t|i18n?.t("{key}")
syntax it's important to set the corresponding ENV variable to the default namespace (default: "common")
Option: if the SHORTEN_AND_REWRITE
ENV variable is true
then it will remove the "default_text" parameter and change the file's soruce code at the matched part to translate|t|i18n?.t("{key}", "{namespace}")
syntax
If the key or the value isn't found in the /{locales_dir}/{default_language}/{namespace}.json
source translation file then the script will create the "{key}": "MISSING_TRANSLATION"
key/value pair and writes it into the /{locales_dir}/translation/{namespace}.json
file.
๐ป AI driven interactive terminal
terminal.mp4
Regular Expressions
Translation collecting
translate|t|i18n?.t("DEFAULT_TEXT")
translate|t|i18n?.t("KEY", {ns: "NAMESPCE"})
translate|t|i18n?.t("KEY", "DEFAUL_TEXT", "NAMESPACE")
Text extraction
๐ Bugs and other issues
But hey, let's keep it real! ATi18n isn't perfect just yet.
In addition, I'm always open for the suggestions and feedback from the community.
๐ Roadmap
โ Interactive terminalโป Standalone npm installable moduleโ Supports Flat Translation JSON filesโ Supports Nested translation JSON filesโ OpenAI Chat & Text Completion as translator serviceโ Google Translate API-less solutionโ Ability to translate the missing key/value combination from the terminalโ AI guess the translation from the key if the source translation or the default text is missingโ AI suggests the KEY and NAMESPACE if only the default text existsโป AI driven folder managementโ Auto-detection of the project's allowed localesโ Translate automatically the entire project from the selected source language using the detected allowed languagesโ Supports .ts, .tsx, .js, .jsx, .cjs, .mjs filesโ Prompt for language/languages array creation ([{language_code, label, flag_icon}])โป Parameterizable npm run scriptsโป Self-integration into the project's package.jsonโป Autosearch for hard-coded parts which should be translatableโป Self-integration to files, where found hard-coded parts, but the import of the translation module is missing
๐ Services as translators
- Google Translate - doesn't need API key
- OpenAI
- Text completion
- Chat completion
๐งฎ Requirements
- source translation file - otherwise it will create only
"{key}": NO_TRANSLATION_FOUND
if there is no OpenAI API key set and theTRY_TO_GUESS_POSSIBLE_TRANSLATION_BY_KEY
ENV variable isfalse
- OpenAI API key if you want to use it as the translator service
(Note: if you have the translate|t|i18n?.t("{key}", "{default_text"}, "{namespace}")
syntax in your code then it will process the extracted default_text
as translatable value and creates the corresponding {namespace}.json
file(s))
โ How to configure โ๏ธ and run ๐
- Clone the repository using the
git clone https://github.com/Cs4K1Sr4C/AutoTranslator-i18n
or download and unzip the following archive: AutoTranslator-i18n - Rename the
.env.example
file to.env
or add its content to your.env
file (Note: be sure to set the proper values which fit your project) - Copy the
.env
andtranslator.cjs
files to the directory where yourpackage.json
is located - Add the
translate: node ./translator.cjs
to your scripts in thepackage.json
- Use one of the following npm run command:
npm run translate
npm run translate --srcLang="<enter your source language here>" --targetLang="<enter your target language here>"
npm run translate --allAvailableLanguages --suggestKeyNamespace --onlyDefaultText --changeToGoogleAfterSuggestion
npm run translate --onlyExtractKeys
๐น Video
ATi18n_converted_3.mp4
(In the video I used an other amazing open-source project, Guild.XYZ, for demonstrating and testing
๐ Contribution
- Enhance your coding skills...
- Collaborate with passionate developers worldwide...
- Build a solid portfolio...
- Contribute the project if aligns with your interests...
- Make a positive impact...
- Fork the repository and create your branch.
- Implement your changes, ensuring code quality and adherence to guidelines.
- Test thoroughly to maintain a stable codebase.
- Submit a pull request with a clear description of your changes.
- Engage in constructive discussions with fellow contributors.
- Iterate and improve based on valuable feedback.
Everyone is welcome to contribute!
- Visit the open issues.
- Choose one that interests you or propose new ideas.
Your contributions, big or small, are highly valued and appreciated!