l10n: adjust the documentation

This commit is contained in:
Sylvestre Ledru 2025-07-27 10:59:30 +09:00
parent 862a7a705c
commit d045f50622

View file

@ -66,30 +66,29 @@ You can override the locale at runtime by running:
## 📥 Retrieving Messages
Two APIs are available:
We have a single macro to handle translations.
It can be used in two ways:
### `get_message(id: &str) -> String`
### `translate!(id: &str) -> String`
Returns the message from the current locale bundle.
```
let msg = get_message("id-greeting");
let msg = translate!("id-greeting");
```
If not found, falls back to `en-US`. If still missing, returns the ID itself.
---
### `get_message_with_args(id: &str, args: HashMap<String, String>) -> String`
### `translate!(id: &str, args: key-value pairs) -> String`
Supports variable interpolation and pluralization.
```
let msg = get_message_with_args(
let msg = translate!(
"error-io",
HashMap::from([
("error".to_string(), std::io::Error::last_os_error().to_string())
])
"error" => std::io::Error::last_os_error()
);
```