Skip to content

Commit 495f684

Browse files
committed
simplify code, only use GET instead of POST and still call the real handler
1 parent 516c140 commit 495f684

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

modules/web/middleware/locale.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
1919
// 1. Check URL arguments.
2020
lang := req.URL.Query().Get("lang")
2121
changeLang := lang != ""
22-
// If the request is sent from language menu by AJAX, then it should only set the language but not run the real handler.
23-
// Otherwise the irrelevant code might be executed.
24-
skipHandler := req.URL.Query().Get("lang_skip_handler") != ""
2522

2623
// 2. Get language information from cookies.
2724
if len(lang) == 0 {
@@ -49,15 +46,7 @@ func Locale(resp http.ResponseWriter, req *http.Request) translation.Locale {
4946
SetLocaleCookie(resp, lang, 1<<31-1)
5047
}
5148

52-
err := translation.NewLocale(lang)
53-
if err != nil {
54-
return err
55-
}
56-
57-
if skipHandler {
58-
resp.WriteHeader(http.StatusNoContent)
59-
}
60-
return nil
49+
return translation.NewLocale(lang)
6150
}
6251

6352
// SetLocaleCookie convenience function to set the locale cookie consistently

web_src/js/features/common-global.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ export function initHeadNavbarContentToggle() {
3636

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

0 commit comments

Comments
 (0)