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