Skip to content

Commit

Permalink
prepare for localization map
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoobes committed Jan 25, 2024
1 parent e83a011 commit 262fa6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/contracts/localizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

export interface Localizer {
translate(text: string, local: string) : string;
// translationsFor(path: string): Record<string, any>
}
6 changes: 5 additions & 1 deletion src/optional/localizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ import assert from 'node:assert';
*/
export class ShrimpleLocalizer implements Localizer, Init {
private __localization!: Localization;
private __localization_map!: Record<string, any>
constructor(){}

translate(text: string, local: string): string {
this.__localization.changeLanguage(local);
return this.__localization.get(text);
}

async init() {
const map = await this.readLocalizationDirectory();
this.__localization = new Localization({
defaultLocale: "en",
fallbackLocale: "en",
locales: await this.readLocalizationDirectory()
locales: map
});
this.__localization_map = map
}

private async readLocalizationDirectory() {
Expand Down

0 comments on commit 262fa6a

Please sign in to comment.