diff options
author | Fabio Berger <me@fabioberger.com> | 2018-02-21 11:53:07 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-02-21 11:53:07 +0800 |
commit | 13fed15e0c4a643bb5a80737901c3d85be39e6ee (patch) | |
tree | 91ff437a50cfde62083a9c3a4a1fd2b999ee6dd5 /packages/website/ts/utils | |
parent | 38a308ce5b15b83f41e2646e50c2bfa7584ca3ab (diff) | |
download | dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar.gz dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar.bz2 dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar.lz dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar.xz dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.tar.zst dexon-sol-tools-13fed15e0c4a643bb5a80737901c3d85be39e6ee.zip |
Improve homepage and add translations in chinese, russian, korean and spanish
Diffstat (limited to 'packages/website/ts/utils')
-rw-r--r-- | packages/website/ts/utils/translate.ts | 34 |
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); |