Skip to content
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

Fix UI language switching bug #21597

Merged
merged 8 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/doc/installation/with-docker.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ services:

## Databases

### SQLite3 database

Use the above "basic" docker-compose config, set "Database Type" to SQLite3 on the installation page.

SQLite3 is only suitable for small instances with few users.
It's recommended to use other database servers for production instances.

### MySQL database

To start Gitea in combination with a MySQL database, apply these changes to the
Expand Down
11 changes: 10 additions & 1 deletion modules/web/middleware/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
// 1. Check URL arguments.
lang := req.URL.Query().Get("lang")
changeLang := lang != ""
skipHandler := req.URL.Query().Get("lang_skip_handler") != ""
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved

// 2. Get language information from cookies.
if len(lang) == 0 {
Expand Down Expand Up @@ -46,7 +47,15 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
SetLocaleCookie(resp, lang, 1<<31-1)
}

return translation.NewLocale(lang)
err := translation.NewLocale(lang)
if err != nil {
return err
}

if skipHandler {
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
resp.WriteHeader(http.StatusNoContent)
}
return nil
}

// SetLocaleCookie convenience function to set the locale cookie consistently
Expand Down
2 changes: 1 addition & 1 deletion routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Install(ctx *context.Context) {
}
}
if !isCurDBTypeSupported {
curDBType = "mysql"
curDBType = setting.SupportedDatabaseTypes[0]
}
ctx.Data["CurDbType"] = curDBType

Expand Down
7 changes: 5 additions & 2 deletions web_src/js/features/common-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ export function initHeadNavbarContentToggle() {

export function initFootLanguageMenu() {
function linkLanguageAction() {
const $this = $(this);
$.post($this.data('url')).always(() => {
let changeLangUrl = $(this).attr('data-url');
changeLangUrl += changeLangUrl.includes('?') ? '&' : '?';
// Only use "lang_skip_handler" for ajax. Page links should not have this parameter because crawlers need to get the full page
changeLangUrl += 'lang_skip_handler=1';
$.get(changeLangUrl).always(() => {
window.location.reload();
});
}
Expand Down