mirror of
https://github.com/sern-handler/website
synced 2026-06-24 00:32:24 +00:00
17 lines
494 B
TypeScript
17 lines
494 B
TypeScript
/**
|
||
* 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
|
||
* site’s 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];
|
||
}
|