Skip to content

A way to automatically detect locales in browser? #28

@patrik-cihal

Description

@patrik-cihal

How could i detect a locale and set it during the first server request?

Would be nice if this was a feature also... This is how I do it now

    let mut il8n = use_init_i18n(|| {
        I18nConfig::new(langid!("cs-CZ"))
            .with_locale((
                langid!("en-US"),
                include_str!("./locales/en-US.ftl")
            ))
            .with_locale((
                langid!("cs-CZ"),
                include_str!("./locales/cs-CZ.ftl")
            ))
    });

    // Use effect to update language after client-side hydration
    use_effect(move || {
        #[cfg(feature = "web")] {
            let browser_locale = get_browser_locale();
            il8n.set_language(browser_locale);
        }
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions