PLT-6518 Fixed user's locale not being loaded with redux actions (#6359)
* Stopped ManageLanguages component from mutating user * Removed obsolete reference to mm_user * PLT-6518 Fixed user's locale not being loaded with redux actions
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
e52ab9737e
Коммит
0c701cc1d0
@@ -379,7 +379,7 @@ export function newLocalizationSelected(locale) {
|
|||||||
translations: en
|
translations: en
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const localeInfo = I18n.getLanguageInfo(locale) || I18n.getLanguageInfo(global.window.mm_config.DefaultClientLocale);
|
const localeInfo = I18n.getLanguageInfo(locale);
|
||||||
|
|
||||||
Client.getTranslations(
|
Client.getTranslations(
|
||||||
localeInfo.url,
|
localeInfo.url,
|
||||||
@@ -401,13 +401,23 @@ export function newLocalizationSelected(locale) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function loadCurrentLocale() {
|
||||||
|
const user = UserStore.getCurrentUser();
|
||||||
|
|
||||||
|
if (user && user.locale) {
|
||||||
|
newLocalizationSelected(user.locale);
|
||||||
|
} else {
|
||||||
|
loadDefaultLocale();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function loadDefaultLocale() {
|
export function loadDefaultLocale() {
|
||||||
const defaultLocale = global.window.mm_config.DefaultClientLocale;
|
let locale = global.window.mm_config.DefaultClientLocale;
|
||||||
let locale = global.window.mm_user ? global.window.mm_user.locale || defaultLocale : defaultLocale;
|
|
||||||
|
|
||||||
if (!I18n.getLanguageInfo(locale)) {
|
if (!I18n.getLanguageInfo(locale)) {
|
||||||
locale = 'en';
|
locale = 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
return newLocalizationSelected(locale);
|
return newLocalizationSelected(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import UserStore from 'stores/user_store.jsx';
|
|||||||
import ChannelStore from 'stores/channel_store.jsx';
|
import ChannelStore from 'stores/channel_store.jsx';
|
||||||
|
|
||||||
import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx';
|
import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx';
|
||||||
|
import {loadCurrentLocale} from 'actions/global_actions.jsx';
|
||||||
import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
|
import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
|
||||||
|
|
||||||
import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx';
|
import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx';
|
||||||
@@ -51,6 +52,8 @@ import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/te
|
|||||||
export function loadMe(callback) {
|
export function loadMe(callback) {
|
||||||
loadMeRedux()(dispatch, getState).then(
|
loadMeRedux()(dispatch, getState).then(
|
||||||
() => {
|
() => {
|
||||||
|
loadCurrentLocale();
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ export default class LoginController extends React.Component {
|
|||||||
|
|
||||||
finishSignin(team) {
|
finishSignin(team) {
|
||||||
const query = this.props.location.query;
|
const query = this.props.location.query;
|
||||||
GlobalActions.loadDefaultLocale();
|
GlobalActions.loadCurrentLocale();
|
||||||
if (query.redirect_to) {
|
if (query.redirect_to) {
|
||||||
browserHistory.push(query.redirect_to);
|
browserHistory.push(query.redirect_to);
|
||||||
} else if (team) {
|
} else if (team) {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ export default class Root extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
locale: 'en',
|
locale: LocalizationStore.getLocale(),
|
||||||
translations: null
|
translations: LocalizationStore.getTranslations()
|
||||||
};
|
};
|
||||||
|
|
||||||
this.localizationChanged = this.localizationChanged.bind(this);
|
this.localizationChanged = this.localizationChanged.bind(this);
|
||||||
@@ -113,7 +113,7 @@ export default class Root extends React.Component {
|
|||||||
LocalizationStore.addChangeListener(this.localizationChanged);
|
LocalizationStore.addChangeListener(this.localizationChanged);
|
||||||
|
|
||||||
// Get our localizaiton
|
// Get our localizaiton
|
||||||
GlobalActions.loadDefaultLocale();
|
GlobalActions.loadCurrentLocale();
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
|||||||
@@ -33,12 +33,10 @@ export default class ManageLanguage extends React.Component {
|
|||||||
changeLanguage(e) {
|
changeLanguage(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var user = this.props.user;
|
this.submitUser({
|
||||||
var locale = this.state.locale;
|
...this.props.user,
|
||||||
|
locale: this.state.locale
|
||||||
user.locale = locale;
|
});
|
||||||
|
|
||||||
this.submitUser(user);
|
|
||||||
}
|
}
|
||||||
submitUser(user) {
|
submitUser(user) {
|
||||||
updateUser(user, Constants.UserUpdateEvents.LANGUAGE,
|
updateUser(user, Constants.UserUpdateEvents.LANGUAGE,
|
||||||
|
|||||||
@@ -133,14 +133,11 @@ export function getLanguages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getLanguageInfo(locale) {
|
export function getLanguageInfo(locale) {
|
||||||
if (!availableLanguages) {
|
return getAllLanguages()[locale];
|
||||||
setAvailableLanguages();
|
|
||||||
}
|
|
||||||
return availableLanguages[locale];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isLanguageAvailable(locale) {
|
export function isLanguageAvailable(locale) {
|
||||||
return Boolean(availableLanguages[locale]);
|
return Boolean(getLanguages()[locale]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function safariFix(callback) {
|
export function safariFix(callback) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class LocalizationStoreClass extends EventEmitter {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.currentLocale = 'en';
|
this.currentLocale = '';
|
||||||
this.currentTranslations = null;
|
this.currentTranslations = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user