laralang 0.1.0

Localized routes for Laravel Rust: one route per language, translated paths, resources and hreflang alternates.
Documentation
//! Localized routes for Laravel Rust: one route per language, translated paths, resources, and the
//! `hreflang` alternates of every page.
//!
//! ```ignore
//! use laralang::{LocalizedRoute, locales};
//!
//! pub fn routes(route: &mut Router) {
//!     LocalizedRoute::get(route, "dashboard", locales!["en", "es" => "panel"], dashboard).name("dashboard");
//! }
//! ```
//!
//! That serves `/dashboard` in English and `/es/panel` in Spanish, and `laralang::route("dashboard", ())`
//! is the URL in the language of the request.
//!
//! The current locale is laralocale's: this crate sets it from the URL prefix and reads it to build
//! URLs, and keeps no locale of its own. Laravel Rust 0.1 has no named routes, so the localized
//! routes are recorded in a [`Registry`] that gives them names.
//!
//! It is the port of the PHP package [`edulazaro/laralang`](https://github.com/edulazaro/laralang) to
//! Laravel Rust 0.1 (beta), and its API follows the framework's changes until 1.0.

pub mod alternates;
pub mod config;
mod current;
pub mod fallback;
pub mod locales;
pub mod middleware;
pub mod params;
mod pattern;
pub mod prefixes;
pub mod provider;
pub mod registry;
pub mod resource;
pub mod route;
pub mod url;
#[cfg(feature = "minijinja")]
mod views;
pub mod ziggy;

pub use alternates::{Alternates, alternates, alternates_head, alternates_with, laralang_alternates};
pub use config::LaralangConfig;
pub use fallback::localized_fallback;
pub use locales::{LocaleDefinition, Locales};
pub use middleware::{SetBrowserLocale, SetRouteLocale, SetSessionLocale, SetSmartLocale};
pub use params::{IntoParams, Params};
pub use prefixes::LocalePrefixes;
pub use provider::LaralangServiceProvider;
pub use registry::{Entry, Registry, Settings};
pub use resource::{LocalizedResource, ResourceHandlers};
pub use route::{LocalizedGroup, LocalizedRoute};
pub use url::{has, route, route_is, route_with};
pub use ziggy::ziggy;

/// Merge the `hreflang` links of the current page into the response's head.
///
/// # Errors
///
/// Fails when [`alternates()`] does.
///
/// # Panics
///
/// Panics when the application is not handling a request.
pub fn merge_alternates() -> laravel::Result<()> {
    laravel::head::merge(alternates_head()?);

    Ok(())
}