-
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.
- Loading branch information
Nikolay Poluhin
committed
May 30, 2023
1 parent
f514bad
commit c58aae6
Showing
28 changed files
with
263 additions
and
2 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 |
---|---|---|
|
@@ -6,3 +6,6 @@ node_modules | |
.editorconfig | ||
.npmrc | ||
.idea | ||
.vscode | ||
dist | ||
lib |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
"webpack-cli": "^5.1.1" | ||
}, | ||
"dependencies": { | ||
"i18next": "^22.5.0", | ||
"tsyringe": "^4.7.0" | ||
} | ||
} |
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,9 @@ | ||
import { Lang } from './lang.enum'; | ||
|
||
export type Dictionary = { | ||
[key in Lang]?: { | ||
translation: { | ||
[key: string]: string; | ||
}; | ||
}; | ||
}; |
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,46 @@ | ||
import { Dictionary } from './dictionary.interface'; | ||
import ar from '../../translations/ar.json'; | ||
import bg from '../../translations/bg.json'; | ||
import cs from '../../translations/cs.json'; | ||
import de from '../../translations/de.json'; | ||
import en from '../../translations/en.json'; | ||
import es from '../../translations/es.json'; | ||
import fr from '../../translations/fr.json'; | ||
import he from '../../translations/he.json'; | ||
import it from '../../translations/it.json'; | ||
import ja from '../../translations/ja.json'; | ||
import ko from '../../translations/ko.json'; | ||
import pl from '../../translations/pl.json'; | ||
import pt from '../../translations/pt.json'; | ||
import ro from '../../translations/ro.json'; | ||
import ru from '../../translations/ru.json'; | ||
import th from '../../translations/th.json'; | ||
import tr from '../../translations/tr.json'; | ||
import vi from '../../translations/vi.json'; | ||
import zhHans from '../../translations/zh_HANS.json'; | ||
import zhHant from '../../translations/zh_HANT.json'; | ||
|
||
export const loadDictionaries = (): Dictionary => { | ||
return { | ||
...ar, | ||
...bg, | ||
...cs, | ||
...de, | ||
...en, | ||
...es, | ||
...fr, | ||
...he, | ||
...it, | ||
...ja, | ||
...ko, | ||
...pl, | ||
...pt, | ||
...ro, | ||
...ru, | ||
...th, | ||
...tr, | ||
...vi, | ||
...zhHans, | ||
...zhHant, | ||
}; | ||
}; |
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,23 @@ | ||
export enum Lang { | ||
AR = 'ar', | ||
BG = 'bg', | ||
CS = 'cs', | ||
CN = 'cn', | ||
DE = 'de', | ||
EN = 'en', | ||
ES = 'es', | ||
FR = 'fr', | ||
HE = 'he', | ||
IT = 'it', | ||
JA = 'ja', | ||
KO = 'ko', | ||
PL = 'pl', | ||
PT = 'pt', | ||
RO = 'ro', | ||
RU = 'ru', | ||
TH = 'th', | ||
TR = 'tr', | ||
VI = 'vi', | ||
ZH_HANS = 'zh_HANS', | ||
ZH_HANT = 'zh_HANT', | ||
} |
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,30 @@ | ||
import i18next from 'i18next'; | ||
import { injectable } from 'tsyringe'; | ||
import { loadDictionaries } from './dirctionary-loader.function'; | ||
import { Lang } from './lang.enum'; | ||
|
||
@injectable() | ||
export class Localize { | ||
public async initDictionaries(): Promise<void> { | ||
await i18next.init({ | ||
lng: Lang.EN, | ||
fallbackLng: Lang.EN, | ||
supportedLngs: Object.values(Lang), | ||
debug: false, | ||
resources: loadDictionaries(), | ||
}); | ||
} | ||
|
||
public translate(key: string): string { | ||
return i18next.t(key); | ||
} | ||
|
||
public async changeLang(lang: Lang): Promise<void> { | ||
// fallback for legacy locale | ||
if (lang === Lang.CN) { | ||
lang = Lang.ZH_HANS; | ||
} | ||
|
||
await i18next.changeLanguage(lang); | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"ar": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"bg": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"cs": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"de": { | ||
"translation": {} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"en": { | ||
"translation": { | ||
"hello": "Hello world!" | ||
} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"es": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"fr": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"he": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"it": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"ja": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"ko": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"pl": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"pt": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"ro": { | ||
"translation": {} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"ru": { | ||
"translation": { | ||
"hello": "Привет мир!" | ||
} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"th": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"tr": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"vi": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"zh_HANS": { | ||
"translation": {} | ||
} | ||
} |
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,5 @@ | ||
{ | ||
"zh_HANT": { | ||
"translation": {} | ||
} | ||
} |