Skip to content

Commit

Permalink
PLT-6518 Fixed user's locale not being loaded with redux actions (mat…
Browse files Browse the repository at this point in the history
…termost#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
  • Loading branch information
hmhealey authored and jwilander committed May 9, 2017
1 parent 29d116b commit bbfc0f2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
16 changes: 13 additions & 3 deletions actions/global_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions actions/user_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,8 @@ import {getTeamMembersByIds, getMyTeamMembers} from 'mattermost-redux/actions/te
export function loadMe(callback) {
loadMeRedux()(dispatch, getState).then(
() => {
loadCurrentLocale();

if (callback) {
callback();
}
Expand Down
2 changes: 1 addition & 1 deletion components/login/login_controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions components/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -113,7 +113,7 @@ export default class Root extends React.Component {
LocalizationStore.addChangeListener(this.localizationChanged);

// Get our localizaiton
GlobalActions.loadDefaultLocale();
GlobalActions.loadCurrentLocale();
}

componentWillUnmount() {
Expand Down
10 changes: 4 additions & 6 deletions components/user_settings/manage_languages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions i18n/i18n.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion stores/localization_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LocalizationStoreClass extends EventEmitter {
constructor() {
super();

this.currentLocale = 'en';
this.currentLocale = '';
this.currentTranslations = null;
}

Expand Down

0 comments on commit bbfc0f2

Please sign in to comment.