Lang Provider
Context provider for language and internationalization. Install Lang Provider from the VLLNT UI registry with the shadcn CLI.
Context provider for language and internationalization. Part of the utility family in VLLNT UI, it ships as a machine-readable registry entry — copy the source directly into your app with the shadcn CLI and own it, no runtime dependency on a component library.
Preview
Switch between light and dark to inspect the embedded Storybook preview.
Installation
Add Lang Provider to your project with the shadcn CLI. The source lands in your codebase, ready to adapt:
pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/lang-provider.jsonSource
"use client";
import { useEffect } from "react";
import { usePathname } from "next/navigation";
import type { SupportedLanguage } from "../../lib/types";
type LangProviderProps = {
defaultLanguage?: SupportedLanguage;
supportedLanguages?: SupportedLanguage[];
};
export function LangProvider({
defaultLanguage = "en",
supportedLanguages = ["en", "fr"],
}: LangProviderProps) {
const pathname = usePathname();
// Derive the language during render from the pathname.
// Matches /en, /fr, /en/, /fr/, etc.
const langMatch = /^\/([a-z]{2})(?:\/|$)/.exec(pathname);
const lang =
langMatch && supportedLanguages.includes(langMatch[1] as SupportedLanguage)
? (langMatch[1] as SupportedLanguage)
: defaultLanguage;
useEffect(() => {
// Sync the derived language to the document's lang attribute.
document.documentElement.setAttribute("lang", lang);
}, [lang]);
return null;
}
Stories
Explore every variant and state in the interactive Storybook:
Preview
Switch between light and dark to inspect the embedded Storybook preview.