Crate rust_i18n_autotranslate

Crate rust_i18n_autotranslate 

Source
Expand description

§rust-i18n-autotranslate

The rust-i18n-autotranslate crate provides a simple function to autogenerate locales at runtime or buildtime

This is meant to be a helper crate to rust-i18n

§Features

  • Tracks the source language file and only translates when it has changed.
  • Set cache = true to reuse already translated words.
  • Normalizes languages to a supported language if supported.

The crate supports creating translations only for version_1 type locales eg:

├── Cargo.lock
├── Cargo.toml
├── locales
│   ├── zh-CN.yml
│   ├── en.yml
└── src
│   └── main.rs

§Current support

  • Google Translate (Cloud Translate - Fallback to google translate web)
  • DeepL (Cloud Translate - Fallback to deeplx)
  • DeepLX (Needs installation Install DeepLX)
  • LibreTranslate (Fallback - Install Self Hosted))
  • Yandex (Planned)
  • aws ML (Planned)

§Usage

The crate uses env variables to set the api keys.

Create a .env file in the root of your project and add the following key.

The crate uses env variables to set the api key:

  • GOOGLE_API_KEY = “xyz” How to generate google api key
  • DEEPL_FREE_API_KEY = “xyz”
  • DEEPL_PRO_API_KEY = “xyz”
  • LIBRE_TRANSLATE_API_KEY = “xyz”

§Language codes need to be in ISO-639 format

Call the translate function directly to translate your locales

use rust_i18n_autotranslate::{
   TranslationAPI,
   config::{Config, TranslationProvider},
};

fn main() {
   env_logger::init();

   let cfg = Config::new()
       .locales_directory("./locales")
       .source_lang("en")
       .add_target_lang("fr")
       .use_cache(true)
       .translation_provider(TranslationProvider::GOOGLE)
       .build();

   TranslationAPI::translate(cfg).unwrap()
}

Modules§

config
Config builder

Structs§

TranslationAPI
The translation api