// @flow import React, { useState } from 'react'; import { FormField } from 'component/common/form'; import Spinner from 'component/spinner'; import { SETTINGS } from 'lbry-redux'; type Props = { language: string, showToast: ({}) => void, setClientSetting: (string, boolean) => void, }; function SettingLanguage(props: Props) { const [isFetching, setIsFetching] = useState(false); // this should be fetched from lbry.com/transifex const languages = { en: 'English', pl: 'Polski', id: 'Bahasa Indonesia', de: 'Deutsche' , fr: 'Français', sk: 'Slovenský', tr: 'Türk', zh: '中文' }; const { language, showToast, setClientSetting } = props; function onLanguageChange(e) { const { value } = e.target; setIsFetching(true); // this should match the behavior/logic in the static index-XXX.html files fetch('https://lbry.com/i18n/get/lbry-desktop/app-strings/' + value + '.json') .then(r => r.json()) .then(j => { window.i18n_messages[value] = j; }) .then(() => { setIsFetching(false); window.localStorage.setItem(SETTINGS.LANGUAGE, value); setClientSetting(SETTINGS.LANGUAGE, value); }) .catch(e => { showToast({ message: __('Failed to load translations.'), error: true, }); setIsFetching(false); }); } return ( {Object.keys(languages).map(language => ( ))} {isFetching && } ); } export default SettingLanguage;