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.",
"Explore new content": "Explore new content",
"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 { selectUser, doRewardList, doFetchAccessToken, selectGetSyncErrorMessage, selectUploadCount } from 'lbryinc';
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 { doSetLanguage } from 'redux/actions/settings';
import { doDownloadUpgradeRequested, doSignIn, doSyncWithPreferences } from 'redux/actions/app';
import App from './view';
@ -12,6 +13,7 @@ const select = state => ({
user: selectUser(state),
theme: selectThemePath(state),
language: makeSelectClientSetting(SETTINGS.LANGUAGE)(state),
languages: selectLoadedLanguages(state),
autoUpdateDownloaded: selectAutoUpdateDownloaded(state),
isUpgradeAvailable: selectIsUpgradeAvailable(state),
syncEnabled: makeSelectClientSetting(SETTINGS.ENABLE_SYNC)(state),
@ -24,6 +26,7 @@ const perform = dispatch => ({
fetchTransactions: (page, pageSize) => dispatch(doFetchTransactions(page, pageSize)),
fetchAccessToken: () => dispatch(doFetchAccessToken()),
fetchChannelListMine: () => dispatch(doFetchChannelListMine()),
setLanguage: language => dispatch(doSetLanguage(language)),
signIn: () => dispatch(doSignIn()),
requestDownloadUpgrade: () => dispatch(doDownloadUpgradeRequested()),
checkSync: () => dispatch(doSyncWithPreferences()),

View file

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

View file

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

View file

@ -5,7 +5,7 @@ import moment from 'moment';
const reducers = {};
const defaultState = {
isNight: false,
isFetchingLanguage: false,
loadedLanguages: Object.keys(window.i18n_messages) || [],
daemonSettings: {},
clientSettings: {
// 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) {
const handler = reducers[action.type];
if (handler) return handler(state, action);

View file

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