[FIX] Moment locales (#1066)
This commit is contained in:
parent
aac6da34af
commit
805be06c4a
|
@ -2,12 +2,15 @@ import {
|
||||||
put, call, takeLatest, select, take, fork, cancel
|
put, call, takeLatest, select, take, fork, cancel
|
||||||
} from 'redux-saga/effects';
|
} from 'redux-saga/effects';
|
||||||
import RNUserDefaults from 'rn-user-defaults';
|
import RNUserDefaults from 'rn-user-defaults';
|
||||||
|
import moment from 'moment';
|
||||||
|
import 'moment/min/locales';
|
||||||
|
|
||||||
import * as types from '../actions/actionsTypes';
|
import * as types from '../actions/actionsTypes';
|
||||||
import { appStart } from '../actions';
|
import { appStart } from '../actions';
|
||||||
import { serverFinishAdd, selectServerRequest } from '../actions/server';
|
import { serverFinishAdd, selectServerRequest } from '../actions/server';
|
||||||
import { loginFailure, loginSuccess, setUser } from '../actions/login';
|
import { loginFailure, loginSuccess, setUser } from '../actions/login';
|
||||||
import { roomsRequest } from '../actions/rooms';
|
import { roomsRequest } from '../actions/rooms';
|
||||||
|
import { toMomentLocale } from '../utils/moment';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import log from '../utils/log';
|
import log from '../utils/log';
|
||||||
import I18n from '../i18n';
|
import I18n from '../i18n';
|
||||||
|
@ -72,6 +75,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
||||||
yield fork(fetchUserPresence);
|
yield fork(fetchUserPresence);
|
||||||
|
|
||||||
I18n.locale = user.language;
|
I18n.locale = user.language;
|
||||||
|
moment.locale(toMomentLocale(user.language));
|
||||||
|
|
||||||
const { serversDB } = database.databases;
|
const { serversDB } = database.databases;
|
||||||
serversDB.write(() => {
|
serversDB.write(() => {
|
||||||
|
@ -132,6 +136,7 @@ const handleLogout = function* handleLogout() {
|
||||||
const handleSetUser = function handleSetUser({ user }) {
|
const handleSetUser = function handleSetUser({ user }) {
|
||||||
if (user && user.language) {
|
if (user && user.language) {
|
||||||
I18n.locale = user.language;
|
I18n.locale = user.language;
|
||||||
|
moment.locale(toMomentLocale(user.language));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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];
|
|
@ -7,8 +7,6 @@ import { connect } from 'react-redux';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
import { SafeAreaView } from 'react-navigation';
|
import { SafeAreaView } from 'react-navigation';
|
||||||
import Orientation from 'react-native-orientation-locker';
|
import Orientation from 'react-native-orientation-locker';
|
||||||
import moment from 'moment';
|
|
||||||
import 'moment/min/locales';
|
|
||||||
|
|
||||||
import database, { safeAddListener } from '../../lib/realm';
|
import database, { safeAddListener } from '../../lib/realm';
|
||||||
import RocketChat from '../../lib/rocketchat';
|
import RocketChat from '../../lib/rocketchat';
|
||||||
|
@ -56,8 +54,7 @@ const keyExtractor = item => item.rid;
|
||||||
showUnread: state.sortPreferences.showUnread,
|
showUnread: state.sortPreferences.showUnread,
|
||||||
useRealName: state.settings.UI_Use_Real_Name,
|
useRealName: state.settings.UI_Use_Real_Name,
|
||||||
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
||||||
StoreLastMessage: state.settings.Store_Last_Message,
|
StoreLastMessage: state.settings.Store_Last_Message
|
||||||
userLanguage: state.login.user && state.login.user.language
|
|
||||||
}), dispatch => ({
|
}), dispatch => ({
|
||||||
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
toggleSortDropdown: () => dispatch(toggleSortDropdownAction()),
|
||||||
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
openSearchHeader: () => dispatch(openSearchHeaderAction()),
|
||||||
|
@ -120,8 +117,7 @@ export default class RoomsListView extends React.Component {
|
||||||
closeSearchHeader: PropTypes.func,
|
closeSearchHeader: PropTypes.func,
|
||||||
appStart: PropTypes.func,
|
appStart: PropTypes.func,
|
||||||
roomsRequest: PropTypes.func,
|
roomsRequest: PropTypes.func,
|
||||||
isAuthenticated: PropTypes.bool,
|
isAuthenticated: PropTypes.bool
|
||||||
userLanguage: PropTypes.string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -152,8 +148,7 @@ export default class RoomsListView extends React.Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.getSubscriptions();
|
this.getSubscriptions();
|
||||||
const { navigation, userLanguage } = this.props;
|
const { navigation } = this.props;
|
||||||
moment.locale(userLanguage);
|
|
||||||
navigation.setParams({
|
navigation.setParams({
|
||||||
onPressItem: this._onPressItem,
|
onPressItem: this._onPressItem,
|
||||||
initSearchingAndroid: this.initSearchingAndroid,
|
initSearchingAndroid: this.initSearchingAndroid,
|
||||||
|
|
Loading…
Reference in New Issue