From d045f50622f22a724ae9d01f56a5be8afa846dda Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 27 Jul 2025 10:59:30 +0900 Subject: [PATCH] l10n: adjust the documentation --- docs/src/l10n.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/docs/src/l10n.md b/docs/src/l10n.md index 7f606a0b1..ec9c1db03 100644 --- a/docs/src/l10n.md +++ b/docs/src/l10n.md @@ -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` +### `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() ); ```