laralang 0.1.0

Localized routes for Laravel Rust: one route per language, translated paths, resources and hreflang alternates.
Documentation
use crate::registry::Registry;

/// The URL prefix of each locale, in one place, so route registration, resources and the fallback
/// can never disagree.
///
/// A value in the configuration is the literal prefix. Without one, the locale code is used,
/// except for the default locale, which never carries a prefix.
pub struct LocalePrefixes;

impl LocalePrefixes {
    /// The URL prefix of a locale, without slashes. An empty string counts as no value: only the
    /// default locale can live at the root.
    ///
    /// # Panics
    ///
    /// Panics outside the application.
    pub fn get(locale: &str) -> String {
        Registry::current().settings().prefix(locale)
    }

    /// The URL prefix of every configured locale, in order.
    ///
    /// # Panics
    ///
    /// Panics outside the application.
    pub fn all() -> Vec<(String, String)> {
        Registry::current().settings().prefixes()
    }

    /// How long a permanent redirect may be cached, in seconds.
    ///
    /// The redirects are computed from the prefixes and the locale order, so a change to either
    /// leaves the ones already cached pointing at URLs that no longer exist, and a permanent redirect
    /// cannot be revoked. An explicit lifetime bounds that.
    ///
    /// # Panics
    ///
    /// Panics outside the application.
    pub fn redirect_max_age() -> u64 {
        Registry::current().settings().redirect_max_age
    }
}