Moved application conteiner alert messages to language file

This commit is contained in:
Mustafa Buyukcelebi 2019-07-19 19:14:41 +03:00
parent 62bf784098
commit aab49edde2
3 changed files with 34 additions and 33 deletions

View File

@ -206,7 +206,8 @@
"removed": "Removed", "removed": "Removed",
"same_user": "This user already added to list", "same_user": "This user already added to list",
"unknow_error": "An error occurred", "unknow_error": "An error occurred",
"error": "Error" "error": "Error",
"fetch_error": "Fetching data from server failed, please try again or notify us at info@esteem.app"
}, },
"post": { "post": {
"reblog_alert": "Are you sure you want to reblog?", "reblog_alert": "Are you sure you want to reblog?",

View File

@ -1,7 +1,19 @@
import React from 'react'; import React from 'react';
import { Provider, connect } from 'react-redux'; import { Provider, connect } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react'; import { PersistGate } from 'redux-persist/integration/react';
import { IntlProvider } from 'react-intl'; import { IntlProvider, addLocaleData } from 'react-intl';
import en from 'react-intl/locale-data/en';
import id from 'react-intl/locale-data/id';
import ru from 'react-intl/locale-data/ru';
import de from 'react-intl/locale-data/de';
import it from 'react-intl/locale-data/it';
import hu from 'react-intl/locale-data/hu';
import tr from 'react-intl/locale-data/tr';
import ko from 'react-intl/locale-data/ko';
import lt from 'react-intl/locale-data/lt';
import pt from 'react-intl/locale-data/pt';
import fa from 'react-intl/locale-data/fa';
import { flattenMessages } from './utils/flattenMessages'; import { flattenMessages } from './utils/flattenMessages';
import messages from './config/locales'; import messages from './config/locales';
@ -9,6 +21,8 @@ import messages from './config/locales';
import Application from './screens/application'; import Application from './screens/application';
import { store, persistor } from './redux/store/store'; import { store, persistor } from './redux/store/store';
addLocaleData([...en, ...ru, ...de, ...id, ...it, ...hu, ...tr, ...ko, ...pt, ...lt, ...fa]);
const _renderApp = ({ locale }) => ( const _renderApp = ({ locale }) => (
<PersistGate loading={null} persistor={persistor}> <PersistGate loading={null} persistor={persistor}>
<IntlProvider locale={locale} messages={flattenMessages(messages[locale])}> <IntlProvider locale={locale} messages={flattenMessages(messages[locale])}>

View File

@ -7,24 +7,11 @@ import get from 'lodash/get';
import AppCenter from 'appcenter'; import AppCenter from 'appcenter';
import changeNavigationBarColor from 'react-native-navigation-bar-color'; import changeNavigationBarColor from 'react-native-navigation-bar-color';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { addLocaleData } from 'react-intl'; import { injectIntl } from 'react-intl';
import { NavigationActions } from 'react-navigation'; import { NavigationActions } from 'react-navigation';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import EStyleSheet from 'react-native-extended-stylesheet'; import EStyleSheet from 'react-native-extended-stylesheet';
// Languages
import en from 'react-intl/locale-data/en';
import id from 'react-intl/locale-data/id';
import ru from 'react-intl/locale-data/ru';
import de from 'react-intl/locale-data/de';
import it from 'react-intl/locale-data/it';
import hu from 'react-intl/locale-data/hu';
import tr from 'react-intl/locale-data/tr';
import ko from 'react-intl/locale-data/ko';
import lt from 'react-intl/locale-data/lt';
import pt from 'react-intl/locale-data/pt';
import fa from 'react-intl/locale-data/fa';
// Constants // Constants
import AUTH_TYPE from '../../../constants/authType'; import AUTH_TYPE from '../../../constants/authType';
import ROUTES from '../../../constants/routeNames'; import ROUTES from '../../../constants/routeNames';
@ -79,8 +66,6 @@ import { encryptKey } from '../../../utils/crypto';
import darkTheme from '../../../themes/darkTheme'; import darkTheme from '../../../themes/darkTheme';
import lightTheme from '../../../themes/lightTheme'; import lightTheme from '../../../themes/lightTheme';
addLocaleData([...en, ...ru, ...de, ...id, ...it, ...hu, ...tr, ...ko, ...pt, ...lt, ...fa]);
class ApplicationContainer extends Component { class ApplicationContainer extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -203,11 +188,11 @@ class ApplicationContainer extends Component {
if (get(result, 'title')) { if (get(result, 'title')) {
content = result; content = result;
} else { } else {
this._handleAlert('No existing post'); this._handleAlert('deep_link.no_existing_post');
} }
}) })
.catch(() => { .catch(() => {
this._handleAlert('No existing post'); this._handleAlert('deep_link.no_existing_post');
}); });
routeName = ROUTES.SCREENS.POST; routeName = ROUTES.SCREENS.POST;
@ -216,7 +201,7 @@ class ApplicationContainer extends Component {
profile = await getUser(author); profile = await getUser(author);
if (!profile) { if (!profile) {
this._handleAlert('No existing user'); this._handleAlert('deep_link.no_existing_user');
return; return;
} }
@ -238,8 +223,13 @@ class ApplicationContainer extends Component {
} }
}; };
_handleAlert = (title = null, text = null) => { _handleAlert = (text = null, title = null) => {
Alert.alert(title, text); const { intl } = this.props;
Alert.alert(
intl.formatMessage({ id: title || 'alert.warning' }),
intl.formatMessage({ id: text || 'alert.unknow_error' }),
);
}; };
_handleAppStateChange = nextAppState => { _handleAppStateChange = nextAppState => {
@ -337,10 +327,6 @@ class ApplicationContainer extends Component {
if (isConnected !== status) { if (isConnected !== status) {
dispatch(setConnectivityStatus(status)); dispatch(setConnectivityStatus(status));
} }
// TODO: solve this work arround
// NetInfo.isConnected.removeEventListener('connectionChange', this._handleConntectionChange);
// NetInfo.isConnected.addEventListener('connectionChange', this._handleConntectionChange);
}; };
_onBackPress = () => { _onBackPress = () => {
@ -442,7 +428,7 @@ class ApplicationContainer extends Component {
}; };
_fetchUserDataFromDsteem = async realmObject => { _fetchUserDataFromDsteem = async realmObject => {
const { dispatch } = this.props; const { dispatch, intl } = this.props;
await getUser(realmObject.username) await getUser(realmObject.username)
.then(accountData => { .then(accountData => {
@ -453,9 +439,9 @@ class ApplicationContainer extends Component {
this._connectNotificationServer(accountData.name); this._connectNotificationServer(accountData.name);
}) })
.catch(err => { .catch(err => {
this._handleAlert();
Alert.alert( Alert.alert(
`Fetching data from server failed, please try again or notify us at info@esteem.app `${intl.formatMessage({ id: 'alert.fetch_error' })} \n${err.message.substr(0, 20)}`,
\n${err.message.substr(0, 20)}`,
); );
}); });
}; };
@ -507,6 +493,7 @@ class ApplicationContainer extends Component {
otherAccounts, otherAccounts,
currentAccount: { name, local }, currentAccount: { name, local },
dispatch, dispatch,
intl,
} = this.props; } = this.props;
removeUserData(name) removeUserData(name)
@ -535,8 +522,7 @@ class ApplicationContainer extends Component {
}) })
.catch(err => { .catch(err => {
Alert.alert( Alert.alert(
`Fetching data from server failed, please try again or notify us at info@esteem.app `${intl.formatMessage({ id: 'alert.fetch_error' })} \n${err.message.substr(0, 20)}`,
\n${err.substr(0, 20)}`,
); );
}); });
}; };
@ -622,4 +608,4 @@ export default connect(
...bindActionCreators({ fetchGlobalProperties }, dispatch), ...bindActionCreators({ fetchGlobalProperties }, dispatch),
}, },
}), }),
)(ApplicationContainer); )(injectIntl(ApplicationContainer));