Skip to content

Commit

Permalink
feat: add internationalization foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-primrose committed Mar 24, 2024
1 parent 9dae148 commit 3264713
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 148 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
indent_style = space
indent_size = 2
charset=utf-8
14 changes: 14 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/open-amt-cloud-toolkit/console/internal/certificates"
"github.com/open-amt-cloud-toolkit/console/internal/dashboard"
"github.com/open-amt-cloud-toolkit/console/internal/devices"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/internal/profiles"
"go.etcd.io/bbolt"
)
Expand Down Expand Up @@ -57,6 +58,19 @@ func main() {
}
logger := log.New(os.Stdout, "http: ", log.LstdFlags)
middleware := internal.Tracing(nextRequestID)(internal.Logging(logger)(router))

// Setup localization
translations, err := i18n.LoadTranslations()
if err != nil {
logger.Println("failed loading translations", err)
os.Exit(1)
}

if err := i18n.SetupTranslations(translations); err != nil {
logger.Println("failed setting up translations", err)
os.Exit(1)
}

port := gotoolbox.GetEnvWithDefault("PORT", "8080")
logger.Println("listening on http://localhost:" + port)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/jritsema/gotoolbox v0.8.0
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.1.11
go.etcd.io/bbolt v1.3.9
golang.org/x/text v0.13.0
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
6 changes: 5 additions & 1 deletion internal/certificates/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/jritsema/gotoolbox/web"
"github.com/open-amt-cloud-toolkit/console/internal"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/pkg/templates"
"github.com/open-amt-cloud-toolkit/console/pkg/webtools"
)
Expand All @@ -26,9 +27,12 @@ type CertificateThing struct {
}

func NewCertificates(router *http.ServeMux) CertificateThing {
funcMap := template.FuncMap{
"Translate": i18n.Translate,
}
//parse templates
var err error
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/certificates", ".html", true, nil)
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/certificates", ".html", true, funcMap)
if err != nil {
panic(err)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/dashboard/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/jritsema/gotoolbox/web"
"github.com/open-amt-cloud-toolkit/console/internal"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/pkg/templates"
"github.com/open-amt-cloud-toolkit/console/pkg/webtools"
)
Expand All @@ -16,10 +17,12 @@ type DashboardPages struct {
}

func NewDashboard(router *http.ServeMux) DashboardPages {

funcMap := template.FuncMap{
"Translate": i18n.Translate,
}
//parse templates
var err error
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/dashboard", ".html", true, nil)
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/dashboard", ".html", true, funcMap)
if err != nil {
panic(err)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/devices/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/open-amt-cloud-toolkit/console/internal"
"github.com/open-amt-cloud-toolkit/console/internal/features/amt"
"github.com/open-amt-cloud-toolkit/console/internal/features/explorer"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/pkg/templates"
"github.com/open-amt-cloud-toolkit/console/pkg/webtools"
"github.com/open-amt-cloud-toolkit/go-wsman-messages/v2/pkg/wsman"
Expand All @@ -32,6 +33,7 @@ func NewDevices(db *bbolt.DB, router *http.ServeMux) DeviceThing {
funcMap := template.FuncMap{
"ProvisioningModeLookup": amt.ProvisioningModeLookup,
"ProvisioningStateLookup": amt.ProvisioningStateLookup,
"Translate": i18n.Translate,
}
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/devices", ".html", true, funcMap)
if err != nil {
Expand Down
54 changes: 54 additions & 0 deletions internal/i18n/i18n.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package i18n

import (
"embed"
"encoding/json"

"golang.org/x/text/language"
"golang.org/x/text/message"
)

type Languages map[string]Messages

type Messages map[string]string

var CurrentLanguage = language.English

//go:embed translations.json
var translations embed.FS

func LoadTranslations() (Languages, error) {
data, err := translations.ReadFile("translations.json")
if err != nil {
return Languages{}, err
}

var languages Languages
err = json.Unmarshal(data, &languages)
if err != nil {
return Languages{}, err
}
return languages, nil
}

func SetupTranslations(translations Languages) error {
for langTag, messages := range translations {
tag, err := language.Parse(langTag)
if err != nil {
return err
}

for key, translation := range messages {
err := message.SetString(tag, key, translation)
if err != nil {
return err
}
}
}
return nil
}

func Translate(key string) string {
p := message.NewPrinter(CurrentLanguage)
return p.Sprintf(key)
}
42 changes: 42 additions & 0 deletions internal/i18n/translations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"en": {
"WELCOME": "Welcome to Console!",
"DESCRIPTION": "Your centralized platform for managing Intel® Active Management Technology (AMT) devices within enterprise environments.",
"DETAILEDDESCRIPTION1": "Our console is expertly designed to streamline the administration of AMT-equipped devices, offering a comprehensive suite of out-of-band management features directly over your local network.",
"DETAILEDDESCRIPTION2": "With Console, you gain unparalleled control and visibility over your devices. Explore detailed device information at a glance, initiate secure connections via Keyboard, Video, Mouse (KVM) for real-time interaction, and leverage a range of out-of-band management capabilities to ensure your devices are always performing at their peak, regardless of their power state or operating system status.",
"DETAILEDDESCRIPTION3": "This console is specifically tailored for IT professionals and system administrators in enterprise settings, facilitating direct connections to AMT devices without the need for internet-based interactions. It's the perfect tool for enhancing your operational efficiency, ensuring security, and managing your devices more effectively.",
"DASHBOARD": "Dashboard",
"DEVICES": "Devices",
"CERTIFICATES": "Certificates",
"PROFILES": "Profiles",
"ADDDEVICE": "Add Device",
"DEVICENAME": "Name",
"DEVICEADDRESS": "Device Address",
"CONNECT": "Connect",
"EDIT": "Edit",
"DELETE": "Delete",
"HOSTOSFQDN": "Host OS FQDN",
"AMTUUID": "AMT UUID",
"POWERSTATE": "Power State"
},
"es": {
"WELCOME": "¡Te damos la bienvenida a la Console!",
"DESCRIPTION": "Su plataforma centralizada para gestionar dispositivos de tecnología Intel® Active Management Technology (AMT) en entornos empresariales.",
"DETAILEDDESCRIPTION1": "Nuestra consola está diseñada por expertos para agilizar la administración de dispositivos equipados con AMT, ofreciendo un conjunto completo de funciones de administración fuera de banda directamente a través de su red local.",
"DETAILEDDESCRIPTION2": "Con Console, obtienes un control y una visibilidad sin precedentes sobre tus dispositivos. Explore la información detallada del dispositivo de un vistazo, inicie conexiones seguras a través de teclado, vídeo y ratón (KVM) para una interacción en tiempo real y aproveche una gama de capacidades de gestión fuera de banda para garantizar que sus dispositivos siempre funcionen al máximo, independientemente de su estado de energía o del estado del sistema operativo.",
"DETAILEDDESCRIPTION3": "Esta consola está diseñada específicamente para profesionales de TI y administradores de sistemas en entornos empresariales, lo que facilita las conexiones directas a dispositivos AMT sin necesidad de interacciones basadas en Internet. Es la herramienta perfecta para mejorar su eficiencia operativa, garantizar la seguridad y administrar sus dispositivos de manera más efectiva.",
"DASHBOARD": "Salpicadero",
"DEVICES": "Dispositivos",
"CERTIFICATES": "Certificados",
"PROFILES": "Perfiles",
"ADDDEVICE": "Agregar dispositivo",
"DEVICENAME": "Nombre",
"DEVICEADDRESS": "Dirección del dispositivo",
"CONNECT": "Conectar",
"EDIT": "Editar",
"DELETE": "Borrar",
"HOSTOSFQDN": "FQDN del sistema operativo host",
"AMTUUID": "AMT UUID",
"POWERSTATE": "Estado de energía"
}
}
6 changes: 5 additions & 1 deletion internal/profiles/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/jritsema/gotoolbox/web"
"github.com/open-amt-cloud-toolkit/console/internal"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/pkg/templates"
"github.com/open-amt-cloud-toolkit/console/pkg/webtools"
"go.etcd.io/bbolt"
Expand All @@ -31,9 +32,12 @@ type ProfileThing struct {

func NewProfiles(db *bbolt.DB, router *http.ServeMux) ProfileThing {

funcMap := template.FuncMap{
"Translate": i18n.Translate,
}
//parse templates
var err error
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/profiles", ".html", true, nil)
html, err := templates.TemplateParseFSRecursive(internal.TemplateFS, "/profiles", ".html", true, funcMap)
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion internal/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/jritsema/gotoolbox/web"
"github.com/open-amt-cloud-toolkit/console/internal/i18n"
"github.com/open-amt-cloud-toolkit/console/pkg/templates"
"github.com/open-amt-cloud-toolkit/console/pkg/webtools"
)
Expand All @@ -22,9 +23,14 @@ var (
)

func NewIndex(router *http.ServeMux) IndexThing {

funcMap := template.FuncMap{
"Translate": i18n.Translate,
}

//parse templates
var err error
html, err = templates.TemplateParseFSRecursive(TemplateFS, "/", ".html", true, nil)
html, err = templates.TemplateParseFSRecursive(TemplateFS, "/", ".html", true, funcMap)
if err != nil {
panic(err)
}
Expand Down
22 changes: 11 additions & 11 deletions internal/templates/dashboard/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="p-4">
<h1 class="text-3xl font-semibold mb-4">Welcome to Console!</h1>
<h3 class="text-lg font-semibold mb-4 text-gray-500">Your centralized platform for managing Intel® Active Management Technology (AMT) devices within enterprise environments.</h3>
<h1 class="text-3xl font-semibold mb-4">{{ "WELCOME" | Translate }}
</h1>
<h3 class="text-lg font-semibold mb-4 text-gray-500">{{ "DESCRIPTION" | Translate }}</h3>

<!-- <div class="flex flex-row">
<div class="w-1/3 p-4">
Expand All @@ -20,16 +21,15 @@ <h2 class="text-lg font-semibold mb-4">Certificates</h2>
</div> -->

<div class="flex bg-gray-200 p-6 rounded-lg w-full">
Our console is expertly designed to streamline the administration of AMT-equipped devices, offering a comprehensive suite of out-of-band management features directly over your local network.
</br></br>
With the AMT Console, you gain unparalleled control and visibility over your devices. Explore detailed device information at a glance, initiate secure connections via Keyboard, Video, Mouse (KVM) for real-time interaction, and leverage a range of out-of-band management capabilities to ensure your devices are always performing at their peak, regardless of their power state or operating system status.
</br></br>
This console is specifically tailored for IT professionals and system administrators in enterprise settings, facilitating direct connections to AMT devices without the need for internet-based interactions. It's the perfect tool for enhancing your operational efficiency, ensuring security, and managing your devices more effectively.
<!-- </br></br>
{{ "DETAILEDDESCRIPTION1" | Translate }}
</br></br>
{{ "DETAILEDDESCRIPTION2" | Translate }}
</br></br>
{{ "DETAILEDDESCRIPTION3" | Translate }}
<!-- </br></br>
If your management needs extend beyond local network boundaries and require cloud-based solutions for connecting to devices over the internet, we recommend exploring the Open AMT Cloud Toolkit on GitHub at <a href="https://github.com/open-amt-cloud-toolkit">Open AMT Cloud Toolkit</a>. This toolkit complements our AMT Console by offering flexible, cloud-based management options for a truly comprehensive AMT device management ecosystem.
</br></br>
Dive into the AMT Console today and discover how our robust, secure, and user-friendly platform can transform your enterprise device management strategy.-->
</div>

</div>


</div>
Loading

0 comments on commit 3264713

Please sign in to comment.