summaryrefslogtreecommitdiff
path: root/src/i18n/translate.ts
blob: b407e3bd80460595599ae8b6d63cf91f9fbc2989 (plain)
1
2
3
4
5
6
7
8
9
import type Locale from '../types/Locale';
import type { TranslationsDictionary } from '../types/TranslationsDictionary';
import { defaultLocale } from './locales';

export default function (locale: Locale) {
  return function <T extends string>(dict: TranslationsDictionary<T>, key: T) {
    return dict[key][locale] ?? dict[key][defaultLocale];
  };
}