Skip to main content

generate_lang_switcher_html

Function generate_lang_switcher_html 

Source
pub fn generate_lang_switcher_html(
    locales: &[String],
    current_locale: &str,
    current_path: &str,
    base_url: &str,
    strategy: &UrlPrefixStrategy,
) -> String
Expand description

Generates an HTML snippet for a language switcher navigation.

This is a pure function that can be called from any plugin or template helper to produce a <nav> block with links to all locale variants of the current page.

§Arguments

  • locales — All available locales.
  • current_locale — The locale of the page being rendered.
  • current_path — The relative path of the page (e.g. about/index.html).
  • base_url — The site base URL.
  • strategy — How locale URLs are constructed.

§Example

use ssg::i18n::{generate_lang_switcher_html, UrlPrefixStrategy};

let html = generate_lang_switcher_html(
    &["en".into(), "fr".into(), "de".into()],
    "en",
    "about/index.html",
    "https://example.com",
    &UrlPrefixStrategy::SubPath,
);
assert!(html.contains("lang=\"fr\""));