diff --git a/src/components/i18n/actions.js b/src/components/i18n/actions.js index 9869ffa..4224f1c 100644 --- a/src/components/i18n/actions.js +++ b/src/components/i18n/actions.js @@ -1,26 +1,26 @@ +// @flow import i18n from 'services/i18n'; import captcha from 'services/captcha'; export const SET_LOCALE = 'i18n:setLocale'; -export function setLocale(locale) { - return (dispatch) => i18n.require( - i18n.detectLanguage(locale) - ).then(({locale, messages}) => { - dispatch(_setLocale({locale, messages})); +export function setLocale(desiredLocale: string) { + return async (dispatch: (action: Object) => any) => { + const { locale, messages } = await i18n.require(i18n.detectLanguage(desiredLocale)); + dispatch(_setLocale(locale, messages)); // TODO: probably should be moved from here, because it is a side effect captcha.setLang(locale); return locale; - }); + }; } -function _setLocale({locale, messages}) { +function _setLocale(locale: string, messages: { [string]: string }) { return { type: SET_LOCALE, payload: { locale, - messages - } + messages, + }, }; } diff --git a/src/components/languageSwitcher/LanguageList.js b/src/components/languageSwitcher/LanguageList.js index 91c7917..9122924 100644 --- a/src/components/languageSwitcher/LanguageList.js +++ b/src/components/languageSwitcher/LanguageList.js @@ -18,14 +18,14 @@ import type { LocalesMap } from './LanguageSwitcher'; const itemHeight = 51; export default class LanguageList extends React.Component<{ - userLang: string, + selectedLocale: string, langs: LocalesMap, onChangeLang: (lang: string) => void, }> { emptyListStateInner: ?HTMLDivElement; render() { - const { userLang, langs } = this.props; + const { selectedLocale, langs } = this.props; const isListEmpty = Object.keys(langs).length === 0; const firstLocale = Object.keys(langs)[0] || null; const emptyCaption = this.getEmptyCaption(); @@ -67,7 +67,7 @@ export default class LanguageList extends React.Component<{ key={locale} style={style} className={classNames(styles.languageItem, { - [styles.activeLanguageItem]: locale === userLang, + [styles.activeLanguageItem]: locale === selectedLocale, [styles.firstLanguageItem]: locale === firstLocale, })} onClick={this.onChangeLang(locale)} diff --git a/src/components/languageSwitcher/LanguageSwitcher.js b/src/components/languageSwitcher/LanguageSwitcher.js index fbb59ad..ae401ba 100644 --- a/src/components/languageSwitcher/LanguageSwitcher.js +++ b/src/components/languageSwitcher/LanguageSwitcher.js @@ -11,7 +11,7 @@ import styles from './languageSwitcher.scss'; import messages from './languageSwitcher.intl.json'; import LanguageList from './LanguageList'; -const translateUrl = 'https://translate.ely.by/project/elyby/invite'; +const translateUrl = 'http://ely.by/translate'; export type LocaleData = { code: string, @@ -25,7 +25,7 @@ export type LocalesMap = {[code: string]: LocaleData}; class LanguageSwitcher extends Component<{ onClose: Function, - userLang: string, + selectedLocale: string, changeLang: (lang: string) => void, langs: LocalesMap, emptyCaptions: Array<{ @@ -51,7 +51,7 @@ class LanguageSwitcher extends Component<{ }; render() { - const { userLang, onClose } = this.props; + const { selectedLocale, onClose } = this.props; const { filteredLangs } = this.state; return ( @@ -80,7 +80,7 @@ class LanguageSwitcher extends Component<{ @@ -157,7 +157,7 @@ import { connect } from 'react-redux'; import { changeLang } from 'components/user/actions'; export default connect((state) => ({ - userLang: state.user.lang, + selectedLocale: state.i18n.locale, }), { changeLang, })(LanguageSwitcher); diff --git a/src/components/languageSwitcher/changeLanguageLink/ChangeLanguageLink.js b/src/components/languageSwitcher/changeLanguageLink/ChangeLanguageLink.js index 547792e..d978a3c 100644 --- a/src/components/languageSwitcher/changeLanguageLink/ChangeLanguageLink.js +++ b/src/components/languageSwitcher/changeLanguageLink/ChangeLanguageLink.js @@ -1,31 +1,43 @@ // @flow import React from 'react'; -import { connect } from 'react-redux'; -import { create as createPopup } from 'components/ui/popup/actions'; +import classNames from 'classnames'; import { localeFlags } from 'components/i18n'; import LANGS from 'i18n/index.json'; -import LanguageSwitcher from '../LanguageSwitcher'; import styles from './link.scss'; function LanguageLink({ userLang, + interfaceLocale, showLanguageSwitcherPopup, }: { - userLang: string, - showLanguageSwitcherPopup: Function, + userLang: string; + interfaceLocale: string; + showLanguageSwitcherPopup: Function; }) { + const localeDefinition = LANGS[userLang] || LANGS[interfaceLocale]; + return ( - + - {LANGS[userLang].name} + {localeDefinition.name} ); } +import { connect } from 'react-redux'; +import { create as createPopup } from 'components/ui/popup/actions'; +import LanguageSwitcher from 'components/languageSwitcher'; + export default connect((state) => ({ userLang: state.user.lang, + interfaceLocale: state.i18n.locale, }), { showLanguageSwitcherPopup: () => createPopup(LanguageSwitcher), })(LanguageLink); diff --git a/src/components/languageSwitcher/changeLanguageLink/link.scss b/src/components/languageSwitcher/changeLanguageLink/link.scss index 61ef597..210a129 100644 --- a/src/components/languageSwitcher/changeLanguageLink/link.scss +++ b/src/components/languageSwitcher/changeLanguageLink/link.scss @@ -1,9 +1,23 @@ +@import '~components/ui/colors.scss'; + .languageLink { + position: relative; + color: #666; border-bottom: 1px dotted #666; text-decoration: none; transition: .25s; cursor: pointer; + + &.mark { + &:after { + position: absolute; + content: '*'; + color: $red; + font-size: 75%; + top: -0.20em; + } + } } .languageIcon { diff --git a/src/components/profile/Profile.intl.json b/src/components/profile/Profile.intl.json index 69a52be..06f0c67 100644 --- a/src/components/profile/Profile.intl.json +++ b/src/components/profile/Profile.intl.json @@ -12,6 +12,8 @@ "email": "E‑mail:", "password": "Password:", "siteLanguage": "Site language:", + "languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", + "participateInTheTranslation": "participate in the translation", "twoFactorAuth": "Two‑factor auth:", "uuid": "UUID:" } diff --git a/src/components/profile/Profile.js b/src/components/profile/Profile.js index 041d530..f1696c3 100644 --- a/src/components/profile/Profile.js +++ b/src/components/profile/Profile.js @@ -14,12 +14,13 @@ import RulesPage from 'pages/rules/RulesPage'; import type { User } from 'components/user'; class Profile extends Component<{ - user: User + user: User; + interfaceLocale: string; }> { UUID: ?HTMLElement; render() { - const { user } = this.props; + const { user, interfaceLocale } = this.props; return (
@@ -85,6 +86,16 @@ class Profile extends Component<{ } value={} + warningMessage={user.lang === interfaceLocale ? '' : ( + + + + ), + }}/> + )} /> ({ user, + interfaceLocale: i18n.locale, }))(Profile); diff --git a/src/i18n/be.json b/src/i18n/be.json index 91dd369..4834fa2 100644 --- a/src/i18n/be.json +++ b/src/i18n/be.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Не ўключана", "components.profile.email": "E‑mail:", "components.profile.enabled": "Уключана", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Знойдзены акаўнт Mojang з такім жа нікам і, па {rules}, яго ўладальнік мае права патрабаваць аднаўленне кантролю над нікам.", "components.profile.multiFactorAuth.codePlaceholder": "Увядзіце код сюды", "components.profile.multiFactorAuth.disable": "Адключыць", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Дадатак устаноўлены", "components.profile.multiFactorAuth.whenKeyEntered": "Убачыўшы ў дадатку часовы код, перайдзіце да наступнага кроку.", "components.profile.nickname": "Нік:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Пароль:", "components.profile.passwordRequestForm.continue": "Працягнуць", "components.profile.passwordRequestForm.description": "Каб завершыць, увядзіце пароль ад акаўнта", diff --git a/src/i18n/en.json b/src/i18n/en.json index a3c5279..307c981 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Disabled", "components.profile.email": "E‑mail:", "components.profile.enabled": "Enabled", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "A Mojang account with the same nickname was found. According to {rules}, account owner has the right to demand the restoration of control over nickname.", "components.profile.multiFactorAuth.codePlaceholder": "Enter the code here", "components.profile.multiFactorAuth.disable": "Disable", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "App has been installed", "components.profile.multiFactorAuth.whenKeyEntered": "If a temporary code appears in your two‑factor auth app, then you may proceed to the next step.", "components.profile.nickname": "Nickname:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Password:", "components.profile.passwordRequestForm.continue": "Continue", "components.profile.passwordRequestForm.description": "To complete action enter the account password", diff --git a/src/i18n/fr.json b/src/i18n/fr.json index bf3c215..08b0799 100644 --- a/src/i18n/fr.json +++ b/src/i18n/fr.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Désactivée", "components.profile.email": "E‑mail:", "components.profile.enabled": "Activer", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Un compte Mojang avec le même pseudo a été trouvé. Selon les {rules}, le propriétaire du compte a le droit d'exiger la restauration du contrôle sur le surnom.", "components.profile.multiFactorAuth.codePlaceholder": "Entrez le code ici", "components.profile.multiFactorAuth.disable": "Désactiver", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "L'application a été installé", "components.profile.multiFactorAuth.whenKeyEntered": "If a temporary code appears in your two‑factor auth app, then you may proceed to the next step.", "components.profile.nickname": "Surnom:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Mot de passe:", "components.profile.passwordRequestForm.continue": "Continuer", "components.profile.passwordRequestForm.description": "Pour compléter cette action, entrez le mot de passe du compte", diff --git a/src/i18n/id.json b/src/i18n/id.json index c45c098..e2ecb02 100644 --- a/src/i18n/id.json +++ b/src/i18n/id.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Dinonaktifkan", "components.profile.email": "E‑mail:", "components.profile.enabled": "Diaktifkan", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Mojang akun dengan nickname yang sama di temukan. Sesuai dengan {rules}, pemilik akun dapat mengambil kontrol dengan nickname-nya.", "components.profile.multiFactorAuth.codePlaceholder": "Masukkan kodenya disini", "components.profile.multiFactorAuth.disable": "Nonaktifkan", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Aplikasi telah diunduh", "components.profile.multiFactorAuth.whenKeyEntered": "Jika kode sementara muncul di aplikasi otorisasi dua-faktor anda, anda boleh lanjut ke tahap berikutnya.", "components.profile.nickname": "Nama panggilan:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Kata sandi:", "components.profile.passwordRequestForm.continue": "Lanjut", "components.profile.passwordRequestForm.description": "Untuk menyelesaikan, masukan kata sandi", diff --git a/src/i18n/lt.json b/src/i18n/lt.json index 1d64403..a655ba8 100644 --- a/src/i18n/lt.json +++ b/src/i18n/lt.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Išjungtas", "components.profile.email": "El.Paštas:", "components.profile.enabled": "Įjungtas", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Buvo rasta Mojang paskyra su tuo pačiu slapyvardžiu. Pagal {rules}, paskyros savininkas turi teisę reikalauti atkurti slapyvardžio kontrolę.", "components.profile.multiFactorAuth.codePlaceholder": "Įveskite kodą čia", "components.profile.multiFactorAuth.disable": "Išjungti", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Programa įdiegta", "components.profile.multiFactorAuth.whenKeyEntered": "Jei dviejų veiksmų programoje pasirodo laikinas kodas, galite pereiti prie kito žingsnio.", "components.profile.nickname": "Slapyvardis:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Slaptažodis:", "components.profile.passwordRequestForm.continue": "Tęsti", "components.profile.passwordRequestForm.description": "Norėdami užbaigti veiksmą įveskite paskyros slaptažodį", diff --git a/src/i18n/pl.json b/src/i18n/pl.json index e9efd93..31263ab 100644 --- a/src/i18n/pl.json +++ b/src/i18n/pl.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Wyłączone", "components.profile.email": "E‑mail:", "components.profile.enabled": "Włączone", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Znaleziono konto Mojang z tym samym nickiem. Zgodnie z {rules} właściciel konta ma prawo żądać przywrócenia kontroli nad pseudonimem.", "components.profile.multiFactorAuth.codePlaceholder": "Wprowadź tutaj kod", "components.profile.multiFactorAuth.disable": "Wyłącz", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Aplikacja została zainstalowana", "components.profile.multiFactorAuth.whenKeyEntered": "Jeżeli kod tymczasowy pojawia się w twojej aplikacji uwierzytelniania dwupoziomowego, możesz przejść do następnego kroku.", "components.profile.nickname": "Nick:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Hasło:", "components.profile.passwordRequestForm.continue": "Kontynuuj", "components.profile.passwordRequestForm.description": "Aby zakończyć działanie, wprowadź hasło konta", diff --git a/src/i18n/pt.json b/src/i18n/pt.json index ba20609..ea73279 100644 --- a/src/i18n/pt.json +++ b/src/i18n/pt.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Desativado", "components.profile.email": "E‑mail:", "components.profile.enabled": "Habilitado", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Uma conta da Mojang com o mesmo nome foi encontrada. De acordo com as {rules}, o dono desta conta tem o poder de controlar este apelido.", "components.profile.multiFactorAuth.codePlaceholder": "Digite o código aqui", "components.profile.multiFactorAuth.disable": "Desabilitar", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Aplicativo instalado", "components.profile.multiFactorAuth.whenKeyEntered": "Se um código temporário aparece no seu app de aut. em dois fatores, então você pode prosseguir para a próxima etapa.", "components.profile.nickname": "Apelido:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Senha:", "components.profile.passwordRequestForm.continue": "Continuar", "components.profile.passwordRequestForm.description": "Para completar a ação, coloque a senha da conta", diff --git a/src/i18n/ru.json b/src/i18n/ru.json index 83897b9..7fe70a1 100644 --- a/src/i18n/ru.json +++ b/src/i18n/ru.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Не включена", "components.profile.email": "E‑mail:", "components.profile.enabled": "Включена", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Найден аккаунт Mojang с таким же ником. Учтите, что согласно с {rules}, его владелец вправе потребовать восстановления контроля над ником.", "components.profile.multiFactorAuth.codePlaceholder": "Введите сюда код", "components.profile.multiFactorAuth.disable": "Отключить", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Приложение установлено", "components.profile.multiFactorAuth.whenKeyEntered": "После того, как вы увидели в приложении временный код, переходите к следующему шагу.", "components.profile.nickname": "Ник:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Пароль:", "components.profile.passwordRequestForm.continue": "Продолжить", "components.profile.passwordRequestForm.description": "Для завершения, укажите пароль от аккаунта", diff --git a/src/i18n/sr.json b/src/i18n/sr.json index 04a2033..8953e21 100644 --- a/src/i18n/sr.json +++ b/src/i18n/sr.json @@ -177,6 +177,7 @@ "components.profile.disabled": "онемогућена", "components.profile.email": "Е-пошта:", "components.profile.enabled": "омогућена", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Пронађен је Mojang налог са истим надимком. Према {rules}, власник налога има право да затражи враћање контроле над надимком.", "components.profile.multiFactorAuth.codePlaceholder": "Овде унесите кôд", "components.profile.multiFactorAuth.disable": "Онемогући", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Апликација је инсталирана", "components.profile.multiFactorAuth.whenKeyEntered": "Ако се привремени кôд појави у апликацији за потврду идентитета помоћу два фактора, можете прећи на следећи корак.", "components.profile.nickname": "Надимак:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Лозинка:", "components.profile.passwordRequestForm.continue": "Настави", "components.profile.passwordRequestForm.description": "Да бисте довршили радњу, унесите лозинку налога", diff --git a/src/i18n/uk.json b/src/i18n/uk.json index ae89164..f8b67e0 100644 --- a/src/i18n/uk.json +++ b/src/i18n/uk.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Вимкнено", "components.profile.email": "E‑mail:", "components.profile.enabled": "Увімкнена", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Знайдений акаунт Mojang з таким же ніком. Майте на увазі, що згідно з {rules}, його власник має право вимагати відновлення контролю над ніком.", "components.profile.multiFactorAuth.codePlaceholder": "Вкажіть код сюди", "components.profile.multiFactorAuth.disable": "Вимкнути", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Додаток встановлено", "components.profile.multiFactorAuth.whenKeyEntered": "Після того, як ви побачили в додатку тимчасовий код, перейдіть до наступного кроку.", "components.profile.nickname": "Нік:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Пароль:", "components.profile.passwordRequestForm.continue": "Продовжити", "components.profile.passwordRequestForm.description": "Для завершення, вкажіть пароль від акаунту", diff --git a/src/i18n/vi.json b/src/i18n/vi.json index 705a6d2..baebf0a 100644 --- a/src/i18n/vi.json +++ b/src/i18n/vi.json @@ -177,6 +177,7 @@ "components.profile.disabled": "Đã vô hiệu hóa", "components.profile.email": "E‑mail:", "components.profile.enabled": "Đã kích hoạt", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "Một tài khoản Mojang với nickname này đã được tìm thấy. Theo {rules}, chủ của tài khoản có quyền được lấy lại nickname của mình.", "components.profile.multiFactorAuth.codePlaceholder": "Nhập mã vào đây", "components.profile.multiFactorAuth.disable": "Vô hiệu hoá", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "Ứng dụng đã được cài đặt", "components.profile.multiFactorAuth.whenKeyEntered": "Nếu xuất hiện một mã tạm thời trong ứng dụng xác thực 2 bước thì bạn đã sẵn sàng để đến với bước kế tiếp.", "components.profile.nickname": "Nickname:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "Mật khẩu:", "components.profile.passwordRequestForm.continue": "Tiếp tục", "components.profile.passwordRequestForm.description": "Để hoàn tất hành động hãy nhập mật khẩu tài khoản", diff --git a/src/i18n/zh.json b/src/i18n/zh.json index 0e16d20..75112bd 100644 --- a/src/i18n/zh.json +++ b/src/i18n/zh.json @@ -177,6 +177,7 @@ "components.profile.disabled": "禁用 ", "components.profile.email": "Email:", "components.profile.enabled": "启用", + "components.profile.languageIsUnavailableWarning": "The locale \"{locale}\" you've used earlier isn't currently translated enough. If you want to continue using the selected language, please {participateInTheTranslation} of the project.", "components.profile.mojangPriorityWarning": "找到一个具有相同昵称的Mojang帐户。根据{rules},账户拥有者有权要求恢复对昵称的控制权。", "components.profile.multiFactorAuth.codePlaceholder": "在这里输入代码", "components.profile.multiFactorAuth.disable": "禁用", @@ -198,6 +199,7 @@ "components.profile.multiFactorAuth.theAppIsInstalled": "应用程序已成功安装", "components.profile.multiFactorAuth.whenKeyEntered": "如果临时代码出现在双重认证应用程序中,则可以继续下一步。", "components.profile.nickname": "名称:", + "components.profile.participateInTheTranslation": "participate in the translation", "components.profile.password": "密码:", "components.profile.passwordRequestForm.continue": "继续", "components.profile.passwordRequestForm.description": "要完成操作,请输入原帐户密码", diff --git a/src/services/i18n.js b/src/services/i18n.js index f015582..cf72d77 100644 --- a/src/services/i18n.js +++ b/src/services/i18n.js @@ -1,3 +1,4 @@ +// @flow import locales from 'i18n/index.json'; import { addLocaleData } from 'react-intl'; @@ -7,37 +8,40 @@ const DEFAULT_LANGUAGE = 'en'; const needPolyfill = !window.Intl; -function getUserLanguages(userSelectedLang = []) { - return [].concat(userSelectedLang || []) +function getUserLanguages(userSelectedLang: string): Array { + return [userSelectedLang] .concat(navigator.languages || []) .concat(navigator.language || []); } -function detectLanguage(userLanguages, availableLanguages, defaultLanguage) { - return (userLanguages || []) - .concat(defaultLanguage) +function detectLanguage( + userLanguages: Array, + availableLanguages: Array, + defaultLanguage: string, +): string { + return userLanguages .map((lang) => lang.split('-').shift().toLowerCase()) - .find((lang) => availableLanguages.indexOf(lang) !== -1); + .find((lang) => availableLanguages.indexOf(lang) !== -1) || defaultLanguage; } export default { - detectLanguage(lang) { + detectLanguage(lang: string): string { return detectLanguage(getUserLanguages(lang), SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE); }, - require(locale) { - const promises = [ + require(locale: string): Promise<{ + locale: string; + messages: { [string]: string }; + }> { + const promises: Array> = [ new Promise(require(`bundle?name=[name]!react-intl/locale-data/${locale}.js`)), new Promise(require(`bundle?name=[name]!i18n/${locale}.json`)) ]; if (needPolyfill) { - promises.push( - new Promise(require('bundle?name=intl!intl')), - ); - promises.push( - new Promise(require(`bundle?name=[name]-polyfill-data!intl/locale-data/jsonp/${locale}.js`)), - ); + // $FlowFixMe + promises.push(new Promise(require('bundle?name=intl!intl'))); + promises.push(new Promise(require(`bundle?name=[name]-polyfill-data!intl/locale-data/jsonp/${locale}.js`))); } return Promise.all(promises)