25 lines
960 B
Markdown
25 lines
960 B
Markdown
# Autolingual
|
|
|
|
Procedural macros in Rust can execute arbitrary code at compile time, even performing network requests. This has potentially terrifying security implications, but we'll use it to our advantage!
|
|
|
|
Autolingual is a Rust macro which automatically translates strings of natural language text into multiple foreign languages at once at compile time. The produced translations are `&'static str` values, so they are very lightweight.
|
|
|
|
|
|
## Examples
|
|
|
|
```rs
|
|
use autolingual::{translate, TranslationSet};
|
|
|
|
// No context
|
|
let button_text_french: &str = translate!("Sign up").fr;
|
|
|
|
// With context (context will not show up in the final translation)
|
|
let button_text_french: &str = translate!("Sign up", "A button for creating a user account.").fr;
|
|
|
|
// Every supported language at once.
|
|
let translation_set: TranslationSet = translate!("Hello!");
|
|
let french = translation_set.fr;
|
|
let german = translation_set.de;
|
|
let portuguese = translation_set.pt;
|
|
// ...
|
|
```
|