// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. // See License.txt for license information. import SettingItemMax from '../setting_item_max.jsx'; import Client from 'client/web_client.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 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) { Client.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 = ; } 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( ); }); const input = (