[FIX] Moment locales (#1066)

This commit is contained in:
Djorkaeff Alexandre 2019-07-23 11:07:19 -03:00 committed by Diego Mello
parent aac6da34af
commit 805be06c4a
3 changed files with 19 additions and 8 deletions

View File

@ -2,12 +2,15 @@ import {
put, call, takeLatest, select, take, fork, cancel
} from 'redux-saga/effects';
import RNUserDefaults from 'rn-user-defaults';
import moment from 'moment';
import 'moment/min/locales';
import * as types from '../actions/actionsTypes';
import { appStart } from '../actions';
import { serverFinishAdd, selectServerRequest } from '../actions/server';
import { loginFailure, loginSuccess, setUser } from '../actions/login';
import { roomsRequest } from '../actions/rooms';
import { toMomentLocale } from '../utils/moment';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
import I18n from '../i18n';
@ -72,6 +75,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
yield fork(fetchUserPresence);
I18n.locale = user.language;
moment.locale(toMomentLocale(user.language));
const { serversDB } = database.databases;
serversDB.write(() => {
@ -132,6 +136,7 @@ const handleLogout = function* handleLogout() {
const handleSetUser = function handleSetUser({ user }) {
if (user && user.language) {
I18n.locale = user.language;
moment.locale(toMomentLocale(user.language));
}
};

11
app/utils/moment.js Normal file
View File

@ -0,0 +1,11 @@
const localeKeys = {
en: 'en',
ru: 'ru',
'pt-BR': 'pt-br',
'zh-CN': 'zh-cn',
fr: 'fr',
de: 'de',
'pt-PT': 'pt'
};
export const toMomentLocale = locale => localeKeys[locale];

View File

@ -7,8 +7,6 @@ import { connect } from 'react-redux';
import { isEqual } from 'lodash';
import { SafeAreaView } from 'react-navigation';
import Orientation from 'react-native-orientation-locker';
import moment from 'moment';
import 'moment/min/locales';
import database, { safeAddListener } from '../../lib/realm';
import RocketChat from '../../lib/rocketchat';
@ -56,8 +54,7 @@ const keyExtractor = item => item.rid;
showUnread: state.sortPreferences.showUnread,
useRealName: state.settings.UI_Use_Real_Name,
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
StoreLastMessage: state.settings.Store_Last_Message,
userLanguage: state.login.user && state.login.user.language
StoreLastMessage: state.settings.Store_Last_Message
}), dispatch => ({
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
openSearchHeader: () => dispatch(openSearchHeaderAction()),
@ -120,8 +117,7 @@ export default class RoomsListView extends React.Component {
closeSearchHeader: PropTypes.func,
appStart: PropTypes.func,
roomsRequest: PropTypes.func,
isAuthenticated: PropTypes.bool,
userLanguage: PropTypes.string
isAuthenticated: PropTypes.bool
}
constructor(props) {
@ -152,8 +148,7 @@ export default class RoomsListView extends React.Component {
componentDidMount() {
this.getSubscriptions();
const { navigation, userLanguage } = this.props;
moment.locale(userLanguage);
const { navigation } = this.props;
navigation.setParams({
onPressItem: this._onPressItem,
initSearchingAndroid: this.initSearchingAndroid,