mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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
This commit is contained in:
committed by
Joram Wilander
parent
e52ab9737e
commit
0c701cc1d0
@@ -379,7 +379,7 @@ export function newLocalizationSelected(locale) {
|
||||
translations: en
|
||||
});
|
||||
} else {
|
||||
const localeInfo = I18n.getLanguageInfo(locale) || I18n.getLanguageInfo(global.window.mm_config.DefaultClientLocale);
|
||||
const localeInfo = I18n.getLanguageInfo(locale);
|
||||
|
||||
Client.getTranslations(
|
||||
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() {
|
||||
const defaultLocale = global.window.mm_config.DefaultClientLocale;
|
||||
let locale = global.window.mm_user ? global.window.mm_user.locale || defaultLocale : defaultLocale;
|
||||
let locale = global.window.mm_config.DefaultClientLocale;
|
||||
|
||||
if (!I18n.getLanguageInfo(locale)) {
|
||||
locale = 'en';
|
||||
}
|
||||
|
||||
return newLocalizationSelected(locale);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import UserStore from 'stores/user_store.jsx';
|
||||
import ChannelStore from 'stores/channel_store.jsx';
|
||||
|
||||
import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx';
|
||||
import {loadCurrentLocale} from 'actions/global_actions.jsx';
|
||||
import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
|
||||
|
||||
import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx';
|
||||
@@ -51,6 +52,8 @@ import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/te
|
||||
export function loadMe(callback) {
|
||||
loadMeRedux()(dispatch, getState).then(
|
||||
() => {
|
||||
loadCurrentLocale();
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ export default class LoginController extends React.Component {
|
||||
|
||||
finishSignin(team) {
|
||||
const query = this.props.location.query;
|
||||
GlobalActions.loadDefaultLocale();
|
||||
GlobalActions.loadCurrentLocale();
|
||||
if (query.redirect_to) {
|
||||
browserHistory.push(query.redirect_to);
|
||||
} else if (team) {
|
||||
|
||||
@@ -20,8 +20,8 @@ export default class Root extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
locale: 'en',
|
||||
translations: null
|
||||
locale: LocalizationStore.getLocale(),
|
||||
translations: LocalizationStore.getTranslations()
|
||||
};
|
||||
|
||||
this.localizationChanged = this.localizationChanged.bind(this);
|
||||
@@ -113,7 +113,7 @@ export default class Root extends React.Component {
|
||||
LocalizationStore.addChangeListener(this.localizationChanged);
|
||||
|
||||
// Get our localizaiton
|
||||
GlobalActions.loadDefaultLocale();
|
||||
GlobalActions.loadCurrentLocale();
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
@@ -33,12 +33,10 @@ export default class ManageLanguage extends React.Component {
|
||||
changeLanguage(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var user = this.props.user;
|
||||
var locale = this.state.locale;
|
||||
|
||||
user.locale = locale;
|
||||
|
||||
this.submitUser(user);
|
||||
this.submitUser({
|
||||
...this.props.user,
|
||||
locale: this.state.locale
|
||||
});
|
||||
}
|
||||
submitUser(user) {
|
||||
updateUser(user, Constants.UserUpdateEvents.LANGUAGE,
|
||||
|
||||
@@ -133,14 +133,11 @@ export function getLanguages() {
|
||||
}
|
||||
|
||||
export function getLanguageInfo(locale) {
|
||||
if (!availableLanguages) {
|
||||
setAvailableLanguages();
|
||||
}
|
||||
return availableLanguages[locale];
|
||||
return getAllLanguages()[locale];
|
||||
}
|
||||
|
||||
export function isLanguageAvailable(locale) {
|
||||
return Boolean(availableLanguages[locale]);
|
||||
return Boolean(getLanguages()[locale]);
|
||||
}
|
||||
|
||||
export function safariFix(callback) {
|
||||
|
||||
@@ -12,7 +12,7 @@ class LocalizationStoreClass extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.currentLocale = 'en';
|
||||
this.currentLocale = '';
|
||||
this.currentTranslations = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user