-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Trap
committed
Dec 28, 2024
1 parent
cca46bb
commit 935681f
Showing
1 changed file
with
30 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { type LocaleName } from '../config'; | ||
|
||
export type AllLocalesInDb = Record<string, Record<string, string>>; | ||
|
||
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<string, string> = {}; | ||
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<string, Record<string, string>>; | ||
|
||
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<string, string> = {}; | ||
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; | ||
} | ||
} |