Expand description
The current locale for Laravel Rust, with the API of laravel::lang.
Laravel Rust 0.1 has no localization. Its prototype (draft PR #309) adds laravel::lang with
locale, set_locale, locales and negotiate, and request.preferred_locale(). This crate
has the same names and behaviour today, so moving to the framework’s own is changing the use.
ⓘ
use laralocale::PreferredLocale;
laralocale::set_locale(request.preferred_locale()); // for the rest of the request
laralocale::locale(); // "es"
laralocale::locales(); // ["en", "ca", "es"]
laralocale::negotiate(&["es-mx".to_owned()]); // "es"
laralocale::with_locale("ca", async { send_the_newsletter().await }).await;The locale lives in a task-local, so every request has its own and requests never see each
other’s. Packages that translate, such as Laratext, Laralang and Larablog, read it with
locale() and need nothing else from this crate.
It targets Laravel Rust 0.1 (beta), whose API it follows until 1.0.
Re-exports§
pub use config::DetectSettings;pub use config::DetectSource;pub use config::LocaleConfig;pub use detect::DetectLocale;pub use locale::candidates;pub use locale::fallback_locale;pub use locale::locale;pub use locale::locales;pub use locale::negotiate;pub use locale::set_locale;pub use locale::with_locale;pub use preferred::PreferredLocale;pub use provider::LaralocaleServiceProvider;pub use scope::LocaleScope;