Adapt locale setup for monorepo, fix webconsole
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
|
||||
PATH_ROOT := ../../..
|
||||
PATH_INTERNAL := $(PATH_ROOT)/locale
|
||||
VERSION := 2022.9.x
|
||||
|
||||
EXTERNAL_PKG := corteza-locale-$(VERSION).zip
|
||||
EXTERNAL_DIR := corteza-locale-$(VERSION)
|
||||
|
||||
# Default task
|
||||
copy-english-from-root-locale-dir: src/en
|
||||
|
||||
# Copy internal language files (english) to pkg/locale/src
|
||||
#
|
||||
# This way languages will be embedded into the build
|
||||
src/en:
|
||||
rm -rf $*
|
||||
cp -r $(PATH_INTERNAL)/en ./src
|
||||
|
||||
# Catch-all for external locales
|
||||
src/%: unpack-external
|
||||
cp -r $(EXTERNAL_DIR)/src/$* ./src
|
||||
|
||||
unpack-external: $(EXTERNAL_DIR)
|
||||
|
||||
$(EXTERNAL_DIR): $(EXTERNAL_PKG)
|
||||
unzip $@
|
||||
|
||||
$(EXTERNAL_PKG):
|
||||
curl -L https://github.com/cortezaproject/corteza-locale/archive/refs/heads/$(VERSION).zip -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(EXTERNAL_PKG) $(EXTERNAL_DIR)
|
||||
@@ -0,0 +1,20 @@
|
||||
package locale
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// This helps us import translations into corteza-server as a module
|
||||
// dependency
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed src/*
|
||||
var languages embed.FS
|
||||
|
||||
// LoadEmbedded returns embedded translation files
|
||||
// as a virtual filesystem
|
||||
func LoadEmbedded() fs.FS {
|
||||
sub, _ := fs.Sub(languages, "src")
|
||||
return sub
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
locale "github.com/cortezaproject/corteza-locale"
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/text/language"
|
||||
@@ -156,7 +155,7 @@ func (svc *service) ReloadStatic() (err error) {
|
||||
}
|
||||
|
||||
// load embedded locales from the corteza-locale package
|
||||
if ll, err = loadConfigs(locale.Languages()); err != nil {
|
||||
if ll, err = loadConfigs(LoadEmbedded()); err != nil {
|
||||
return fmt.Errorf("could not load embedded locales: %w", err)
|
||||
} else {
|
||||
// cleanup src and effectively mark the
|
||||
@@ -173,6 +172,13 @@ func (svc *service) ReloadStatic() (err error) {
|
||||
return fmt.Errorf("could not load imported locales: %w", err)
|
||||
}
|
||||
|
||||
if len(aux) == 0 {
|
||||
svc.log.Warn(
|
||||
"no languages found in path, future versions of Corteza will require at least one language to be present",
|
||||
zap.String("path", p),
|
||||
)
|
||||
}
|
||||
|
||||
for _, l := range aux {
|
||||
l.src = p + "/" + l.src
|
||||
}
|
||||
@@ -230,6 +236,11 @@ func (svc *service) ReloadStatic() (err error) {
|
||||
svc.set[lang.Tag] = lang
|
||||
}
|
||||
|
||||
svc.log.Debug("languages loaded",
|
||||
zap.Strings("path", svc.src),
|
||||
zap.Int("count", len(svc.set)),
|
||||
)
|
||||
|
||||
// Do another pass and link all extended languages
|
||||
for _, lang := range svc.set {
|
||||
if lang.Extends.IsRoot() {
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Place for embedded language files that get copied here before building the Corteza server.
|
||||
|
||||
See Makefile for details
|
||||
@@ -0,0 +1,7 @@
|
||||
package options
|
||||
|
||||
func (o *LocaleOpt) Defaults() {
|
||||
if Environment().IsDevelopment() || o.DevelopmentMode {
|
||||
o.Path = "../locale"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user