load language on startup
This commit is contained in:
parent
d289616347
commit
a2d0f0dcf8
10 changed files with 80 additions and 35 deletions
|
@ -138,7 +138,7 @@ class DrawerContent extends React.PureComponent {
|
||||||
<View key={groupName} style={discoverStyle.menuGroup}>
|
<View key={groupName} style={discoverStyle.menuGroup}>
|
||||||
{groupNames[3] !== groupName && (
|
{groupNames[3] !== groupName && (
|
||||||
<Text key={`${groupName}-title`} style={discoverStyle.menuGroupName}>
|
<Text key={`${groupName}-title`} style={discoverStyle.menuGroupName}>
|
||||||
{groupName}
|
{__(groupName)}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
{menuItems.map(item => {
|
{menuItems.map(item => {
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { __ } from 'i18n';
|
||||||
|
|
||||||
const SORT_BY_NEW = 'new';
|
const SORT_BY_NEW = 'new';
|
||||||
const SORT_BY_HOT = 'hot';
|
const SORT_BY_HOT = 'hot';
|
||||||
const SORT_BY_TOP = 'top';
|
const SORT_BY_TOP = 'top';
|
||||||
|
@ -94,8 +96,8 @@ const Constants = {
|
||||||
|
|
||||||
ROUTE_FILE: 'File',
|
ROUTE_FILE: 'File',
|
||||||
|
|
||||||
ITEM_CREATE_A_CHANNEL: 'Create a channel...',
|
ITEM_CREATE_A_CHANNEL: __('Create a channel...'),
|
||||||
ITEM_ANONYMOUS: 'Publish anonymously',
|
ITEM_ANONYMOUS: __('Publish anonymously'),
|
||||||
|
|
||||||
SUBSCRIPTIONS_VIEW_ALL: 'view_all',
|
SUBSCRIPTIONS_VIEW_ALL: 'view_all',
|
||||||
SUBSCRIPTIONS_VIEW_LATEST_FIRST: 'view_latest_first',
|
SUBSCRIPTIONS_VIEW_LATEST_FIRST: 'view_latest_first',
|
||||||
|
@ -114,17 +116,17 @@ const Constants = {
|
||||||
TIME_ALL,
|
TIME_ALL,
|
||||||
|
|
||||||
CLAIM_SEARCH_SORT_BY_ITEMS: [
|
CLAIM_SEARCH_SORT_BY_ITEMS: [
|
||||||
{ icon: 'fire-alt', name: SORT_BY_HOT, label: 'Trending content' },
|
{ icon: 'fire-alt', name: SORT_BY_HOT, label: __('Trending content') },
|
||||||
{ icon: 'certificate', name: SORT_BY_NEW, label: 'New content' },
|
{ icon: 'certificate', name: SORT_BY_NEW, label: __('New content') },
|
||||||
{ icon: 'chart-line', name: SORT_BY_TOP, label: 'Top content' },
|
{ icon: 'chart-line', name: SORT_BY_TOP, label: __('Top content') },
|
||||||
],
|
],
|
||||||
|
|
||||||
CLAIM_SEARCH_TIME_ITEMS: [
|
CLAIM_SEARCH_TIME_ITEMS: [
|
||||||
{ name: TIME_DAY, label: 'Past 24 hours' },
|
{ name: TIME_DAY, label: __('Past 24 hours') },
|
||||||
{ name: TIME_WEEK, label: 'Past week' },
|
{ name: TIME_WEEK, label: __('Past week') },
|
||||||
{ name: TIME_MONTH, label: 'Past month' },
|
{ name: TIME_MONTH, label: __('Past month') },
|
||||||
{ name: TIME_YEAR, label: 'Past year' },
|
{ name: TIME_YEAR, label: __('Past year') },
|
||||||
{ name: TIME_ALL, label: 'All time' },
|
{ name: TIME_ALL, label: __('All time') },
|
||||||
],
|
],
|
||||||
|
|
||||||
DEFAULT_ORDER_BY: ['trending_global', 'trending_mixed'],
|
DEFAULT_ORDER_BY: ['trending_global', 'trending_mixed'],
|
||||||
|
|
|
@ -256,7 +256,7 @@ class DiscoverPage extends React.PureComponent {
|
||||||
return (
|
return (
|
||||||
<View style={discoverStyle.listHeader}>
|
<View style={discoverStyle.listHeader}>
|
||||||
<View style={discoverStyle.titleRow}>
|
<View style={discoverStyle.titleRow}>
|
||||||
<Text style={discoverStyle.pageTitle}>Your tags</Text>
|
<Text style={discoverStyle.pageTitle}>{__('Your Tags')}</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={discoverStyle.pickerRow}>
|
<View style={discoverStyle.pickerRow}>
|
||||||
<View style={discoverStyle.leftPickerRow}>
|
<View style={discoverStyle.leftPickerRow}>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doToast } from 'lbry-redux';
|
import { SETTINGS, doToast } from 'lbry-redux';
|
||||||
import {
|
import {
|
||||||
doAuthenticate,
|
doAuthenticate,
|
||||||
doCheckSync,
|
doCheckSync,
|
||||||
|
@ -21,6 +21,7 @@ import {
|
||||||
selectUser,
|
selectUser,
|
||||||
} from 'lbryinc';
|
} from 'lbryinc';
|
||||||
import { doSetClientSetting } from 'redux/actions/settings';
|
import { doSetClientSetting } from 'redux/actions/settings';
|
||||||
|
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||||
import FirstRun from './view';
|
import FirstRun from './view';
|
||||||
|
|
||||||
const select = state => ({
|
const select = state => ({
|
||||||
|
@ -31,6 +32,7 @@ const select = state => ({
|
||||||
emailNewPending: selectEmailNewIsPending(state),
|
emailNewPending: selectEmailNewIsPending(state),
|
||||||
hasSyncedWallet: selectHasSyncedWallet(state),
|
hasSyncedWallet: selectHasSyncedWallet(state),
|
||||||
getSyncIsPending: selectGetSyncIsPending(state),
|
getSyncIsPending: selectGetSyncIsPending(state),
|
||||||
|
language: makeSelectClientSetting(SETTINGS.LANGUAGE)(state),
|
||||||
syncApplyErrorMessage: selectSyncApplyErrorMessage(state),
|
syncApplyErrorMessage: selectSyncApplyErrorMessage(state),
|
||||||
syncApplyIsPending: selectSyncApplyIsPending(state),
|
syncApplyIsPending: selectSyncApplyIsPending(state),
|
||||||
syncHash: selectSyncHash(state),
|
syncHash: selectSyncHash(state),
|
||||||
|
|
|
@ -11,6 +11,7 @@ import EmailCollectPage from './internal/email-collect-page';
|
||||||
import EmailVerifyPage from './internal/email-verify-page';
|
import EmailVerifyPage from './internal/email-verify-page';
|
||||||
import SkipAccountPage from './internal/skip-account-page';
|
import SkipAccountPage from './internal/skip-account-page';
|
||||||
import firstRunStyle from 'styles/firstRun';
|
import firstRunStyle from 'styles/firstRun';
|
||||||
|
import RNFS from 'react-native-fs';
|
||||||
|
|
||||||
class FirstRunScreen extends React.PureComponent {
|
class FirstRunScreen extends React.PureComponent {
|
||||||
static pages = [
|
static pages = [
|
||||||
|
@ -35,6 +36,7 @@ class FirstRunScreen extends React.PureComponent {
|
||||||
showBottomContainer: false,
|
showBottomContainer: false,
|
||||||
walletPassword: '',
|
walletPassword: '',
|
||||||
syncApplyStarted: false,
|
syncApplyStarted: false,
|
||||||
|
languageLoaded: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -43,27 +45,46 @@ class FirstRunScreen extends React.PureComponent {
|
||||||
this.setState({ launchUrl: url });
|
this.setState({ launchUrl: url });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (NativeModules.FirstRun) {
|
componentDidUpdate() {
|
||||||
NativeModules.FirstRun.isFirstRun().then(firstRun => {
|
const { language } = this.props;
|
||||||
AsyncStorage.removeItem(Constants.KEY_FIRST_RUN_EMAIL);
|
|
||||||
AsyncStorage.removeItem(Constants.KEY_EMAIL_VERIFY_PENDING);
|
|
||||||
this.setState({ isFirstRun: firstRun });
|
|
||||||
|
|
||||||
if (firstRun) {
|
if (language && !this.state.languageLoaded) {
|
||||||
NativeModules.Firebase.setCurrentScreen('First Run');
|
this.setState({ languageLoaded: true }, () => {
|
||||||
this.setState({ currentPage: FirstRunScreen.pages[0] });
|
// Load the current language setting before doing anything
|
||||||
} else {
|
const languageFile = RNFS.ExternalDirectoryPath + '/' + language + '.json';
|
||||||
// Not the first run. Navigate to the splash screen right away
|
RNFS.readFile(languageFile, 'utf8')
|
||||||
this.launchSplashScreen();
|
.then(fileContents => {
|
||||||
}
|
const json = JSON.parse(fileContents);
|
||||||
|
window.language = language;
|
||||||
|
window.i18n_messages[language] = json;
|
||||||
|
this.checkFirstRun();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
// language file doesn't exist? maintain the default language
|
||||||
|
this.checkFirstRun();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// The first run module was not detected. Go straight to the splash screen.
|
|
||||||
this.launchSplashScreen();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkFirstRun = () => {
|
||||||
|
NativeModules.FirstRun.isFirstRun().then(firstRun => {
|
||||||
|
AsyncStorage.removeItem(Constants.KEY_FIRST_RUN_EMAIL);
|
||||||
|
AsyncStorage.removeItem(Constants.KEY_EMAIL_VERIFY_PENDING);
|
||||||
|
this.setState({ isFirstRun: firstRun });
|
||||||
|
|
||||||
|
if (firstRun) {
|
||||||
|
NativeModules.Firebase.setCurrentScreen('First Run');
|
||||||
|
this.setState({ currentPage: FirstRunScreen.pages[0] });
|
||||||
|
} else {
|
||||||
|
// Not the first run. Navigate to the splash screen right away
|
||||||
|
this.launchSplashScreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
const { emailNewErrorMessage, emailNewPending, syncApplyErrorMessage, syncApplyIsPending, user } = nextProps;
|
const { emailNewErrorMessage, emailNewPending, syncApplyErrorMessage, syncApplyIsPending, user } = nextProps;
|
||||||
const { notify, isApplyingSync, setClientSetting } = this.props;
|
const { notify, isApplyingSync, setClientSetting } = this.props;
|
||||||
|
@ -325,6 +346,7 @@ class FirstRunScreen extends React.PureComponent {
|
||||||
emailNewErrorMessage,
|
emailNewErrorMessage,
|
||||||
emailNewPending,
|
emailNewPending,
|
||||||
emailToVerify,
|
emailToVerify,
|
||||||
|
language,
|
||||||
notify,
|
notify,
|
||||||
hasSyncedWallet,
|
hasSyncedWallet,
|
||||||
getSyncIsPending,
|
getSyncIsPending,
|
||||||
|
|
|
@ -96,8 +96,6 @@ class SettingsPage extends React.PureComponent {
|
||||||
.then(j => {
|
.then(j => {
|
||||||
window.i18n_messages[language] = j;
|
window.i18n_messages[language] = j;
|
||||||
|
|
||||||
console.log(window.i18n_messages);
|
|
||||||
|
|
||||||
// write the language file to the filesystem
|
// write the language file to the filesystem
|
||||||
const langFilePath = RNFS.ExternalDirectoryPath + '/' + language + '.json';
|
const langFilePath = RNFS.ExternalDirectoryPath + '/' + language + '.json';
|
||||||
RNFS.writeFile(langFilePath, JSON.stringify(j), 'utf8');
|
RNFS.writeFile(langFilePath, JSON.stringify(j), 'utf8');
|
||||||
|
@ -168,7 +166,7 @@ class SettingsPage extends React.PureComponent {
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<Text style={settingsStyle.sectionTitle}>{__('Language')}</Text>
|
<Text style={settingsStyle.sectionTitle}>{__('Language')}</Text>
|
||||||
<View style={settingsStyle.row}>
|
<View style={settingsStyle.pickerRow}>
|
||||||
<View style={settingsStyle.pickerText}>
|
<View style={settingsStyle.pickerText}>
|
||||||
<Text style={settingsStyle.label}>{__('Choose language')}</Text>
|
<Text style={settingsStyle.label}>{__('Choose language')}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { doBalanceSubscribe, doUpdateBlockHeight, doPopulateSharedUserState, doToast } from 'lbry-redux';
|
import { SETTINGS, doBalanceSubscribe, doUpdateBlockHeight, doPopulateSharedUserState, doToast } from 'lbry-redux';
|
||||||
import {
|
import {
|
||||||
doAuthenticate,
|
doAuthenticate,
|
||||||
doBlackListedOutpointsSubscribe,
|
doBlackListedOutpointsSubscribe,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { ActivityIndicator, DeviceEventEmitter, Linking, NativeModules, Platform
|
||||||
import { NavigationActions, StackActions } from 'react-navigation';
|
import { NavigationActions, StackActions } from 'react-navigation';
|
||||||
import { decode as atob } from 'base-64';
|
import { decode as atob } from 'base-64';
|
||||||
import { navigateToUri, transformUrl } from 'utils/helper';
|
import { navigateToUri, transformUrl } from 'utils/helper';
|
||||||
|
import { __ } from 'i18n';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import AsyncStorage from '@react-native-community/async-storage';
|
import AsyncStorage from '@react-native-community/async-storage';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
@ -13,7 +14,7 @@ import PropTypes from 'prop-types';
|
||||||
import Colors from 'styles/colors';
|
import Colors from 'styles/colors';
|
||||||
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
|
import Constants from 'constants'; // eslint-disable-line node/no-deprecated-api
|
||||||
import splashStyle from 'styles/splash';
|
import splashStyle from 'styles/splash';
|
||||||
import { __ } from 'i18n';
|
import RNFS from 'react-native-fs';
|
||||||
|
|
||||||
const BLOCK_HEIGHT_INTERVAL = 1000 * 60 * 2.5; // every 2.5 minutes
|
const BLOCK_HEIGHT_INTERVAL = 1000 * 60 * 2.5; // every 2.5 minutes
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ const channelSelectorStyle = StyleSheet.create({
|
||||||
height: 52,
|
height: 52,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
},
|
},
|
||||||
|
channelPickerItem: {
|
||||||
|
fontFamily: 'Inter-UI-Regular',
|
||||||
|
fontSize: 16,
|
||||||
|
},
|
||||||
bidRow: {
|
bidRow: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
|
|
@ -29,10 +29,12 @@ const settingsStyle = StyleSheet.create({
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
pickerText: {
|
pickerText: {
|
||||||
width: '50%',
|
width: '40%',
|
||||||
},
|
},
|
||||||
pickerContainer: {
|
pickerContainer: {
|
||||||
width: '50%',
|
width: '60%',
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
|
@ -60,6 +62,20 @@ const settingsStyle = StyleSheet.create({
|
||||||
sectionDivider: {
|
sectionDivider: {
|
||||||
marginTop: 24,
|
marginTop: 24,
|
||||||
},
|
},
|
||||||
|
languagePicker: {
|
||||||
|
width: '85%',
|
||||||
|
},
|
||||||
|
languagePickerItem: {
|
||||||
|
fontFamily: 'Inter-UI-Regular',
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
pickerRow: {
|
||||||
|
marginBottom: 24,
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default settingsStyle;
|
export default settingsStyle;
|
||||||
|
|
Loading…
Reference in a new issue