Check active path for being the root path

This commit is contained in:
Achim Rohn
2025-08-13 11:11:59 +02:00
parent e09f88ee5b
commit 414c05f711
+8 -1
View File
@@ -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)
}