mazey
    Preparing search index...

    Function resolveLanguagePreference

    • Resolve the current website language.

      Resolution checks the fixed lang URL query, the supplied local-storage key, navigator.language, and finally the fixed en fallback. Each value is trimmed, treats _ as -, and is canonicalized as a language tag. navigator.languages is intentionally ignored.

      The label is generated at runtime with Intl.DisplayNames in the resolved language when available. Runtime wording may vary; the canonical language value is used as the label when display-name generation is unavailable.

      Usage:

      import {
      resolveLanguagePreference,
      setLanguagePreference,
      } from "mazey";

      const language =
      resolveLanguagePreference(
      "MY_WEBSITE_LANGUAGE"
      );

      console.log(language);

      setLanguagePreference(
      "MY_WEBSITE_LANGUAGE",
      "ja-JP"
      );

      Possible output:

      {
        value: "ja-JP",
        label: "日本語(日本)"
      }
      

      Parameters

      • storageKey: string

        Project-specific local-storage key.

      Returns PreferenceResult<string>

      The canonical current language and a runtime-generated display label.

      If storageKey is not a non-empty string.

      Safe during SSR and resilient to unavailable or throwing browser and Intl APIs. This function reads preferences only and never writes storage, mutates the DOM, loads translations, redirects, or adds listeners.