diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-11-14 03:22:21 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-11-14 03:22:21 +0100 |
| commit | 04315a5555e8796f4459524421a8daf4f83ddfc1 (patch) | |
| tree | ef2e1308ae969ab6efc1426d35c297749912f0d3 /code/app/src/lib/i18n | |
| parent | 7ccbb71702c26c3a9b79a2915910ad420c8ee012 (diff) | |
| download | greatoffice-04315a5555e8796f4459524421a8daf4f83ddfc1.tar.xz greatoffice-04315a5555e8796f4459524421a8daf4f83ddfc1.zip | |
feat: Updated utils after package update
Diffstat (limited to 'code/app/src/lib/i18n')
| -rw-r--r-- | code/app/src/lib/i18n/i18n-util.async.ts | 4 | ||||
| -rw-r--r-- | code/app/src/lib/i18n/i18n-util.ts | 18 |
2 files changed, 12 insertions, 10 deletions
diff --git a/code/app/src/lib/i18n/i18n-util.async.ts b/code/app/src/lib/i18n/i18n-util.async.ts index 00b8e0a..2e6717e 100644 --- a/code/app/src/lib/i18n/i18n-util.async.ts +++ b/code/app/src/lib/i18n/i18n-util.async.ts @@ -19,10 +19,10 @@ const localeNamespaceLoaders = { } } -const updateDictionary = (locale: Locales, dictionary: Partial<Translations>) => +const updateDictionary = (locale: Locales, dictionary: Partial<Translations>): Translations => loadedLocales[locale] = { ...loadedLocales[locale], ...dictionary } -export const importLocaleAsync = async (locale: Locales) => +export const importLocaleAsync = async (locale: Locales): Promise<Translations> => (await localeTranslationLoaders[locale]()).default as unknown as Translations export const loadLocaleAsync = async (locale: Locales): Promise<void> => { diff --git a/code/app/src/lib/i18n/i18n-util.ts b/code/app/src/lib/i18n/i18n-util.ts index 35f023c..12feb33 100644 --- a/code/app/src/lib/i18n/i18n-util.ts +++ b/code/app/src/lib/i18n/i18n-util.ts @@ -3,6 +3,7 @@ import { i18n as initI18n, i18nObject as initI18nObject, i18nString as initI18nString } from 'typesafe-i18n' import type { LocaleDetector } from 'typesafe-i18n/detectors' +import type { LocaleTranslationFunctions, TranslateByString } from 'typesafe-i18n' import { detectLocale as detectLocaleFn } from 'typesafe-i18n/detectors' import type { Formatters, Locales, Namespaces, Translations, TranslationFunctions } from './i18n-types' @@ -17,23 +18,24 @@ export const namespaces: Namespaces[] = [ 'app' ] -export const isLocale = (locale: string) => locales.includes(locale as Locales) +export const isLocale = (locale: string): locale is Locales => locales.includes(locale as Locales) -export const isNamespace = (namespace: string) => namespaces.includes(namespace as Namespaces) +export const isNamespace = (namespace: string): namespace is Namespaces => namespaces.includes(namespace as Namespaces) -export const loadedLocales = {} as Record<Locales, Translations> +export const loadedLocales: Record<Locales, Translations> = {} as Record<Locales, Translations> -export const loadedFormatters = {} as Record<Locales, Formatters> +export const loadedFormatters: Record<Locales, Formatters> = {} as Record<Locales, Formatters> -export const i18nString = (locale: Locales) => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale]) +export const i18nString = (locale: Locales): TranslateByString => initI18nString<Locales, Formatters>(locale, loadedFormatters[locale]) -export const i18nObject = (locale: Locales) => +export const i18nObject = (locale: Locales): TranslationFunctions => initI18nObject<Locales, Translations, TranslationFunctions, Formatters>( locale, loadedLocales[locale], loadedFormatters[locale] ) -export const i18n = () => initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters) +export const i18n = (): LocaleTranslationFunctions<Locales, Translations, TranslationFunctions> => + initI18n<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters) -export const detectLocale = (...detectors: LocaleDetector[]) => detectLocaleFn<Locales>(baseLocale, locales, ...detectors) +export const detectLocale = (...detectors: LocaleDetector[]): Locales => detectLocaleFn<Locales>(baseLocale, locales, ...detectors) |
