/ATi18n

🤖 AI driven interactive and autonomous i18n extractor and translator for projects with i18n internationalization modules 🌍

Primary LanguageTypeScript

🤖 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

AgentGPT

An other amazing open-source autonomous AI Agent which can write from the right to the left

BabyAGI-UI

✨ 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")

image

translate|t|i18n?.t("KEY", {ns: "NAMESPCE"})

image

translate|t|i18n?.t("KEY", "DEFAUL_TEXT", "NAMESPACE")

image

Text extraction

image

image

🐛 Bugs and other issues

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! 🌟🌈

🚗 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

  1. Google Translate - doesn't need API key
  2. 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 the TRY_TO_GUESS_POSSIBLE_TRANSLATION_BY_KEY ENV variable is false
  • 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 🏃

  1. Clone the repository using the git clone https://github.com/Cs4K1Sr4C/AutoTranslator-i18n or download and unzip the following archive: AutoTranslator-i18n
  2. 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)
  3. Copy the .env and translator.cjs files to the directory where your package.json is located
  4. Add the translate: node ./translator.cjs to your scripts in the package.json
  5. 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 🤖ATi18n's automatized translation power... 🦾

🌟 Contribution

🤝 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

  1. Visit the open issues.
  2. Choose one that interests you or propose new ideas.

Your contributions, big or small, are highly valued and appreciated! 🤝