diff --git a/src/services/LocaleResolver.ts b/src/services/LocaleResolver.ts index ba72767..c5f0356 100644 --- a/src/services/LocaleResolver.ts +++ b/src/services/LocaleResolver.ts @@ -1,30 +1,30 @@ -import { type LocaleName } from '../config'; - -export type AllLocalesInDb = Record>; - -type LocaleKey = string; - -type LocaleKeysLowerCaseMapping = { - [localeName: string]: { - [lowerCasedLocaleKey: string]: LocaleKey; - }; -}; - -export class LocaleResolver { - private readonly localeKeysMapping: LocaleKeysLowerCaseMapping = {}; - - constructor(allLocales: AllLocalesInDb) { - void Object.keys(allLocales).forEach(localeName => { - const localeValues: Record = {}; - this.localeKeysMapping[localeName] = localeValues; - - void Object.keys(allLocales[localeName]).forEach(localeKey => { - localeValues[localeKey.toLowerCase()] = localeKey; - }); - }); - } - - public retrieveKey(exfilName: string, locale: LocaleName): string { - return this.localeKeysMapping?.[locale]?.[exfilName.toLowerCase()] ?? exfilName; - } -} +import { type LocaleName } from '../config'; + +export type AllLocalesInDb = Record>; + +type LocaleKey = string; + +type LocaleKeysLowerCaseMapping = { + [localeName: string]: { + [lowerCasedLocaleKey: string]: LocaleKey; + }; +}; + +export class LocaleResolver { + private readonly localeKeysMapping: LocaleKeysLowerCaseMapping = {}; + + constructor(allLocales: AllLocalesInDb) { + void Object.keys(allLocales).forEach(localeName => { + const localeValues: Record = {}; + this.localeKeysMapping[localeName] = localeValues; + + void Object.keys(allLocales[localeName]).forEach(localeKey => { + localeValues[localeKey.toLowerCase()] = localeKey; + }); + }); + } + + public retrieveKey(exfilName: string, locale: LocaleName): string { + return this.localeKeysMapping?.[locale]?.[exfilName.toLowerCase()] ?? exfilName; + } +}