mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 16:32:31 +01:00
feature (languages): locale awareness for plugin
This commit is contained in:
parent
d0e856fe90
commit
5099422836
2 changed files with 15 additions and 0 deletions
|
|
@ -11,4 +11,5 @@ type App struct {
|
|||
Share Share
|
||||
Context context.Context
|
||||
Authorization string
|
||||
Languages []string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ func SessionStart(fn HandlerFunc) HandlerFunc {
|
|||
SendErrorResult(res, err)
|
||||
return
|
||||
}
|
||||
ctx.Languages = _extractLanguages(req)
|
||||
|
||||
fn(ctx, res, req)
|
||||
})
|
||||
}
|
||||
|
|
@ -327,3 +329,15 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
|
|||
func _extractBackend(req *http.Request, ctx *App) (IBackend, error) {
|
||||
return model.NewBackend(ctx, ctx.Session)
|
||||
}
|
||||
|
||||
func _extractLanguages(req *http.Request) []string {
|
||||
var lng = []string{}
|
||||
for _, lngs := range strings.Split(req.Header.Get("Accept-Language"), ",") {
|
||||
chunks := strings.Split(lngs, ";")
|
||||
if len(chunks) == 0 {
|
||||
continue
|
||||
}
|
||||
lng = append(lng, chunks[0])
|
||||
}
|
||||
return lng
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue