-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduction of I18n and fixes (#49)
* introduction of I18n and fixes * fix * fix in useCampaign campaign name * lint
- Loading branch information
Showing
11 changed files
with
104 additions
and
26 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const en = { | ||
pages: { | ||
opportunities: { | ||
title: "Explore opportunities", | ||
description: "Browse opportunities, compare rewards, and earn tokens", | ||
}, | ||
campaings: { | ||
title: "Explore opportunities", | ||
description: "Browse opportunities, compare rewards, and earn tokens", | ||
}, | ||
}, | ||
}; | ||
|
||
export default en; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import en from "./en"; | ||
|
||
type LanguageFiles = typeof en; | ||
|
||
/** | ||
* I18n class to handle translations | ||
*/ | ||
export class I18n { | ||
public static readonly trad: I18n = new I18n(en); | ||
|
||
private primary: LanguageFiles; | ||
// private secondary: LanguageFiles; | ||
|
||
public get: LanguageFiles; | ||
|
||
constructor(primary: LanguageFiles) { | ||
this.primary = primary; | ||
// this.secondary = secondary; | ||
this.get = this.createProxy(this.primary); | ||
} | ||
|
||
// proxy to handle typing autocompletion | ||
private createProxy<T extends object>(obj: T): T { | ||
return new Proxy(obj, { | ||
get: (target, prop) => { | ||
const value = target[prop as keyof T]; | ||
if (typeof value === "object" && value !== null) { | ||
return this.createProxy(value as object); | ||
} | ||
return value; | ||
}, | ||
}); | ||
} | ||
} |
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
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
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
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
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
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
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
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