Check active path for being the root path
This commit is contained in:
@@ -9,6 +9,10 @@ const (
|
||||
De Language = "de"
|
||||
)
|
||||
|
||||
func (t Language) GetPath() string {
|
||||
return "/" + string(t)
|
||||
}
|
||||
|
||||
type GlobalI18nTexts interface {
|
||||
Add(text I18nText) GlobalI18nTexts
|
||||
GetAllTexts() []I18nText
|
||||
@@ -87,10 +91,13 @@ func NewActivePath(langMap map[Language]string, paths LanguagePaths) ActivePath
|
||||
}
|
||||
|
||||
func (a ActivePath) GetPath(language Language) string {
|
||||
return "/" + string(language) + a.Paths[language]
|
||||
return language.GetPath() + a.Paths[language]
|
||||
}
|
||||
|
||||
func (a ActivePath) IsActive(c HtmxContext) bool {
|
||||
pathWithLang := a.GetPath(c.GetLanguage())
|
||||
if pathWithLang == c.GetLanguage().GetPath()+"/" {
|
||||
return pathWithLang == c.GetPath()
|
||||
}
|
||||
return strings.HasPrefix(c.GetPath(), pathWithLang)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user