Files
website/node_modules/@astrojs/starlight/integrations/shared/localeToLang.ts
2024-05-06 17:15:30 -04:00

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';
}