laratext 0.1.0

Laratext for Laravel Rust: translation keys with their source text, and auto-translation with OpenAI, Claude, Google Translate or Translatorio.
Documentation
use crate::replace::Replace;
use crate::text::Text;

/// The text of a key in the current locale, with its source text for when there is no translation
/// yet: PHP's `text('key_name', 'default_value')`.
///
/// For a key alone, a replacement or another locale, use the [`text!`](crate::text!) macro, which
/// takes the same arguments as the PHP helper.
///
/// ```
/// assert_eq!(laratext::text("save", "Save changes"), "Save changes");
/// ```
pub fn text(key: &str, default: &str) -> String {
    Text::get(key, Some(default), &Replace::new(), None)
}

/// PHP's `text()` helper, with the arguments it takes: `text!("key")`, `text!("key", "default")`,
/// `text!("key", "default", replace)` and `text!("key", "default", replace, "locale")`.
///
/// ```
/// use laratext::{replace, text};
///
/// // Auto-generated from the key: the last part after a dot, capitalised.
/// assert_eq!(text!("user.first_name"), "First Name");
///
/// assert_eq!(
///     text!("welcome.user", "Welcome, :name!", replace! { name => "John" }),
///     "Welcome, John!"
/// );
/// ```
#[macro_export]
macro_rules! text {
    ($key:expr) => {
        $crate::Text::get(
            $key,
            ::core::option::Option::None,
            &$crate::Replace::new(),
            ::core::option::Option::None,
        )
    };
    ($key:expr, $default:expr) => {
        $crate::Text::get(
            $key,
            ::core::option::Option::Some($default),
            &$crate::Replace::new(),
            ::core::option::Option::None,
        )
    };
    ($key:expr, $default:expr, $replace:expr) => {
        $crate::Text::get(
            $key,
            ::core::option::Option::Some($default),
            &$replace,
            ::core::option::Option::None,
        )
    };
    ($key:expr, $default:expr, $replace:expr, $locale:expr) => {
        $crate::Text::get(
            $key,
            ::core::option::Option::Some($default),
            &$replace,
            ::core::option::Option::Some($locale),
        )
    };
}