fix(localization): HTML language header and forced-language (#787)
* fix: HTML language header and forced-language * style(changelog): added a couple headers * add test
This commit is contained in:
parent
e79cd93b61
commit
a900e98b8b
6 changed files with 275 additions and 253 deletions
|
|
@ -3,11 +3,11 @@ package localization
|
|||
import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"github.com/TecharoHQ/anubis"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/TecharoHQ/anubis"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
|
@ -94,6 +94,15 @@ func (sl *SimpleLocalizer) T(messageID string) string {
|
|||
return sl.Localizer.MustLocalize(&i18n.LocalizeConfig{MessageID: messageID})
|
||||
}
|
||||
|
||||
// Get the language that is used by the localizer by retrieving a well-known string that is required to be present
|
||||
func (sl *SimpleLocalizer) GetLang() string {
|
||||
_, tag, err := sl.Localizer.LocalizeWithTag(&i18n.LocalizeConfig{MessageID: "loading"})
|
||||
if err != nil {
|
||||
return "en"
|
||||
}
|
||||
return tag.String()
|
||||
}
|
||||
|
||||
// GetLocalizer creates a localizer based on the request's Accept-Language header or forcedLanguage option
|
||||
func GetLocalizer(r *http.Request) *SimpleLocalizer {
|
||||
var localizer *i18n.Localizer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue