Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HARMONY
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amel Abdic
HARMONY
Commits
89f135d4
Commit
89f135d4
authored
1 year ago
by
jensilo
Browse files
Options
Downloads
Patches
Plain Diff
add language change to frontend
parent
220862a8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
config/trans.toml
+5
-1
5 additions, 1 deletion
config/trans.toml
src/app/user/web/web.go
+51
-0
51 additions, 0 deletions
src/app/user/web/web.go
translations/de.json
+6
-1
6 additions, 1 deletion
translations/de.json
translations/es.json
+1
-0
1 addition, 0 deletions
translations/es.json
with
63 additions
and
2 deletions
config/trans.toml
+
5
−
1
View file @
89f135d4
...
...
@@ -7,4 +7,8 @@ default = true
[locales.en]
path
=
"en"
name
=
"English"
\ No newline at end of file
name
=
"English"
[locales.es]
path
=
"es"
name
=
"Español"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/app/user/web/web.go
+
51
−
0
View file @
89f135d4
...
...
@@ -6,9 +6,11 @@ import (
"github.com/org-harmony/harmony/src/core/auth"
"github.com/org-harmony/harmony/src/core/config"
"github.com/org-harmony/harmony/src/core/hctx"
"github.com/org-harmony/harmony/src/core/trans"
"github.com/org-harmony/harmony/src/core/util"
"github.com/org-harmony/harmony/src/core/web"
"net/http"
"time"
)
const
Pkg
=
"app.user.web"
...
...
@@ -18,6 +20,7 @@ var ErrUpdateUser = errors.New("user.settings.update-error")
// RegisterController registers the web controllers for the user module.
// It registers the following routes:
// - GET /user/me/language/{locale} For updating the user language.
// - GET /auth/login For displaying various OAuth2 login buttons.
// - GET /auth/logout For logging out the user.
// - GET /user/me For displaying the user profile.
...
...
@@ -35,6 +38,7 @@ func RegisterController(appCtx *hctx.AppCtx, webCtx *web.Ctx) {
authCfg
:=
&
auth
.
Cfg
{}
util
.
Ok
(
config
.
C
(
authCfg
,
config
.
From
(
"auth"
),
config
.
Validate
(
appCtx
.
Validator
)))
router
.
Get
(
"/user/me/language/{locale}"
,
userLanguageController
(
appCtx
,
webCtx
)
.
ServeHTTP
)
router
.
Get
(
"/auth/login"
,
loginController
(
appCtx
,
webCtx
,
authCfg
)
.
ServeHTTP
)
router
.
Get
(
"/auth/logout"
,
logoutController
(
appCtx
,
webCtx
)
.
ServeHTTP
)
...
...
@@ -78,6 +82,34 @@ func registerNavigation(appCtx *hctx.AppCtx, webCtx *web.Ctx) {
},
Position
:
1000
,
})
webCtx
.
Navigation
.
Add
(
"user.language.de"
,
web
.
NavItem
{
URL
:
"/user/me/language/de"
,
Name
:
"harmony.menu.language.de"
,
Display
:
func
(
io
web
.
IO
)
(
bool
,
error
)
{
locale
,
err
:=
io
.
Request
()
.
Cookie
(
trans
.
LocaleSessionKey
)
if
err
!=
nil
{
return
false
,
err
}
return
locale
.
Value
!=
"de"
,
nil
},
Position
:
1050
,
})
webCtx
.
Navigation
.
Add
(
"user.language.en"
,
web
.
NavItem
{
URL
:
"/user/me/language/en"
,
Name
:
"harmony.menu.language.en"
,
Display
:
func
(
io
web
.
IO
)
(
bool
,
error
)
{
locale
,
err
:=
io
.
Request
()
.
Cookie
(
trans
.
LocaleSessionKey
)
if
err
!=
nil
{
return
true
,
err
}
return
locale
.
Value
!=
"en"
,
nil
},
Position
:
1050
,
})
}
func
registerTemplateDataExtensions
(
appCtx
*
hctx
.
AppCtx
,
webCtx
*
web
.
Ctx
)
{
...
...
@@ -122,6 +154,25 @@ func logoutController(appCtx *hctx.AppCtx, webCtx *web.Ctx) http.Handler {
})
}
func
userLanguageController
(
appCtx
*
hctx
.
AppCtx
,
webCtx
*
web
.
Ctx
)
http
.
Handler
{
return
web
.
NewController
(
appCtx
,
webCtx
,
func
(
io
web
.
IO
)
error
{
request
:=
io
.
Request
()
locale
:=
web
.
URLParam
(
request
,
"locale"
)
cookie
:=
http
.
Cookie
{
Name
:
trans
.
LocaleSessionKey
,
Value
:
locale
,
Expires
:
time
.
Now
()
.
Add
(
365
*
24
*
time
.
Hour
),
SameSite
:
http
.
SameSiteLaxMode
,
Path
:
"/"
,
}
http
.
SetCookie
(
io
.
Response
(),
&
cookie
)
return
io
.
Redirect
(
"/"
,
http
.
StatusTemporaryRedirect
)
})
}
func
userProfileController
(
appCtx
*
hctx
.
AppCtx
,
webCtx
*
web
.
Ctx
)
http
.
Handler
{
return
web
.
NewController
(
appCtx
,
webCtx
,
func
(
io
web
.
IO
)
error
{
return
io
.
Render
(
...
...
This diff is collapsed.
Click to expand it.
translations/de.json
+
6
−
1
View file @
89f135d4
...
...
@@ -181,7 +181,12 @@
"template-sets"
:
"Schablonen"
,
"user"
:
"Profil"
,
"login"
:
"Anmelden"
,
"logout"
:
"Abmelden"
"logout"
:
"Abmelden"
,
"language"
:
{
"label"
:
"Sprache"
,
"de"
:
"Deutsch"
,
"en"
:
"Englisch"
}
},
"error"
:
{
"generic"
:
"Leider ist ein unerwarteter Fehler aufgetreten."
,
...
...
This diff is collapsed.
Click to expand it.
translations/es.json
0 → 100644
+
1
−
0
View file @
89f135d4
{}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment