From 2cbeeac90a6de170023d6919f1aef25383512a23 Mon Sep 17 00:00:00 2001 From: Dmytro Gokun Date: Fri, 29 Mar 2019 12:29:54 +0200 Subject: [PATCH] Make sure flow tests pass --- src/ui/localization/ui-translator.js | 54 +++++++++++----------------- src/ui/localization/uk.js | 2 ++ src/ui/map.js | 2 +- 3 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/ui/localization/ui-translator.js b/src/ui/localization/ui-translator.js index 3d96e0e57ad..af2762a407d 100644 --- a/src/ui/localization/ui-translator.js +++ b/src/ui/localization/ui-translator.js @@ -5,50 +5,36 @@ import uk from './uk'; const SupportedUiLanguages = { 'en': {}, - 'uk': uk + uk }; -class UiTranslator -{ - _strings: object; +class UiTranslator { + _strings: Object; - constructor(uiLanguage?: string, uiLanguagePatch?: object) { - switch (typeof uiLanguage) { - case 'string': - this._strings = SupportedUiLanguages[uiLanguage]; - if (this._strings === undefined) { - warnOnce(`uiLanguage '${uiLanguage}' is not supported`); - this._strings = {}; - } - break; - - case 'null': - case 'undefined': - this._strings = {}; - break; - - default: - warnOnce(`'uiLanguage' expected to be a string but it is '${typeof uiLanguage}'`); + constructor(uiLanguage: ?string, uiLanguagePatch: ?Object) { + if (uiLanguage == null) { + this._strings = {}; + } else if (typeof uiLanguage === 'string') { + this._strings = SupportedUiLanguages[uiLanguage]; + if (this._strings === undefined) { + warnOnce(`uiLanguage '${uiLanguage}' is not supported`); this._strings = {}; - break; + } + } else { + warnOnce(`'uiLanguage' expected to be a string but it has type '${typeof uiLanguage}'`); + this._strings = {}; } - switch (typeof uiLanguagePatch) { - case 'object': + if (uiLanguagePatch != null) { + if (typeof uiLanguagePatch === 'object') { this._strings = extend(clone(this._strings), uiLanguagePatch); - break; - - case 'null': - case 'undefined': - break; - - default: - warnOnce(`'uiLanguagePatch' expected to be an object but it is '${typeof uiLanguagePatch}'`); - break; + } else { + warnOnce(`'uiLanguagePatch' expected to be an object but it has type '${typeof uiLanguagePatch}'`); + } } } - translate(key: string): string | undefined { + translate(key: string): ?string { return this._strings[key]; } } diff --git a/src/ui/localization/uk.js b/src/ui/localization/uk.js index 7d7b166554c..7ec46f0b494 100644 --- a/src/ui/localization/uk.js +++ b/src/ui/localization/uk.js @@ -1,3 +1,5 @@ +// @flow + const uk = { 'FullscreenControl.EnterTooltip': 'Повноекранний режим', 'FullscreenControl.ExitTooltip': 'Вийти з повноекранного режиму', diff --git a/src/ui/map.js b/src/ui/map.js index dd6fa1b5aca..62402b979b5 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -98,7 +98,7 @@ type MapOptions = { maxTileCacheSize?: number, transformRequest?: RequestTransformFunction, uiLanguage?: string, - uiLanguagePatch?: object + uiLanguagePatch?: Object }; const defaultMinZoom = 0;