Adapt locale setup for monorepo, fix webconsole
This commit is contained in:
13
.github/workflows/release.yml
vendored
13
.github/workflows/release.yml
vendored
@@ -31,6 +31,9 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with: { go-version: "${{ env.GO_VERSION }}" }
|
||||
- name: "Copy language files"
|
||||
working-directory: server/pkg/locale
|
||||
run: make src/en
|
||||
- name: "Unit"
|
||||
working-directory: server
|
||||
run: make test.unit
|
||||
@@ -87,12 +90,14 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-go@v3
|
||||
with: { go-version: "${{ env.GO_VERSION }}" }
|
||||
# - name: "Restore web console dist from cache"
|
||||
# uses: actions/cache@v3
|
||||
# with: { path: ./server/webconsole/dist, key: console-build }
|
||||
|
||||
- name: "Restore web console dist from cache"
|
||||
uses: actions/cache@v3
|
||||
with: { path: ./server/webconsole/dist, key: console-build }
|
||||
- name: "Copy essentials"
|
||||
run: cp *.md DCO LICENSE server/
|
||||
- name: "Copy language files"
|
||||
working-directory: server/pkg/locale
|
||||
run: make src/en src/de src/fr
|
||||
- name: "Build"
|
||||
working-directory: server
|
||||
run: make release-clean release
|
||||
|
||||
@@ -163,13 +163,6 @@ provision:
|
||||
webapp:
|
||||
@ $(MAKE) --directory=webapp
|
||||
|
||||
locale.update:
|
||||
$(GO) get github.com/cortezaproject/corteza-locale@2022.9.x
|
||||
$(GO) mod vendor
|
||||
git add --all vendor/github.com/cortezaproject
|
||||
git commit -m 'Update corteza-locale dep' vendor/github.com/cortezaproject vendor/modules.txt go.mod go.sum
|
||||
|
||||
|
||||
vendors.check: $(MODOUTDATED)
|
||||
$(GO) list -mod=mod -u -m -json all | $(MODOUTDATED) -update -direct
|
||||
|
||||
@@ -216,7 +209,6 @@ test.pkg: $(GOTEST)
|
||||
# Test defaults to test.unit
|
||||
test: test.unit
|
||||
|
||||
|
||||
vet:
|
||||
$(GO) vet ./...
|
||||
|
||||
|
||||
@@ -134,7 +134,10 @@ func (app *CortezaApp) Setup() (err error) {
|
||||
}
|
||||
|
||||
if languages, err := locale.Service(localeLog, app.Opt.Locale); err != nil {
|
||||
return fmt.Errorf("locale service setup: %w", err)
|
||||
return fmt.Errorf(
|
||||
"locale service setup: %w; "+
|
||||
"if this is development environment set ENVIRONMENT=dev or LOCALE_DEVELOPMENT_MODE=true, "+
|
||||
"or run make -C pkg/locale if you want to embed languages before bulding server binary", err)
|
||||
} else {
|
||||
locale.SetGlobal(languages)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,12 @@ locale: schema.#optionsGroup & {
|
||||
}
|
||||
|
||||
path: {
|
||||
description: "One or more paths to locale config and translation files, separated by colon"
|
||||
description: """
|
||||
One or more paths to locale config and translation files, separated by colon
|
||||
|
||||
When with LOCALE_DEVELOPMENT_MODE=true, default value for path is ../../locale
|
||||
"""
|
||||
"""
|
||||
}
|
||||
|
||||
query_string_param: {
|
||||
|
||||
32
server/pkg/locale/Makefile
Normal file
32
server/pkg/locale/Makefile
Normal file
@@ -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)
|
||||
20
server/pkg/locale/embeded.go
Normal file
20
server/pkg/locale/embeded.go
Normal file
@@ -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() {
|
||||
|
||||
3
server/pkg/locale/src/README.md
Normal file
3
server/pkg/locale/src/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Place for embedded language files that get copied here before building the Corteza server.
|
||||
|
||||
See Makefile for details
|
||||
7
server/pkg/options/locale.go
Normal file
7
server/pkg/options/locale.go
Normal file
@@ -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