mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
l10n: adjust the documentation
This commit is contained in:
parent
862a7a705c
commit
d045f50622
1 changed files with 7 additions and 8 deletions
|
|
@ -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()
|
||||
);
|
||||
```
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue