PLT-1800 Load server side locale from the config.json (#3092)
* PLT-1800 Load server side locale from the config.json * Add support for locales with country specifics * Fix localization on served locale file as plain/text
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
15e427e806
Коммит
a2c183f401
@@ -30,7 +30,7 @@ type TestHelper struct {
|
|||||||
func SetupEnterprise() *TestHelper {
|
func SetupEnterprise() *TestHelper {
|
||||||
if Srv == nil {
|
if Srv == nil {
|
||||||
utils.LoadConfig("config.json")
|
utils.LoadConfig("config.json")
|
||||||
utils.InitTranslations()
|
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||||
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
utils.License.Features.SetDefaults()
|
utils.License.Features.SetDefaults()
|
||||||
@@ -50,7 +50,7 @@ func SetupEnterprise() *TestHelper {
|
|||||||
func Setup() *TestHelper {
|
func Setup() *TestHelper {
|
||||||
if Srv == nil {
|
if Srv == nil {
|
||||||
utils.LoadConfig("config.json")
|
utils.LoadConfig("config.json")
|
||||||
utils.InitTranslations()
|
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||||
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||||
utils.DisableDebugLogForTest()
|
utils.DisableDebugLogForTest()
|
||||||
NewServer()
|
NewServer()
|
||||||
|
|||||||
@@ -239,6 +239,7 @@ func CreateUser(user *model.User) (*model.User, *model.AppError) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.MakeNonNil()
|
user.MakeNonNil()
|
||||||
|
user.Locale = *utils.Cfg.LocalizationSettings.DefaultClientLocale
|
||||||
|
|
||||||
if result := <-Srv.Store.User().Save(user); result.Err != nil {
|
if result := <-Srv.Store.User().Save(user); result.Err != nil {
|
||||||
l4g.Error(utils.T("api.user.create_user.save.error"), result.Err)
|
l4g.Error(utils.T("api.user.create_user.save.error"), result.Err)
|
||||||
|
|||||||
@@ -155,5 +155,10 @@
|
|||||||
"Enable": false,
|
"Enable": false,
|
||||||
"Directory": "./data/",
|
"Directory": "./data/",
|
||||||
"EnableDaily": false
|
"EnableDaily": false
|
||||||
|
},
|
||||||
|
"LocalizationSettings": {
|
||||||
|
"DefaultServerLocale": "en",
|
||||||
|
"DefaultClientLocale": "en",
|
||||||
|
"AvailableLocales": "en,es,fr,ja,pt-BR"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,6 @@ func main() {
|
|||||||
|
|
||||||
parseCmds()
|
parseCmds()
|
||||||
|
|
||||||
utils.InitTranslations()
|
|
||||||
if errstr := doLoadConfig(flagConfigFile); errstr != "" {
|
if errstr := doLoadConfig(flagConfigFile); errstr != "" {
|
||||||
l4g.Exit(utils.T("mattermost.unable_to_load_config"), errstr)
|
l4g.Exit(utils.T("mattermost.unable_to_load_config"), errstr)
|
||||||
return
|
return
|
||||||
@@ -87,6 +86,7 @@ func main() {
|
|||||||
if flagRunCmds {
|
if flagRunCmds {
|
||||||
utils.ConfigureCmdLineLog()
|
utils.ConfigureCmdLineLog()
|
||||||
}
|
}
|
||||||
|
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||||
|
|
||||||
pwd, _ := os.Getwd()
|
pwd, _ := os.Getwd()
|
||||||
l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise)
|
l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash, model.BuildHashEnterprise)
|
||||||
|
|||||||
@@ -204,20 +204,27 @@ type ComplianceSettings struct {
|
|||||||
EnableDaily *bool
|
EnableDaily *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LocalizationSettings struct {
|
||||||
|
DefaultServerLocale *string
|
||||||
|
DefaultClientLocale *string
|
||||||
|
AvailableLocales *string
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
ServiceSettings ServiceSettings
|
ServiceSettings ServiceSettings
|
||||||
TeamSettings TeamSettings
|
TeamSettings TeamSettings
|
||||||
SqlSettings SqlSettings
|
SqlSettings SqlSettings
|
||||||
LogSettings LogSettings
|
LogSettings LogSettings
|
||||||
FileSettings FileSettings
|
FileSettings FileSettings
|
||||||
EmailSettings EmailSettings
|
EmailSettings EmailSettings
|
||||||
RateLimitSettings RateLimitSettings
|
RateLimitSettings RateLimitSettings
|
||||||
PrivacySettings PrivacySettings
|
PrivacySettings PrivacySettings
|
||||||
SupportSettings SupportSettings
|
SupportSettings SupportSettings
|
||||||
GitLabSettings SSOSettings
|
GitLabSettings SSOSettings
|
||||||
GoogleSettings SSOSettings
|
GoogleSettings SSOSettings
|
||||||
LdapSettings LdapSettings
|
LdapSettings LdapSettings
|
||||||
ComplianceSettings ComplianceSettings
|
ComplianceSettings ComplianceSettings
|
||||||
|
LocalizationSettings LocalizationSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) ToJson() string {
|
func (o *Config) ToJson() string {
|
||||||
@@ -513,6 +520,21 @@ func (o *Config) SetDefaults() {
|
|||||||
o.LdapSettings.NicknameAttribute = new(string)
|
o.LdapSettings.NicknameAttribute = new(string)
|
||||||
*o.LdapSettings.NicknameAttribute = ""
|
*o.LdapSettings.NicknameAttribute = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if o.LocalizationSettings.DefaultServerLocale == nil {
|
||||||
|
o.LocalizationSettings.DefaultServerLocale = new(string)
|
||||||
|
*o.LocalizationSettings.DefaultServerLocale = DEFAULT_LOCALE
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.LocalizationSettings.DefaultClientLocale == nil {
|
||||||
|
o.LocalizationSettings.DefaultClientLocale = new(string)
|
||||||
|
*o.LocalizationSettings.DefaultClientLocale = DEFAULT_LOCALE
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.LocalizationSettings.AvailableLocales == nil {
|
||||||
|
o.LocalizationSettings.AvailableLocales = new(string)
|
||||||
|
*o.LocalizationSettings.AvailableLocales = *o.LocalizationSettings.DefaultClientLocale
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) IsValid() *AppError {
|
func (o *Config) IsValid() *AppError {
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ func (u *User) PreSave() {
|
|||||||
|
|
||||||
u.Username = strings.ToLower(u.Username)
|
u.Username = strings.ToLower(u.Username)
|
||||||
u.Email = strings.ToLower(u.Email)
|
u.Email = strings.ToLower(u.Email)
|
||||||
u.Locale = strings.ToLower(u.Locale)
|
|
||||||
|
|
||||||
u.CreateAt = GetMillis()
|
u.CreateAt = GetMillis()
|
||||||
u.UpdateAt = u.CreateAt
|
u.UpdateAt = u.CreateAt
|
||||||
@@ -166,7 +165,6 @@ func (u *User) PreSave() {
|
|||||||
func (u *User) PreUpdate() {
|
func (u *User) PreUpdate() {
|
||||||
u.Username = strings.ToLower(u.Username)
|
u.Username = strings.ToLower(u.Username)
|
||||||
u.Email = strings.ToLower(u.Email)
|
u.Email = strings.ToLower(u.Email)
|
||||||
u.Locale = strings.ToLower(u.Locale)
|
|
||||||
u.UpdateAt = GetMillis()
|
u.UpdateAt = GetMillis()
|
||||||
|
|
||||||
if u.AuthData != nil && *u.AuthData == "" {
|
if u.AuthData != nil && *u.AuthData == "" {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ var store Store
|
|||||||
func Setup() {
|
func Setup() {
|
||||||
if store == nil {
|
if store == nil {
|
||||||
utils.LoadConfig("config.json")
|
utils.LoadConfig("config.json")
|
||||||
utils.InitTranslations()
|
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||||
store = NewSqlStore()
|
store = NewSqlStore()
|
||||||
|
|
||||||
store.MarkSystemRanUnitTests()
|
store.MarkSystemRanUnitTests()
|
||||||
|
|||||||
@@ -246,7 +246,8 @@ func getClientConfig(c *model.Config) map[string]string {
|
|||||||
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
|
||||||
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
|
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
|
||||||
|
|
||||||
props["AllowCorsFrom"] = *c.ServiceSettings.AllowCorsFrom
|
props["DefaultClientLocale"] = *c.LocalizationSettings.DefaultClientLocale
|
||||||
|
props["AvailableLocales"] = *c.LocalizationSettings.AvailableLocales
|
||||||
|
|
||||||
if IsLicensed {
|
if IsLicensed {
|
||||||
if *License.Features.CustomBrand {
|
if *License.Features.CustomBrand {
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ import (
|
|||||||
|
|
||||||
func TestConfig(t *testing.T) {
|
func TestConfig(t *testing.T) {
|
||||||
LoadConfig("config.json")
|
LoadConfig("config.json")
|
||||||
InitTranslations()
|
InitTranslations(Cfg.LocalizationSettings)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/cloudfoundry/jibber_jabber"
|
//"github.com/cloudfoundry/jibber_jabber"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/nicksnyder/go-i18n/i18n"
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
var T i18n.TranslateFunc
|
var T i18n.TranslateFunc
|
||||||
var locales map[string]string = make(map[string]string)
|
var locales map[string]string = make(map[string]string)
|
||||||
|
var settings model.LocalizationSettings
|
||||||
|
|
||||||
func InitTranslations() {
|
func InitTranslations(localizationSettings model.LocalizationSettings) {
|
||||||
|
settings = localizationSettings
|
||||||
InitTranslationsWithDir("i18n")
|
InitTranslationsWithDir("i18n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,14 +36,10 @@ func InitTranslationsWithDir(dir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTranslationsBySystemLocale() i18n.TranslateFunc {
|
func GetTranslationsBySystemLocale() i18n.TranslateFunc {
|
||||||
locale := model.DEFAULT_LOCALE
|
locale := *settings.DefaultServerLocale
|
||||||
if userLanguage, err := jibber_jabber.DetectLanguage(); err == nil {
|
if _, ok := locales[locale]; !ok {
|
||||||
if _, ok := locales[userLanguage]; ok {
|
l4g.Error("Failed to load system translations for '%v' attempting to fall back to '%v'", locale, model.DEFAULT_LOCALE)
|
||||||
locale = userLanguage
|
locale = model.DEFAULT_LOCALE
|
||||||
} else {
|
|
||||||
l4g.Error("Failed to load system translations for '%v' attempting to fall back to '%v'", locale, model.DEFAULT_LOCALE)
|
|
||||||
locale = model.DEFAULT_LOCALE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if locales[locale] == "" {
|
if locales[locale] == "" {
|
||||||
@@ -72,10 +70,20 @@ func SetTranslations(locale string) i18n.TranslateFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
|
func GetTranslationsAndLocale(w http.ResponseWriter, r *http.Request) (i18n.TranslateFunc, string) {
|
||||||
|
// This is for checking against locales like pt_BR or zn_CN
|
||||||
|
headerLocaleFull := strings.Split(r.Header.Get("Accept-Language"), ",")[0]
|
||||||
|
// This is for checking agains locales like en, es
|
||||||
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
|
headerLocale := strings.Split(strings.Split(r.Header.Get("Accept-Language"), ",")[0], "-")[0]
|
||||||
if locales[headerLocale] != "" {
|
defaultLocale := *settings.DefaultClientLocale
|
||||||
|
if locales[headerLocaleFull] != "" {
|
||||||
|
translations := TfuncWithFallback(headerLocaleFull)
|
||||||
|
return translations, headerLocaleFull
|
||||||
|
} else if locales[headerLocale] != "" {
|
||||||
translations := TfuncWithFallback(headerLocale)
|
translations := TfuncWithFallback(headerLocale)
|
||||||
return translations, headerLocale
|
return translations, headerLocale
|
||||||
|
} else if locales[defaultLocale] != "" {
|
||||||
|
translations := TfuncWithFallback(defaultLocale)
|
||||||
|
return translations, headerLocale
|
||||||
}
|
}
|
||||||
|
|
||||||
translations := TfuncWithFallback(model.DEFAULT_LOCALE)
|
translations := TfuncWithFallback(model.DEFAULT_LOCALE)
|
||||||
@@ -89,7 +97,7 @@ func TfuncWithFallback(pref string) i18n.TranslateFunc {
|
|||||||
return translated
|
return translated
|
||||||
}
|
}
|
||||||
|
|
||||||
t, _ := i18n.Tfunc("en")
|
t, _ := i18n.Tfunc(model.DEFAULT_LOCALE)
|
||||||
return t(translationID, args...)
|
return t(translationID, args...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var URL string
|
|||||||
func Setup() {
|
func Setup() {
|
||||||
if api.Srv == nil {
|
if api.Srv == nil {
|
||||||
utils.LoadConfig("config.json")
|
utils.LoadConfig("config.json")
|
||||||
utils.InitTranslations()
|
utils.InitTranslations(utils.Cfg.LocalizationSettings)
|
||||||
api.NewServer()
|
api.NewServer()
|
||||||
api.StartServer()
|
api.StartServer()
|
||||||
api.InitApi()
|
api.InitApi()
|
||||||
|
|||||||
@@ -392,9 +392,14 @@ export function newLocalizationSelected(locale) {
|
|||||||
translations: en
|
translations: en
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const localeInfo = I18n.getLanguageInfo(locale) || I18n.getLanguageInfo(global.window.mm_config.DefaultClientLocale);
|
||||||
|
|
||||||
Client.getTranslations(
|
Client.getTranslations(
|
||||||
I18n.getLanguageInfo(locale).url,
|
localeInfo.url,
|
||||||
(data) => {
|
(data, res) => {
|
||||||
|
if (!data && res.text) {
|
||||||
|
data = JSON.parse(res.text); //eslint-disable-line no-param-reassign
|
||||||
|
}
|
||||||
AppDispatcher.handleServerAction({
|
AppDispatcher.handleServerAction({
|
||||||
type: ActionTypes.RECEIVED_LOCALE,
|
type: ActionTypes.RECEIVED_LOCALE,
|
||||||
locale,
|
locale,
|
||||||
@@ -408,10 +413,11 @@ export function newLocalizationSelected(locale) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadBrowserLocale() {
|
export function loadDefaultLocale() {
|
||||||
let locale = (navigator.languages && navigator.languages.length > 0 ? navigator.languages[0] :
|
const defaultLocale = global.window.mm_config.DefaultClientLocale;
|
||||||
(navigator.language || navigator.userLanguage)).split('-')[0];
|
let locale = global.window.mm_user ? global.window.mm_user.locale || defaultLocale : defaultLocale;
|
||||||
if (!I18n.getLanguages()[locale]) {
|
|
||||||
|
if (!I18n.getLanguageInfo(locale)) {
|
||||||
locale = 'en';
|
locale = 'en';
|
||||||
}
|
}
|
||||||
return newLocalizationSelected(locale);
|
return newLocalizationSelected(locale);
|
||||||
|
|||||||
@@ -292,6 +292,15 @@ export default class AdminSidebar extends React.Component {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<AdminSidebarSection
|
||||||
|
name='localization'
|
||||||
|
title={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.sidebar.localization'
|
||||||
|
defaultMessage='Localization'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<AdminSidebarSection
|
<AdminSidebarSection
|
||||||
name='users_and_teams'
|
name='users_and_teams'
|
||||||
title={
|
title={
|
||||||
|
|||||||
145
webapp/components/admin_console/localization_settings.jsx
Обычный файл
145
webapp/components/admin_console/localization_settings.jsx
Обычный файл
@@ -0,0 +1,145 @@
|
|||||||
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import * as I18n from 'i18n/i18n.jsx';
|
||||||
|
|
||||||
|
import AdminSettings from './admin_settings.jsx';
|
||||||
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
import SettingsGroup from './settings_group.jsx';
|
||||||
|
import DropdownSetting from './dropdown_setting.jsx';
|
||||||
|
import MultiSelectSetting from './multiselect_settings.jsx';
|
||||||
|
|
||||||
|
export default class LocalizationSettings extends AdminSettings {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.getConfigFromState = this.getConfigFromState.bind(this);
|
||||||
|
|
||||||
|
this.renderSettings = this.renderSettings.bind(this);
|
||||||
|
this.canSave = this.canSave.bind(this);
|
||||||
|
|
||||||
|
const locales = I18n.getAllLanguages();
|
||||||
|
|
||||||
|
this.state = Object.assign(this.state, {
|
||||||
|
hasErrors: false,
|
||||||
|
defaultServerLocale: props.config.LocalizationSettings.DefaultServerLocale,
|
||||||
|
defaultClientLocale: props.config.LocalizationSettings.DefaultClientLocale,
|
||||||
|
availableLocales: props.config.LocalizationSettings.AvailableLocales.split(','),
|
||||||
|
languages: Object.keys(locales).map((l) => {
|
||||||
|
return {value: locales[l].value, text: locales[l].name};
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
canSave() {
|
||||||
|
return this.state.availableLocales.join(',').indexOf(this.state.defaultClientLocale) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
getConfigFromState(config) {
|
||||||
|
config.LocalizationSettings.DefaultServerLocale = this.state.defaultServerLocale;
|
||||||
|
config.LocalizationSettings.DefaultClientLocale = this.state.defaultClientLocale;
|
||||||
|
config.LocalizationSettings.AvailableLocales = this.state.availableLocales.join(',');
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTitle() {
|
||||||
|
return (
|
||||||
|
<h3>
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.title'
|
||||||
|
defaultMessage='General Settings'
|
||||||
|
/>
|
||||||
|
</h3>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderSettings() {
|
||||||
|
return (
|
||||||
|
<SettingsGroup
|
||||||
|
header={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization'
|
||||||
|
defaultMessage='Localization'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DropdownSetting
|
||||||
|
id='defaultServerLocale'
|
||||||
|
values={this.state.languages}
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.serverLocaleTitle'
|
||||||
|
defaultMessage='Default Server Language:'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
value={this.state.defaultServerLocale}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
helpText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.serverLocaleDescription'
|
||||||
|
defaultMessage='This setting sets the default language for the system messages and logs. (NEED SERVER RESTART)'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<DropdownSetting
|
||||||
|
id='defaultClientLocale'
|
||||||
|
values={this.state.languages}
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.clientLocaleTitle'
|
||||||
|
defaultMessage='Default Client Language:'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
value={this.state.defaultClientLocale}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
helpText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.clientLocaleDescription'
|
||||||
|
defaultMessage="This setting sets the Default language for newly created users and for pages where the user hasn't loggged in."
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<MultiSelectSetting
|
||||||
|
id='availableLocales'
|
||||||
|
values={this.state.languages}
|
||||||
|
label={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.availableLocalesTitle'
|
||||||
|
defaultMessage='Available Languages:'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
selected={this.state.availableLocales}
|
||||||
|
mustBePresent={this.state.defaultClientLocale}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
helpText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.availableLocalesDescription'
|
||||||
|
defaultMessage='This setting determines the available languages that a user can set using the Account Settings.'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
noResultText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.availableLocalesNoResults'
|
||||||
|
defaultMessage='No results found'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
errorText={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.availableLocalesError'
|
||||||
|
defaultMessage='There has to be at least one language available'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
notPresent={
|
||||||
|
<FormattedMessage
|
||||||
|
id='admin.general.localization.availableLocalesNotPresent'
|
||||||
|
defaultMessage='The default client language must be included in the available list'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SettingsGroup>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
80
webapp/components/admin_console/multiselect_settings.jsx
Обычный файл
80
webapp/components/admin_console/multiselect_settings.jsx
Обычный файл
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
import React from 'react';
|
||||||
|
import ReactSelect from 'react-select';
|
||||||
|
|
||||||
|
import Setting from './setting.jsx';
|
||||||
|
import FormError from 'components/form_error.jsx';
|
||||||
|
|
||||||
|
export default class MultiSelectSetting extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.handleChange = this.handleChange.bind(this);
|
||||||
|
this.state = {error: false};
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChange(newValue) {
|
||||||
|
const values = newValue.map((n) => {
|
||||||
|
return n.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!newValue || newValue.length === 0) {
|
||||||
|
this.setState({error: this.props.errorText});
|
||||||
|
} else if (this.props.mustBePresent && values.join(',').indexOf(this.props.mustBePresent) === -1) {
|
||||||
|
this.setState({error: this.props.notPresent});
|
||||||
|
} else {
|
||||||
|
this.props.onChange(this.props.id, values);
|
||||||
|
this.setState({error: false});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(newProps) {
|
||||||
|
if (newProps.mustBePresent && newProps.selected.join(',').indexOf(newProps.mustBePresent) === -1) {
|
||||||
|
this.setState({error: this.props.notPresent});
|
||||||
|
} else {
|
||||||
|
this.setState({error: false});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Setting
|
||||||
|
label={this.props.label}
|
||||||
|
inputId={this.props.id}
|
||||||
|
helpText={this.props.helpText}
|
||||||
|
>
|
||||||
|
<ReactSelect
|
||||||
|
id={this.props.id}
|
||||||
|
multi={true}
|
||||||
|
labelKey='text'
|
||||||
|
options={this.props.values}
|
||||||
|
joinValues={true}
|
||||||
|
disabled={this.props.disabled}
|
||||||
|
noResultsText={this.props.noResultText}
|
||||||
|
onChange={this.handleChange}
|
||||||
|
value={this.props.selected}
|
||||||
|
/>
|
||||||
|
<FormError error={this.state.error}/>
|
||||||
|
</Setting>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiSelectSetting.defaultProps = {
|
||||||
|
disabled: false
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiSelectSetting.propTypes = {
|
||||||
|
id: React.PropTypes.string.isRequired,
|
||||||
|
values: React.PropTypes.array.isRequired,
|
||||||
|
label: React.PropTypes.node.isRequired,
|
||||||
|
selected: React.PropTypes.array.isRequired,
|
||||||
|
mustBePresent: React.PropTypes.string,
|
||||||
|
onChange: React.PropTypes.func.isRequired,
|
||||||
|
disabled: React.PropTypes.bool,
|
||||||
|
helpText: React.PropTypes.node,
|
||||||
|
noResultText: React.PropTypes.node,
|
||||||
|
errorText: React.PropTypes.node,
|
||||||
|
notPresent: React.PropTypes.node
|
||||||
|
};
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
import LocalizationStore from 'stores/localization_store.jsx';
|
import LocalizationStore from 'stores/localization_store.jsx';
|
||||||
|
import Client from 'utils/web_client.jsx';
|
||||||
|
|
||||||
import {IntlProvider} from 'react-intl';
|
import {IntlProvider} from 'react-intl';
|
||||||
|
|
||||||
@@ -26,9 +27,25 @@ export default class Root extends React.Component {
|
|||||||
|
|
||||||
this.localizationChanged = this.localizationChanged.bind(this);
|
this.localizationChanged = this.localizationChanged.bind(this);
|
||||||
this.redirectIfNecessary = this.redirectIfNecessary.bind(this);
|
this.redirectIfNecessary = this.redirectIfNecessary.bind(this);
|
||||||
|
|
||||||
|
// Ya....
|
||||||
|
/*eslint-disable */
|
||||||
|
if (window.mm_config.SegmentDeveloperKey != null && window.mm_config.SegmentDeveloperKey !== "") {
|
||||||
|
!function(){var analytics=global.window.analytics=global.window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.1";
|
||||||
|
analytics.load(window.mm_config.SegmentDeveloperKey);
|
||||||
|
analytics.page();
|
||||||
|
}}();
|
||||||
|
}
|
||||||
|
/*eslint-enable */
|
||||||
|
|
||||||
|
// Fastclick
|
||||||
|
FastClick.attach(document.body);
|
||||||
}
|
}
|
||||||
localizationChanged() {
|
localizationChanged() {
|
||||||
this.setState({locale: LocalizationStore.getLocale(), translations: LocalizationStore.getTranslations()});
|
const locale = LocalizationStore.getLocale();
|
||||||
|
|
||||||
|
Client.setAcceptLanguage(locale);
|
||||||
|
this.setState({locale, translations: LocalizationStore.getTranslations()});
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectIfNecessary(props) {
|
redirectIfNecessary(props) {
|
||||||
@@ -46,27 +63,15 @@ export default class Root extends React.Component {
|
|||||||
this.redirectIfNecessary(newProps);
|
this.redirectIfNecessary(newProps);
|
||||||
}
|
}
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
|
// Redirect if Necessary
|
||||||
|
this.redirectIfNecessary(this.props);
|
||||||
|
}
|
||||||
|
componentDidMount() {
|
||||||
// Setup localization listener
|
// Setup localization listener
|
||||||
LocalizationStore.addChangeListener(this.localizationChanged);
|
LocalizationStore.addChangeListener(this.localizationChanged);
|
||||||
|
|
||||||
// Ya....
|
|
||||||
/*eslint-disable */
|
|
||||||
if (window.mm_config.SegmentDeveloperKey != null && window.mm_config.SegmentDeveloperKey !== "") {
|
|
||||||
!function(){var analytics=global.window.analytics=global.window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.1";
|
|
||||||
analytics.load(window.mm_config.SegmentDeveloperKey);
|
|
||||||
analytics.page();
|
|
||||||
}}();
|
|
||||||
}
|
|
||||||
/*eslint-enable */
|
|
||||||
|
|
||||||
// Fastclick
|
|
||||||
FastClick.attach(document.body);
|
|
||||||
|
|
||||||
// Get our localizaiton
|
// Get our localizaiton
|
||||||
GlobalActions.loadBrowserLocale();
|
GlobalActions.loadBrowserLocale();
|
||||||
|
|
||||||
// Redirect if Necessary
|
|
||||||
this.redirectIfNecessary(this.props);
|
|
||||||
}
|
}
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
LocalizationStore.removeChangeListener(this.localizationChanged);
|
LocalizationStore.removeChangeListener(this.localizationChanged);
|
||||||
|
|||||||
@@ -641,7 +641,11 @@ export default class UserSettingsDisplay extends React.Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const userLocale = this.props.user.locale;
|
||||||
if (this.props.activeSection === 'languages') {
|
if (this.props.activeSection === 'languages') {
|
||||||
|
if (!I18n.isLanguageAvailable(userLocale)) {
|
||||||
|
this.props.user.locale = global.window.mm_config.DefaultClientLocale;
|
||||||
|
}
|
||||||
languagesSection = (
|
languagesSection = (
|
||||||
<ManageLanguages
|
<ManageLanguages
|
||||||
user={this.props.user}
|
user={this.props.user}
|
||||||
@@ -652,7 +656,12 @@ export default class UserSettingsDisplay extends React.Component {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
var locale = I18n.getLanguageInfo(this.props.user.locale).name;
|
let locale;
|
||||||
|
if (I18n.isLanguageAvailable(userLocale)) {
|
||||||
|
locale = I18n.getLanguageInfo(userLocale).name;
|
||||||
|
} else {
|
||||||
|
locale = I18n.getLanguageInfo(global.window.mm_config.DefaultClientLocale).name;
|
||||||
|
}
|
||||||
|
|
||||||
languagesSection = (
|
languagesSection = (
|
||||||
<SettingItemMin
|
<SettingItemMin
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
const es = require('!!file?name=i18n/[name].[ext]!./es.json');
|
const es = require('!!file?name=i18n/[name].[ext]!./es.json');
|
||||||
const fr = require('!!file?name=i18n/[name].[ext]!./fr.json');
|
const fr = require('!!file?name=i18n/[name].[ext]!./fr.json');
|
||||||
const ja = require('!!file?name=i18n/[name].[ext]!./ja.json');
|
const ja = require('!!file?name=i18n/[name].[ext]!./ja.json');
|
||||||
const pt = require('!!file?name=i18n/[name].[ext]!./pt.json');
|
const pt_BR = require('!!file?name=i18n/[name].[ext]!./pt-BR.json'); //eslint-disable-line camelcase
|
||||||
|
|
||||||
import {addLocaleData} from 'react-intl';
|
import {addLocaleData} from 'react-intl';
|
||||||
import enLocaleData from 'react-intl/locale-data/en';
|
import enLocaleData from 'react-intl/locale-data/en';
|
||||||
@@ -34,19 +34,47 @@ const languages = {
|
|||||||
name: '日本語 (Beta)',
|
name: '日本語 (Beta)',
|
||||||
url: ja
|
url: ja
|
||||||
},
|
},
|
||||||
pt: {
|
'pt-BR': {
|
||||||
value: 'pt',
|
value: 'pt-BR',
|
||||||
name: 'Portugues (Beta)',
|
name: 'Portugues (Beta)',
|
||||||
url: pt
|
url: pt_BR
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getLanguages() {
|
let availableLanguages = null;
|
||||||
|
|
||||||
|
function setAvailableLanguages() {
|
||||||
|
const available = global.window.mm_config.AvailableLocales.split(',');
|
||||||
|
|
||||||
|
availableLanguages = {};
|
||||||
|
|
||||||
|
available.forEach((l) => {
|
||||||
|
if (languages[l]) {
|
||||||
|
availableLanguages[l] = languages[l];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAllLanguages() {
|
||||||
return languages;
|
return languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLanguages() {
|
||||||
|
if (!availableLanguages) {
|
||||||
|
setAvailableLanguages();
|
||||||
|
}
|
||||||
|
return availableLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
export function getLanguageInfo(locale) {
|
export function getLanguageInfo(locale) {
|
||||||
return languages[locale];
|
if (!availableLanguages) {
|
||||||
|
setAvailableLanguages();
|
||||||
|
}
|
||||||
|
return availableLanguages[locale];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLanguageAvailable(locale) {
|
||||||
|
return !!availableLanguages[locale];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function safariFix(callback) {
|
export function safariFix(callback) {
|
||||||
|
|||||||
@@ -27,8 +27,9 @@
|
|||||||
"react-bootstrap": "0.29.3",
|
"react-bootstrap": "0.29.3",
|
||||||
"react-custom-scrollbars": "4.0.0-beta.1",
|
"react-custom-scrollbars": "4.0.0-beta.1",
|
||||||
"react-dom": "15.0.2",
|
"react-dom": "15.0.2",
|
||||||
"react-intl": "2.0.0-rc-1",
|
"react-intl": "2.1.2",
|
||||||
"react-router": "2.4.0",
|
"react-router": "2.4.0",
|
||||||
|
"react-select": "1.0.0-beta13",
|
||||||
"react-textarea-autosize": "4.0.1",
|
"react-textarea-autosize": "4.0.1",
|
||||||
"superagent": "1.8.3",
|
"superagent": "1.8.3",
|
||||||
"twemoji": "2.0.5",
|
"twemoji": "2.0.5",
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const ActionTypes = Constants.ActionTypes;
|
|||||||
import AdminConsole from 'components/admin_console/admin_console.jsx';
|
import AdminConsole from 'components/admin_console/admin_console.jsx';
|
||||||
import SystemAnalytics from 'components/analytics/system_analytics.jsx';
|
import SystemAnalytics from 'components/analytics/system_analytics.jsx';
|
||||||
import ConfigurationSettings from 'components/admin_console/configuration_settings.jsx';
|
import ConfigurationSettings from 'components/admin_console/configuration_settings.jsx';
|
||||||
|
import LocalizationSettings from 'components/admin_console/localization_settings.jsx';
|
||||||
import UsersAndTeamsSettings from 'components/admin_console/users_and_teams_settings.jsx';
|
import UsersAndTeamsSettings from 'components/admin_console/users_and_teams_settings.jsx';
|
||||||
import PrivacySettings from 'components/admin_console/privacy_settings.jsx';
|
import PrivacySettings from 'components/admin_console/privacy_settings.jsx';
|
||||||
import LogSettings from 'components/admin_console/log_settings.jsx';
|
import LogSettings from 'components/admin_console/log_settings.jsx';
|
||||||
@@ -142,8 +143,8 @@ function preRenderSetup(callwhendone) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function afterIntl() {
|
function afterIntl() {
|
||||||
I18n.doAddLocaleData();
|
|
||||||
$.when(d1).done(() => {
|
$.when(d1).done(() => {
|
||||||
|
I18n.doAddLocaleData();
|
||||||
callwhendone();
|
callwhendone();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -362,6 +363,10 @@ function renderRootComponent() {
|
|||||||
path='configuration'
|
path='configuration'
|
||||||
component={ConfigurationSettings}
|
component={ConfigurationSettings}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path='localization'
|
||||||
|
component={LocalizationSettings}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path='users_and_teams'
|
path='users_and_teams'
|
||||||
component={UsersAndTeamsSettings}
|
component={UsersAndTeamsSettings}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
@import '~perfect-scrollbar/dist/css/perfect-scrollbar.css';
|
@import '~perfect-scrollbar/dist/css/perfect-scrollbar.css';
|
||||||
@import '~font-awesome/css/font-awesome.css';
|
@import '~font-awesome/css/font-awesome.css';
|
||||||
@import '~bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css';
|
@import '~bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css';
|
||||||
|
@import '~react-select/dist/react-select.css';
|
||||||
|
|
||||||
// styles.scss
|
// styles.scss
|
||||||
@import 'utils/module';
|
@import 'utils/module';
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
|
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||||
|
import LocalizationStore from './localization_store.jsx';
|
||||||
|
|
||||||
import Constants from 'utils/constants.jsx';
|
import Constants from 'utils/constants.jsx';
|
||||||
const ActionTypes = Constants.ActionTypes;
|
const ActionTypes = Constants.ActionTypes;
|
||||||
|
|
||||||
@@ -100,6 +103,9 @@ class UserStoreClass extends EventEmitter {
|
|||||||
this.saveProfile(user);
|
this.saveProfile(user);
|
||||||
this.currentUserId = user.id;
|
this.currentUserId = user.id;
|
||||||
global.window.mm_current_user_id = this.currentUserId;
|
global.window.mm_current_user_id = this.currentUserId;
|
||||||
|
if (LocalizationStore.getLocale() !== user.locale) {
|
||||||
|
GlobalActions.newLocalizationSelected(user.locale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentId() {
|
getCurrentId() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user