Files
website/node_modules/@astrojs/starlight/utils/i18n.ts
2024-05-06 17:15:30 -04:00

17 lines
494 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Get the string for the passed language from a dictionary object.
*
* TODO: Make this clever. Currently a simple key look-up, but should use
* BCP-47 mapping so that e.g. `en-US` returns `en` strings, and use the
* sites default locale as a last resort.
*
* @example
* pickLang({ en: 'Hello', fr: 'Bonjour' }, 'en'); // => 'Hello'
*/
export function pickLang<T extends Record<string, string>>(
dictionary: T,
lang: keyof T
): string | undefined {
return dictionary[lang];
}