Silvan e4843d7692
fix(middleware): init translation messages (#7778)
* fix(middleware): init translation messages

* revert change

* refactor: split loop in separate function

* add imports to ensure init of fs

(cherry picked from commit 9bcfa12be237ab929a5d82b10d23e765753d3704)
2024-04-16 15:46:13 +02:00

54 lines
1.1 KiB
Go

package i18n
import (
"net/http"
"github.com/rakyll/statik/fs"
"github.com/zitadel/logging"
// ensure fs is setup
_ "github.com/zitadel/zitadel/internal/api/ui/login/statik"
_ "github.com/zitadel/zitadel/internal/notification/statik"
_ "github.com/zitadel/zitadel/internal/statik"
)
var zitadelFS, loginFS, notificationFS http.FileSystem
type Namespace string
const (
ZITADEL Namespace = "zitadel"
LOGIN Namespace = "login"
NOTIFICATION Namespace = "notification"
)
func LoadFilesystem(ns Namespace) http.FileSystem {
var err error
defer func() {
if err != nil {
logging.WithFields("namespace", ns).OnError(err).Panic("unable to get namespace")
}
}()
switch ns {
case ZITADEL:
if zitadelFS != nil {
return zitadelFS
}
zitadelFS, err = fs.NewWithNamespace(string(ns))
return zitadelFS
case LOGIN:
if loginFS != nil {
return loginFS
}
loginFS, err = fs.NewWithNamespace(string(ns))
return loginFS
case NOTIFICATION:
if notificationFS != nil {
return notificationFS
}
notificationFS, err = fs.NewWithNamespace(string(ns))
return notificationFS
}
return nil
}