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 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.
terminal.mp4
Translation collecting
But hey, let's keep it real! ATi18n isn't perfect just yet. 🙈🔧 It does have a few bugs and areas that need improvement. I'm as the main developer constantly working on making it even better! 💪🛠️ I'm aware that some bugs may creep in, causing unexpected behavior. 🐛 Don't worry, I'm actively addressing these issues and squashing those bugs. 🐜🔨
In addition, I'm always open for the suggestions and feedback from the community. 🤝❤️ Your input can help me enhance ATi18n's features, usability, and overall performance. Let's collaborate with me and others to create something amazing together! 🌟🌈
- ✔ 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
- Google Translate - doesn't need API key
- OpenAI
- Text completion
- Chat completion
- 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))
- 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
ATi18n_converted_3.mp4
(In the video I used an other amazing open-source project, Guild.XYZ, for demonstrating and testing 🤖ATi18n's automatized translation power... 🦾
🤝 Why Contribute?
- 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...
🔧 How to Contribute?
- 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! ❤️
🎉 Start Contributing Now
- Visit the open issues.
- Choose one that interests you or propose new ideas.
Your contributions, big or small, are highly valued and appreciated! 🤝