-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added user language setting #3875
Changes from 2 commits
6bd5c33
2f1934b
064eb06
5f7f2cc
047f488
d06e37f
5ed980d
0d51925
d72c183
08ef144
6b90197
dfe96f1
0a25402
0b72ded
818fac3
425af39
1f02048
45213db
cf65e37
5660ff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2018 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
"github.com/go-xorm/xorm" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix import order |
||
) | ||
|
||
func addLanguageSetting(x *xorm.Engine) error { | ||
type User struct { | ||
Language string `xorm:"VARCHAR(5)"` | ||
} | ||
|
||
if err := x.Sync2(new(User)); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible that if a user logs in after an upgrade of the database, the language he/she is currently using is set as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think empty can be left as default after migration but when first logging in if it is empty it could be set to current ui language There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't thought of that, I'll implement it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,11 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR | |
ctx.Session.Set("uid", u.ID) | ||
ctx.Session.Set("uname", u.Name) | ||
|
||
// Language setting of the user overwrites the one previously set | ||
if u.Language != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. len(u.Language) != 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
ctx.SetCookie("lang", u.Language, nil, setting.AppSubURL) | ||
} | ||
|
||
// Clear whatever CSRF has right now, force to generate a new one | ||
ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL) | ||
|
||
|
@@ -698,6 +703,7 @@ func SignOut(ctx *context.Context) { | |
ctx.SetCookie(setting.CookieUserName, "", -1, setting.AppSubURL) | ||
ctx.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubURL) | ||
ctx.SetCookie(setting.CSRFCookieName, "", -1, setting.AppSubURL) | ||
ctx.SetCookie("lang", "", -1, setting.AppSubURL) // Setting the lang cookie will trigger the middleware to reset the language ot previous state. | ||
ctx.Redirect(setting.AppSubURL + "/") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/setting" | ||
"github.com/Unknwon/i18n" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix import order There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
) | ||
|
||
const ( | ||
|
@@ -105,6 +106,7 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) { | |
ctx.User.KeepEmailPrivate = form.KeepEmailPrivate | ||
ctx.User.Website = form.Website | ||
ctx.User.Location = form.Location | ||
ctx.User.Language = form.Language | ||
if err := models.UpdateUserSetting(ctx.User); err != nil { | ||
if _, ok := err.(models.ErrEmailAlreadyUsed); ok { | ||
ctx.Flash.Error(ctx.Tr("form.email_been_used")) | ||
|
@@ -115,8 +117,11 @@ func SettingsPost(ctx *context.Context, form auth.UpdateProfileForm) { | |
return | ||
} | ||
|
||
// Update the language to the one we just set | ||
ctx.SetCookie("lang", ctx.User.Language, nil, setting.AppSubURL) | ||
|
||
log.Trace("User settings updated: %s", ctx.User.Name) | ||
ctx.Flash.Success(ctx.Tr("settings.update_profile_success")) | ||
ctx.Flash.Success(i18n.Tr(ctx.User.Language, "settings.update_profile_success")) | ||
ctx.Redirect(setting.AppSubURL + "/user/settings") | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,20 @@ | |
<input id="location" name="location" value="{{.SignedUser.Location}}"> | ||
</div> | ||
|
||
<div class="field"> | ||
<label for="language">{{.i18n.Tr "settings.language"}}</label> | ||
<div class="ui language selection dropdown" id="language"> | ||
<input name="language" type="hidden"> | ||
<i class="dropdown icon"></i> | ||
<div class="text">{{.LangName}}</div> | ||
<div class="menu"> | ||
{{range .AllLangs}} | ||
<div class="item{{if eq $.Lang .Lang}} active selected{{end}}" data-value="{{.Lang}}">{{.Name}}</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed that. |
||
{{end}} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<button class="ui green button">{{$.i18n.Tr "settings.update_profile"}}</button> | ||
</div> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo