blob: 4f5eb223dca729c64c4d867f709411d5b1284463 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
import SettingItemMax from '../setting_item_max.jsx';
import * as I18n from 'i18n/i18n.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
import Constants from 'utils/constants.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import {updateUser} from 'actions/user_actions.jsx';
import React from 'react';
export default class ManageLanguage extends React.Component {
constructor(props) {
super(props);
this.setupInitialState = this.setupInitialState.bind(this);
this.setLanguage = this.setLanguage.bind(this);
this.changeLanguage = this.changeLanguage.bind(this);
this.submitUser = this.submitUser.bind(this);
this.state = this.setupInitialState(props);
}
setupInitialState(props) {
var user = props.user;
return {
locale: user.locale
};
}
setLanguage(e) {
this.setState({locale: e.target.value});
}
changeLanguage(e) {
e.preventDefault();
var user = this.props.user;
var locale = this.state.locale;
user.locale = locale;
this.submitUser(user);
}
submitUser(user) {
updateUser(user, Constants.UserUpdateEvents.LANGUAGE,
() => {
GlobalActions.newLocalizationSelected(user.locale);
},
(err) => {
let serverError;
if (err.message) {
serverError = err.message;
} else {
serverError = err;
}
this.setState({serverError});
}
);
}
render() {
let serverError;
if (this.state.serverError) {
serverError = <label className='has-error'>{this.state.serverError}</label>;
}
const options = [];
const locales = I18n.getLanguages();
const languages = Object.keys(locales).map((l) => {
return {
value: locales[l].value,
name: locales[l].name,
order: locales[l].order
};
}).
sort((a, b) => a.order - b.order);
languages.forEach((lang) => {
options.push(
<option
key={lang.value}
value={lang.value}
>
{lang.name}
</option>
);
});
const input = (
<div key='changeLanguage'>
<br/>
<label className='control-label'>
<FormattedMessage
id='user.settings.languages.change'
defaultMessage='Change interface language'
/>
</label>
<div className='padding-top'>
<select
ref='language'
className='form-control'
value={this.state.locale}
onChange={this.setLanguage}
>
{options}
</select>
{serverError}
</div>
<div>
<br/>
<FormattedHTMLMessage
id='user.settings.languages.promote'
defaultMessage='Select which language Mattermost displays in the user interface.<br /><br />Would like to help with translations? Join the <a href="http://translate.mattermost.com/" target="_blank">Mattermost Translation Server</a> to contribute.'
/>
</div>
</div>
);
return (
<SettingItemMax
title={
<FormattedMessage
id='user.settings.display.language'
defaultMessage='Language'
/>
}
width='medium'
submit={this.changeLanguage}
inputs={[input]}
updateSection={this.props.updateSection}
/>
);
}
}
ManageLanguage.propTypes = {
user: React.PropTypes.object.isRequired,
updateSection: React.PropTypes.func.isRequired
};
|