mirror of
https://github.com/sern-handler/website
synced 2026-06-28 02:32:23 +00:00
12 lines
477 B
TypeScript
12 lines
477 B
TypeScript
import type { StarlightConfig } from '../../types';
|
|
|
|
/**
|
|
* Get the BCP-47 language tag for the given locale.
|
|
* @param locale Locale string or `undefined` for the root locale.
|
|
*/
|
|
export function localeToLang(config: StarlightConfig, locale: string | undefined): string {
|
|
const lang = locale ? config.locales?.[locale]?.lang : config.locales?.root?.lang;
|
|
const defaultLang = config.defaultLocale?.lang || config.defaultLocale?.locale;
|
|
return lang || defaultLang || 'en';
|
|
}
|