aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/utils/translate.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/ts/utils/translate.ts')
-rw-r--r--packages/website/ts/utils/translate.ts34
1 files changed, 31 insertions, 3 deletions
diff --git a/packages/website/ts/utils/translate.ts b/packages/website/ts/utils/translate.ts
index cddfef088..db8683aa2 100644
--- a/packages/website/ts/utils/translate.ts
+++ b/packages/website/ts/utils/translate.ts
@@ -1,11 +1,21 @@
import * as _ from 'lodash';
+import { chinese } from 'ts/translations/chinese';
import { english } from 'ts/translations/english';
+import { korean } from 'ts/translations/korean';
+import { russian } from 'ts/translations/russian';
+import { spanish } from 'ts/translations/spanish';
import { Deco, Key, Language } from 'ts/types';
const languageToTranslations = {
[Language.English]: english,
+ [Language.Spanish]: spanish,
+ [Language.Chinese]: chinese,
+ [Language.Korean]: korean,
+ [Language.Russian]: russian,
};
+const languagesWithoutCaps = [Language.Chinese, Language.Korean];
+
interface Translation {
[key: string]: string;
}
@@ -13,8 +23,26 @@ interface Translation {
export class Translate {
private _selectedLanguage: Language;
private _translation: Translation;
- constructor() {
- this.setLanguage(Language.English);
+ constructor(desiredLanguage?: Language) {
+ if (!_.isUndefined(desiredLanguage)) {
+ this.setLanguage(desiredLanguage);
+ return;
+ }
+ const browserLanguage = (window.navigator as any).userLanguage || window.navigator.language || 'en-US';
+ let language = Language.English;
+ if (_.includes(browserLanguage, 'es-')) {
+ language = Language.Spanish;
+ } else if (_.includes(browserLanguage, 'zh-')) {
+ language = Language.Chinese;
+ } else if (_.includes(browserLanguage, 'ko-')) {
+ language = Language.Korean;
+ } else if (_.includes(browserLanguage, 'ru-')) {
+ language = Language.Russian;
+ }
+ this.setLanguage(Language.Russian);
+ }
+ public getLanguage() {
+ return this._selectedLanguage;
}
public setLanguage(language: Language) {
const isLanguageSupported = !_.isUndefined(languageToTranslations[language]);
@@ -26,7 +54,7 @@ export class Translate {
}
public get(key: Key, decoration?: Deco) {
let text = this._translation[key];
- if (!_.isUndefined(decoration)) {
+ if (!_.isUndefined(decoration) && !_.includes(languagesWithoutCaps, this._selectedLanguage)) {
switch (decoration) {
case Deco.Cap:
text = this._capitalize(text);