this also doesnt work

This commit is contained in:
Jeremy Kauffman 2019-11-08 15:51:42 -05:00 committed by Sean Yesmunt
parent 8a2393cb67
commit d10ec54a5e
7 changed files with 41 additions and 7 deletions

View file

@ -861,5 +861,6 @@
"You haven't downloaded anything from LBRY yet.": "You haven't downloaded anything from LBRY yet.", "You haven't downloaded anything from LBRY yet.": "You haven't downloaded anything from LBRY yet.",
"Explore new content": "Explore new content", "Explore new content": "Explore new content",
"Use this address to receive LBC.": "Use this address to receive LBC.", "Use this address to receive LBC.": "Use this address to receive LBC.",
"Embedded": "Embedded" "Embedded": "Embedded",
"Failed to load %language% translations.": "Failed to load %language% translations."
} }

View file

@ -3,8 +3,9 @@ import { hot } from 'react-hot-loader/root';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectUser, doRewardList, doFetchAccessToken, selectGetSyncErrorMessage, selectUploadCount } from 'lbryinc'; import { selectUser, doRewardList, doFetchAccessToken, selectGetSyncErrorMessage, selectUploadCount } from 'lbryinc';
import { doFetchTransactions, doFetchChannelListMine } from 'lbry-redux'; import { doFetchTransactions, doFetchChannelListMine } from 'lbry-redux';
import { makeSelectClientSetting, selectThemePath } from 'redux/selectors/settings'; import { makeSelectClientSetting, selectLoadedLanguages, selectThemePath } from 'redux/selectors/settings';
import { selectIsUpgradeAvailable, selectAutoUpdateDownloaded } from 'redux/selectors/app'; import { selectIsUpgradeAvailable, selectAutoUpdateDownloaded } from 'redux/selectors/app';
import { doSetLanguage } from 'redux/actions/settings';
import { doDownloadUpgradeRequested, doSignIn, doSyncWithPreferences } from 'redux/actions/app'; import { doDownloadUpgradeRequested, doSignIn, doSyncWithPreferences } from 'redux/actions/app';
import App from './view'; import App from './view';
@ -12,6 +13,7 @@ const select = state => ({
user: selectUser(state), user: selectUser(state),
theme: selectThemePath(state), theme: selectThemePath(state),
language: makeSelectClientSetting(SETTINGS.LANGUAGE)(state), language: makeSelectClientSetting(SETTINGS.LANGUAGE)(state),
languages: selectLoadedLanguages(state),
autoUpdateDownloaded: selectAutoUpdateDownloaded(state), autoUpdateDownloaded: selectAutoUpdateDownloaded(state),
isUpgradeAvailable: selectIsUpgradeAvailable(state), isUpgradeAvailable: selectIsUpgradeAvailable(state),
syncEnabled: makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state), syncEnabled: makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state),
@ -24,6 +26,7 @@ const perform = dispatch => ({
fetchTransactions: (page, pageSize) => dispatch(doFetchTransactions(page, pageSize)), fetchTransactions: (page, pageSize) => dispatch(doFetchTransactions(page, pageSize)),
fetchAccessToken: () => dispatch(doFetchAccessToken()), fetchAccessToken: () => dispatch(doFetchAccessToken()),
fetchChannelListMine: () => dispatch(doFetchChannelListMine()), fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
setLanguage: language => dispatch(doSetLanguage(language)),
signIn: () => dispatch(doSignIn()), signIn: () => dispatch(doSignIn()),
requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()), requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()),
checkSync: () => dispatch(doSyncWithPreferences()), checkSync: () => dispatch(doSyncWithPreferences()),

View file

@ -26,6 +26,7 @@ type Props = {
alertError: (string | {}) => void, alertError: (string | {}) => void,
pageTitle: ?string, pageTitle: ?string,
language: string, language: string,
languages: Array<string>,
theme: string, theme: string,
user: ?{ id: string, has_verified_email: boolean, is_reward_approved: boolean }, user: ?{ id: string, has_verified_email: boolean, is_reward_approved: boolean },
location: { pathname: string, hash: string }, location: { pathname: string, hash: string },
@ -38,6 +39,7 @@ type Props = {
requestDownloadUpgrade: () => void, requestDownloadUpgrade: () => void,
fetchChannelListMine: () => void, fetchChannelListMine: () => void,
onSignedIn: () => void, onSignedIn: () => void,
setLanguage: string => void,
isUpgradeAvailable: boolean, isUpgradeAvailable: boolean,
autoUpdateDownloaded: boolean, autoUpdateDownloaded: boolean,
checkSync: () => void, checkSync: () => void,
@ -65,6 +67,9 @@ function App(props: Props) {
uploadCount, uploadCount,
history, history,
syncError, syncError,
language,
languages,
setLanguage,
} = props; } = props;
const appRef = useRef(); const appRef = useRef();
@ -111,6 +116,12 @@ function App(props: Props) {
document.documentElement.setAttribute('data-mode', theme); document.documentElement.setAttribute('data-mode', theme);
}, [theme]); }, [theme]);
useEffect(() => {
if (!languages.includes(language)) {
setLanguage(language);
}
}, [language, languages]);
useEffect(() => { useEffect(() => {
if (previousUserId === undefined && userId) { if (previousUserId === undefined && userId) {
analytics.setUser(userId); analytics.setUser(userId);

View file

@ -159,8 +159,7 @@ export const CLAIM_REWARD_CLEAR_ERROR = 'CLAIM_REWARD_CLEAR_ERROR';
export const FETCH_REWARD_CONTENT_COMPLETED = 'FETCH_REWARD_CONTENT_COMPLETED'; export const FETCH_REWARD_CONTENT_COMPLETED = 'FETCH_REWARD_CONTENT_COMPLETED';
// Language // Language
export const DOWNLOAD_LANGUAGE_SUCCEEDED = 'DOWNLOAD_LANGUAGE_SUCCEEDED'; export const DOWNLOAD_LANGUAGE_SUCCESS = 'DOWNLOAD_LANGUAGE_SUCCESS';
export const DOWNLOAD_LANGUAGE_FAILED = 'DOWNLOAD_LANGUAGE_FAILED';
// Subscriptions // Subscriptions
export const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE'; export const CHANNEL_SUBSCRIBE = 'CHANNEL_SUBSCRIBE';

View file

@ -1,5 +1,6 @@
import { Lbry, ACTIONS, doToast } from 'lbry-redux'; import { Lbry, ACTIONS, doToast } from 'lbry-redux';
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import * as LOCAL_ACTIONS from 'constants/action_types';
import analytics from 'analytics'; import analytics from 'analytics';
import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import SUPPORTED_LANGUAGES from 'constants/supported_languages';
@ -91,6 +92,12 @@ export function doSetLanguage(language) {
.then(r => r.json()) .then(r => r.json())
.then(j => { .then(j => {
window.i18n_messages[language] = j; window.i18n_messages[language] = j;
dispatch({
type: LOCAL_ACTIONS.DOWNLOAD_LANGUAGE_SUCCESS,
data: {
language,
},
});
}) })
.then(() => { .then(() => {
// set on localStorage so it can be read outside of redux // set on localStorage so it can be read outside of redux

View file

@ -5,7 +5,7 @@ import moment from 'moment';
const reducers = {}; const reducers = {};
const defaultState = { const defaultState = {
isNight: false, isNight: false,
isFetchingLanguage: false, loadedLanguages: Object.keys(window.i18n_messages) || [],
daemonSettings: {}, daemonSettings: {},
clientSettings: { clientSettings: {
// UX // UX
@ -70,6 +70,19 @@ reducers[ACTIONS.UPDATE_IS_NIGHT] = state => {
}); });
}; };
reducers[ACTIONS.DOWNLOAD_LANGUAGE_SUCCESS] = (state, action) => {
const { loadedLanguages } = state;
const { language } = action.data;
if (language && !loadedLanguages.includes(language)) {
return Object.assign({}, state, {
loadedLanguages: [...loadedLanguages, language],
});
} else {
return state;
}
};
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -13,9 +13,9 @@ export const selectClientSettings = createSelector(
state => state.clientSettings || {} state => state.clientSettings || {}
); );
export const selectIsFetchingLanguage = createSelector( export const selectLoadedLanguages = createSelector(
selectState, selectState,
state => state.isFetchingLanguage || {} state => state.loadedLanguages || {}
); );
export const makeSelectClientSetting = setting => export const makeSelectClientSetting = setting =>