From 945048f43efbb0def581439529c7622f933a15dd Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sat, 6 Sep 2025 11:58:40 -0500 Subject: [PATCH] docs(multi lang support): work on getting multi lang support working --- .gitignore | 1 + .vscode/settings.json | 21 ++- .../{build app V2.bru => version.bru} | 6 +- controller/main.go | 123 +++++++++--------- lang/de.json | 5 + lang/en.json | 5 + lang/es.json | 5 + lstDocs/docs/install-extras/iis.md | 12 +- lstDocs/docs/install.md | 3 +- lstDocs/docs/intro.md | 4 + lstDocs/docs/ocp/materials.md | 29 +++-- lstDocs/docusaurus.config.ts | 29 ++++- lstDocs/sidebars.ts | 5 + .../img/install}/addApplication.png | Bin .../img/install}/application.png | Bin .../img/install}/applicationPools.png | Bin .../img/install}/createApplicationPool.png | Bin .../img/install}/defaultsite.png | Bin .../img => static/img/install}/pool.png | Bin .../img => static/img/install}/terminal.png | Bin .../ocp/img => static/img/ocp}/consume.png | Bin .../img/ocp}/consumeMaterial.png | Bin .../img => static/img/ocp}/consumebarcode.png | Bin .../{docs/ocp/img => static/img/ocp}/e1.png | Bin .../{docs/ocp/img => static/img/ocp}/e2.png | Bin .../{docs/ocp/img => static/img/ocp}/e3.png | Bin .../{docs/ocp/img => static/img/ocp}/e4.png | Bin .../{docs/ocp/img => static/img/ocp}/e5.png | Bin .../ocp/img => static/img/ocp}/label.png | Bin .../ocp/img => static/img/ocp}/labelQty.png | Bin .../{docs/ocp/img => static/img/ocp}/logs.png | Bin .../img => static/img/ocp}/lotTransfer.png | Bin .../img => static/img/ocp}/lst-consume.png | Bin .../img/ocp}/reprint-caution.png | Bin .../img => static/img/ocp}/returnBarcode.png | Bin .../ocp/img => static/img/ocp}/workorder.png | Bin package.json | 5 +- scripts/translateScript.js | 88 +++++++++++++ tsconfig.json | 11 +- 39 files changed, 259 insertions(+), 93 deletions(-) rename LogisticsSupportTool_API_DOCS/Controller/{build app V2.bru => version.bru} (60%) create mode 100644 lang/de.json create mode 100644 lang/en.json create mode 100644 lang/es.json rename lstDocs/{docs/install-extras/img => static/img/install}/addApplication.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/application.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/applicationPools.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/createApplicationPool.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/defaultsite.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/pool.png (100%) rename lstDocs/{docs/install-extras/img => static/img/install}/terminal.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/consume.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/consumeMaterial.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/consumebarcode.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/e1.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/e2.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/e3.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/e4.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/e5.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/label.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/labelQty.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/logs.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/lotTransfer.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/lst-consume.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/reprint-caution.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/returnBarcode.png (100%) rename lstDocs/{docs/ocp/img => static/img/ocp}/workorder.png (100%) create mode 100644 scripts/translateScript.js diff --git a/.gitignore b/.gitignore index 4b5e14d..509fc0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # ---> Node app/src/docs app/src/frontend +lstDocs/i18n lstWrapper/bin lstWrapper/obj lstWrapper/publish diff --git a/.vscode/settings.json b/.vscode/settings.json index ff325e0..59ec064 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,5 +24,24 @@ }, "[handlebars]": { "editor.formatOnSave": true - } + }, + "[go]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "golang.go" + }, + "[powershell]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "ms-vscode.powershell" // requires PowerShell extension + }, + "[bat]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" // supports .sh, .bat, .cmd + }, + "[cmd]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + + // Optional: Configure goimports instead of gofmt + "go.formatTool": "goimports" } diff --git a/LogisticsSupportTool_API_DOCS/Controller/build app V2.bru b/LogisticsSupportTool_API_DOCS/Controller/version.bru similarity index 60% rename from LogisticsSupportTool_API_DOCS/Controller/build app V2.bru rename to LogisticsSupportTool_API_DOCS/Controller/version.bru index 6d57caf..61abe75 100644 --- a/LogisticsSupportTool_API_DOCS/Controller/build app V2.bru +++ b/LogisticsSupportTool_API_DOCS/Controller/version.bru @@ -1,11 +1,11 @@ meta { - name: build app V2 + name: version type: http seq: 2 } -post { - url: http://localhost:8080/build +get { + url: http://localhost:8080/version body: none auth: inherit } diff --git a/controller/main.go b/controller/main.go index c2e19cb..937d1d5 100644 --- a/controller/main.go +++ b/controller/main.go @@ -11,84 +11,81 @@ import ( ) func main() { - r := gin.Default() + r := gin.Default() - // POST /build -> run npm build + increment .build - r.POST("/build", func(c *gin.Context) { - if err := runNpmBuild(); err != nil { - c.JSON(500, gin.H{"error": "npm build failed", "details": err.Error()}) - return - } + // POST /build -> run npm build + increment .build + r.POST("/build", func(c *gin.Context) { + host, err := os.Hostname() + if err != nil { + c.JSON(500, gin.H{"error": "Could not retrieve hostname"}) + return + } - buildNum, err := bumpBuild() - if err != nil { - c.JSON(500, gin.H{"error": "failed updating build counter", "details": err.Error()}) - return - } + log.Println(host) + if strings.Contains(host, "VMS") || strings.Contains(host, "vms") { + c.JSON(500, gin.H{"error": "You are not allowed to run the build on a production server"}) + return + } + // run the old builder first this will be removed once we switch fully over here and shut down the old version + if err := runNpmV2Build(); err != nil { + c.JSON(500, gin.H{"error": "npm build failed on lstV2", "details": err.Error()}) + return + } - // run the zip + // the new builder + if err := runNpmBuild(); err != nil { + c.JSON(500, gin.H{"error": "npm build failed", "details": err.Error()}) + return + } + + buildNum, err := bumpBuild() + if err != nil { + c.JSON(500, gin.H{"error": "failed updating build counter", "details": err.Error()}) + return + } + + // run the zip includes, _ := loadIncludePatterns("../.include") // Name the archive after build number if available - data, _ := os.ReadFile("../.build") - buildNum1 := strings.TrimSpace(string(data)) - if buildNum1 == "" { - buildNum1 = "0" - } + data, _ := os.ReadFile("../.build") + buildNum1 := strings.TrimSpace(string(data)) + if buildNum1 == "" { + buildNum1 = "0" + } buildDir, err := getBuildDir() if err != nil { log.Fatal(err) } //buildDir, err := ensureBuildDir("../builds") - if err != nil { - c.JSON(500, gin.H{"error": err.Error()}) - return - } + if err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + return + } - zipPath := filepath.Join(buildDir, fmt.Sprintf("release-%d.zip", buildNum)) + zipPath := filepath.Join(buildDir, fmt.Sprintf("release-%d.zip", buildNum)) - if err := zipProject("..", zipPath, includes); err != nil { - c.JSON(500, gin.H{"error": err.Error()}) - return - } + if err := zipProject("..", zipPath, includes); err != nil { + c.JSON(500, gin.H{"error": err.Error()}) + return + } - c.JSON(200, gin.H{ - "message": "build successful", - "build": buildNum, - }) - }) + c.JSON(200, gin.H{ + "message": "build successful", + "build": buildNum, + }) + }) - r.POST("/buildv2", func(c *gin.Context) { - if err := runNpmV2Build(); err != nil { - c.JSON(500, gin.H{"error": "npm build failed on lstV2", "details": err.Error()}) - return - } + // GET /version -> read current build version + r.GET("/version", func(c *gin.Context) { + data, err := os.ReadFile("../.build") + if err != nil { + c.JSON(404, gin.H{"error": "no build info"}) + return + } + c.JSON(200, gin.H{"build": strings.TrimSpace(string(data))}) + }) - buildNum, err := bumpBuild() - if err != nil { - c.JSON(500, gin.H{"error": "failed updating build counter", "details": err.Error()}) - return - } - - - - c.JSON(200, gin.H{ - "message": "build successful", - "build": buildNum, - }) - }) - - // GET /version -> read current build version - r.GET("/version", func(c *gin.Context) { - data, err := os.ReadFile(".build") - if err != nil { - c.JSON(404, gin.H{"error": "no build info"}) - return - } - c.JSON(200, gin.H{"build": strings.TrimSpace(string(data))}) - }) - - r.Run(":8080") // serve API + r.Run(":8080") // serve API } - diff --git a/lang/de.json b/lang/de.json new file mode 100644 index 0000000..92a5988 --- /dev/null +++ b/lang/de.json @@ -0,0 +1,5 @@ +{ + "intro.title": "Einführung", + "intro.heading": "Willkommen zu unserer Dokumentation", + "intro.body": "Dies ist der deutsche Einführungsabsatz." +} diff --git a/lang/en.json b/lang/en.json new file mode 100644 index 0000000..a498c3e --- /dev/null +++ b/lang/en.json @@ -0,0 +1,5 @@ +{ + "intro.title": "Introduction", + "intro.heading": "Welcome to our Docs", + "intro.body": "This is the English introduction paragraph." +} diff --git a/lang/es.json b/lang/es.json new file mode 100644 index 0000000..c573016 --- /dev/null +++ b/lang/es.json @@ -0,0 +1,5 @@ +{ + "intro.title": "Introducción", + "intro.heading": "Bienvenido a nuestra Documentación", + "intro.body": "Este es el párrafo de introducción en español." +} diff --git a/lstDocs/docs/install-extras/iis.md b/lstDocs/docs/install-extras/iis.md index 74aee20..ea1b55d 100644 --- a/lstDocs/docs/install-extras/iis.md +++ b/lstDocs/docs/install-extras/iis.md @@ -15,28 +15,28 @@ Please note that if you plan to utlize the scanner app you must use IIS to run a 1. Open IIS 2. Expand the plant and select application pools - ![](./img/applicationPools.png) + ![](/img/install/applicationPools.png) 3. Right click and create application - ![](./img/createApplicationPool.png) + ![](/img/install/createApplicationPool.png) 4. Name is Logistics Support Tool - Change .NET CLR verion to not managed - leave the rest as default - ![](./img/pool.png) + ![](/img/install/pool.png) ## Create the website 1. Expand the Sites -![](./img/defaultsite.png) +![](/img/install/defaultsite.png) 2. Right click on default site and click "Add Application..." -![](./img/addApplication.png) +![](/img/install/addApplication.png) 3. Fill out the form like below @@ -48,7 +48,7 @@ Please note that if you plan to utlize the scanner app you must use IIS to run a E:\LST\lstWrapper ``` -![](./img/application.png) +![](/img/install/application.png) ## Making sure websocket is enabled diff --git a/lstDocs/docs/install.md b/lstDocs/docs/install.md index 1bdbe9a..2122315 100644 --- a/lstDocs/docs/install.md +++ b/lstDocs/docs/install.md @@ -1,5 +1,6 @@ --- sidebar_position: 2 +id: install --- # Install Process @@ -105,7 +106,7 @@ Make sure you have installed both open the app in vs code open terminal -![](./install-extras/img/terminal.png) +![](/img/install/terminal.png) run the install command diff --git a/lstDocs/docs/intro.md b/lstDocs/docs/intro.md index 061e075..28b561f 100644 --- a/lstDocs/docs/intro.md +++ b/lstDocs/docs/intro.md @@ -1,5 +1,9 @@ --- sidebar_position: 1 +id: intro +title: intro.title +--- + --- # Logisitcs Support Tool Intro diff --git a/lstDocs/docs/ocp/materials.md b/lstDocs/docs/ocp/materials.md index 78264fd..739ccb0 100644 --- a/lstDocs/docs/ocp/materials.md +++ b/lstDocs/docs/ocp/materials.md @@ -1,5 +1,6 @@ --- sidebar_position: 1 +id: ocp --- # Material Consumption @@ -22,7 +23,7 @@ here you will be able to see the logs for the last 4 hours to identifty what the below is an example of missing materials. -![](./img/logs.png) +![](/img/ocp/logs.png) as you see this lot is missing a lot of items. if the packer keeps pressing the pause button you will see quite a few of these. @@ -39,16 +40,16 @@ To correct these errors follow each error. Grab a scanner and scan the Consume non-prepared material -![](./img/consume.png) +![](/img/ocp//consume.png) next grab the production work order of the lot you will be running the material on. Then scan the top barcode. -![](./img/workorder.png) +![](/img/ocp//workorder.png) Lastly scan the cage of preforms, resin, or color you will be consuming to the lot. -![](./img/label.png) +![](/img/ocp//label.png) ## Consuming new manual material via LST. @@ -58,7 +59,7 @@ Click on material helper on the left side bar. Enter the lot and running number and click consume, the card also comes with basic insturctions. -![](./img/lst-consume.png) +![](/img/ocp//lst-consume.png) This will do the exact same process as using the scanner. @@ -75,7 +76,7 @@ then you will want to add the enter the running number and the original quantity label example to show where to look -![](./img/labelQty.png) +![](/img/ocp/labelQty.png) NOTE: preforms have there quantity on the label as well and you can still use the external running number(iowas perform running numebr) to move to the next lot. @@ -83,15 +84,15 @@ Last part you will need is the lot number you will be moving the material too. Like in the consume lst comes with basic insturctions as well. -![](./img/lotTransfer.png) +![](/img/ocp/lotTransfer.png) Please see example errors that you could see when utlizeing the lotTransfer card. -![](./img/e1.png) ![](./img/e2.png) ![](./img/e3.png) ![](./img/e4.png) +![](/img/ocp/e1.png) ![](/img/ocp//e2.png) ![](/img/ocp/e3.png) ![](/img/ocp/e4.png) The below specfic and very generic error is more than likely an input error. And that could be the running number is wrong and never actually was in the system, but in the event everything was checked and you still get the error please report by entering a helpdesk ticket. -![](./img/e5.png) +![](/img/ocp/e5.png) ## Manual return and consume @@ -110,7 +111,7 @@ Grab your label you are wanting to move to the next lot Note the running number and qty. you will not ever be able to reprint for more than the qty that is currenty on the label -![](./img/labelQty.png) +![](/img/ocp/labelQty.png) next open up alpla label (any version of alpla label will work for this step) and click on the reprint tab. @@ -120,13 +121,13 @@ NOTE: if you see the yellow triangle like in the below example this indicates th please reach out to your manager or supervisor to ask for next steps on what to do. -![](./img/reprint-caution.png) +![](/img/ocp//reprint-caution.png) Next take the newly printed label, a scanner, workorder, and location barcode. scan -![](./img/returnBarcode.png) +![](/img/ocp/returnBarcode.png) - Scan the unit (The label you reprinted). - Scan the lane (location where you will be returning this material/preforms to) @@ -136,10 +137,10 @@ Grab the new work order Scan -![](./img/consumebarcode.png) +![](/img/ocp/consumebarcode.png) - Scan the top bar code on the production order - ![](./img/workorder.png) + ![](/img/ocp/workorder.png) - Scan the barcode of the label you reprinted diff --git a/lstDocs/docusaurus.config.ts b/lstDocs/docusaurus.config.ts index e06a501..bd2874a 100644 --- a/lstDocs/docusaurus.config.ts +++ b/lstDocs/docusaurus.config.ts @@ -33,7 +33,30 @@ const config: Config = { // may want to replace "en" with "zh-Hans". i18n: { defaultLocale: "en", - locales: ["en"], + locales: ["en", "es"], + // localeConfigs: { + // en: { + // label: "English", + // direction: "ltr", + // htmlLang: "en-US", + // calendar: "gregory", + // path: "en", + // }, + // es: { + // label: "Español", + // direction: "ltr", + // htmlLang: "es-ES", + // calendar: "gregory", + // path: "es", + // }, + // de: { + // label: "Deutsch", + // direction: "ltr", + // htmlLang: "de-DE", + // calendar: "gregory", + // path: "de", + // }, + // }, }, presets: [ @@ -92,6 +115,10 @@ const config: Config = { // label: "GitHub", // position: "right", // }, + // { + // type: "localeDropdown", + // position: "right", + // }, ], }, footer: { diff --git a/lstDocs/sidebars.ts b/lstDocs/sidebars.ts index 663ee01..e804cda 100644 --- a/lstDocs/sidebars.ts +++ b/lstDocs/sidebars.ts @@ -14,6 +14,11 @@ import type { SidebarsConfig } from "@docusaurus/plugin-content-docs"; */ const sidebars: SidebarsConfig = { // By default, Docusaurus generates a sidebar from the docs folder structure + // docsSidebar: [ + // { type: "doc", id: "intro" }, + // { type: "doc", id: "install" }, + // { type: "doc", id: "ocp/ocp" }, + // ], docsSidebar: [{ type: "autogenerated", dirName: "." }], // But you can create a sidebar manually diff --git a/lstDocs/docs/install-extras/img/addApplication.png b/lstDocs/static/img/install/addApplication.png similarity index 100% rename from lstDocs/docs/install-extras/img/addApplication.png rename to lstDocs/static/img/install/addApplication.png diff --git a/lstDocs/docs/install-extras/img/application.png b/lstDocs/static/img/install/application.png similarity index 100% rename from lstDocs/docs/install-extras/img/application.png rename to lstDocs/static/img/install/application.png diff --git a/lstDocs/docs/install-extras/img/applicationPools.png b/lstDocs/static/img/install/applicationPools.png similarity index 100% rename from lstDocs/docs/install-extras/img/applicationPools.png rename to lstDocs/static/img/install/applicationPools.png diff --git a/lstDocs/docs/install-extras/img/createApplicationPool.png b/lstDocs/static/img/install/createApplicationPool.png similarity index 100% rename from lstDocs/docs/install-extras/img/createApplicationPool.png rename to lstDocs/static/img/install/createApplicationPool.png diff --git a/lstDocs/docs/install-extras/img/defaultsite.png b/lstDocs/static/img/install/defaultsite.png similarity index 100% rename from lstDocs/docs/install-extras/img/defaultsite.png rename to lstDocs/static/img/install/defaultsite.png diff --git a/lstDocs/docs/install-extras/img/pool.png b/lstDocs/static/img/install/pool.png similarity index 100% rename from lstDocs/docs/install-extras/img/pool.png rename to lstDocs/static/img/install/pool.png diff --git a/lstDocs/docs/install-extras/img/terminal.png b/lstDocs/static/img/install/terminal.png similarity index 100% rename from lstDocs/docs/install-extras/img/terminal.png rename to lstDocs/static/img/install/terminal.png diff --git a/lstDocs/docs/ocp/img/consume.png b/lstDocs/static/img/ocp/consume.png similarity index 100% rename from lstDocs/docs/ocp/img/consume.png rename to lstDocs/static/img/ocp/consume.png diff --git a/lstDocs/docs/ocp/img/consumeMaterial.png b/lstDocs/static/img/ocp/consumeMaterial.png similarity index 100% rename from lstDocs/docs/ocp/img/consumeMaterial.png rename to lstDocs/static/img/ocp/consumeMaterial.png diff --git a/lstDocs/docs/ocp/img/consumebarcode.png b/lstDocs/static/img/ocp/consumebarcode.png similarity index 100% rename from lstDocs/docs/ocp/img/consumebarcode.png rename to lstDocs/static/img/ocp/consumebarcode.png diff --git a/lstDocs/docs/ocp/img/e1.png b/lstDocs/static/img/ocp/e1.png similarity index 100% rename from lstDocs/docs/ocp/img/e1.png rename to lstDocs/static/img/ocp/e1.png diff --git a/lstDocs/docs/ocp/img/e2.png b/lstDocs/static/img/ocp/e2.png similarity index 100% rename from lstDocs/docs/ocp/img/e2.png rename to lstDocs/static/img/ocp/e2.png diff --git a/lstDocs/docs/ocp/img/e3.png b/lstDocs/static/img/ocp/e3.png similarity index 100% rename from lstDocs/docs/ocp/img/e3.png rename to lstDocs/static/img/ocp/e3.png diff --git a/lstDocs/docs/ocp/img/e4.png b/lstDocs/static/img/ocp/e4.png similarity index 100% rename from lstDocs/docs/ocp/img/e4.png rename to lstDocs/static/img/ocp/e4.png diff --git a/lstDocs/docs/ocp/img/e5.png b/lstDocs/static/img/ocp/e5.png similarity index 100% rename from lstDocs/docs/ocp/img/e5.png rename to lstDocs/static/img/ocp/e5.png diff --git a/lstDocs/docs/ocp/img/label.png b/lstDocs/static/img/ocp/label.png similarity index 100% rename from lstDocs/docs/ocp/img/label.png rename to lstDocs/static/img/ocp/label.png diff --git a/lstDocs/docs/ocp/img/labelQty.png b/lstDocs/static/img/ocp/labelQty.png similarity index 100% rename from lstDocs/docs/ocp/img/labelQty.png rename to lstDocs/static/img/ocp/labelQty.png diff --git a/lstDocs/docs/ocp/img/logs.png b/lstDocs/static/img/ocp/logs.png similarity index 100% rename from lstDocs/docs/ocp/img/logs.png rename to lstDocs/static/img/ocp/logs.png diff --git a/lstDocs/docs/ocp/img/lotTransfer.png b/lstDocs/static/img/ocp/lotTransfer.png similarity index 100% rename from lstDocs/docs/ocp/img/lotTransfer.png rename to lstDocs/static/img/ocp/lotTransfer.png diff --git a/lstDocs/docs/ocp/img/lst-consume.png b/lstDocs/static/img/ocp/lst-consume.png similarity index 100% rename from lstDocs/docs/ocp/img/lst-consume.png rename to lstDocs/static/img/ocp/lst-consume.png diff --git a/lstDocs/docs/ocp/img/reprint-caution.png b/lstDocs/static/img/ocp/reprint-caution.png similarity index 100% rename from lstDocs/docs/ocp/img/reprint-caution.png rename to lstDocs/static/img/ocp/reprint-caution.png diff --git a/lstDocs/docs/ocp/img/returnBarcode.png b/lstDocs/static/img/ocp/returnBarcode.png similarity index 100% rename from lstDocs/docs/ocp/img/returnBarcode.png rename to lstDocs/static/img/ocp/returnBarcode.png diff --git a/lstDocs/docs/ocp/img/workorder.png b/lstDocs/static/img/ocp/workorder.png similarity index 100% rename from lstDocs/docs/ocp/img/workorder.png rename to lstDocs/static/img/ocp/workorder.png diff --git a/package.json b/package.json index 027f186..0ac20a7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts", - "dev:docs": "cd lstDocs && npm start", + "dev:docs": "npm run translateDocs && cd lstDocs && npm start", "dev:front": "cd frontend && npm run dev", "dev": "npm run dev:app", "copy:docs": "node scripts/lstDocCopy.mjs", @@ -26,7 +26,8 @@ "commit": "cz", "deploy": "standard-version --conventional-commits && npm run build", "db:migrate": "npx drizzle-kit push --config=drizzle-dev.config.ts", - "db:generate": "npx drizzle-kit generate --config=drizzle-dev.config.ts" + "db:generate": "npx drizzle-kit generate --config=drizzle-dev.config.ts", + "translateDocs": "cd scripts && node translateScript.js" }, "repository": { "type": "git", diff --git a/scripts/translateScript.js b/scripts/translateScript.js new file mode 100644 index 0000000..a63a89c --- /dev/null +++ b/scripts/translateScript.js @@ -0,0 +1,88 @@ +// scripts/sync-translations.js +import fs from "fs"; +import path from "path"; + +const locales = ["en", "es", "de"]; + +const docsDir = path.join(process.cwd(), "../lstDocs/docs"); // canonical English docs +const i18nDir = path.join(process.cwd(), "../lstDocs/i18n"); // output localized docs +const langDir = path.join(process.cwd(), "../lang"); // json translations + +// load translations +const translations = {}; +for (const locale of locales) { + const filePath = path.join(langDir, `${locale}.json`); + translations[locale] = JSON.parse(fs.readFileSync(filePath, "utf8")); +} + +// lookup helper with English fallback +function t(key, locale) { + return translations[locale][key] || translations["en"][key] || key; +} + +// copy directory recursively +function copyDir(src, dest) { + if (!fs.existsSync(src)) return; + fs.mkdirSync(dest, { recursive: true }); + for (const item of fs.readdirSync(src)) { + const s = path.join(src, item); + const d = path.join(dest, item); + const stat = fs.statSync(s); + if (stat.isDirectory()) copyDir(s, d); + else fs.copyFileSync(s, d); + } +} + +// recursive doc processor +function processDir(srcDir, relDir = "") { + for (const item of fs.readdirSync(srcDir, { withFileTypes: true })) { + const srcPath = path.join(srcDir, item.name); + const relPath = path.join(relDir, item.name); + + if (item.isDirectory()) { + processDir(srcPath, relPath); + continue; + } + + if (item.isFile() && item.name.endsWith(".md")) { + const baseContent = fs.readFileSync(srcPath, "utf8"); + + for (const locale of locales) { + // replace keys with translations + const localizedContent = baseContent.replace( + /([a-z]+(\.[a-z]+)+)/g, + (match) => t(match, locale) + ); + + // output directory preserves structure + const outDir = path.join( + i18nDir, + locale, + "docusaurus-plugin-content-docs/current", + relDir + ); + fs.mkdirSync(outDir, { recursive: true }); + + const outFile = path.join(outDir, item.name); + fs.writeFileSync(outFile, localizedContent, "utf8"); + } + } + + // if there's an "img" folder alongside docs, copy it once for each locale + if (item.isDirectory() && item.name === "img") { + for (const locale of locales) { + const outDir = path.join( + i18nDir, + locale, + "docusaurus-plugin-content-docs/current", + relDir, + "img" + ); + copyDir(srcPath, outDir); + } + } + } +} + +// run +processDir(docsDir); diff --git a/tsconfig.json b/tsconfig.json index de914d1..8fa3223 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,14 @@ "include": [ "app/src", "scripts/**/*.ts", - "database/testFiles/test-tiPostOrders.ts" + "database/testFiles/test-tiPostOrders.ts", + "scripts/translateScript.js" ], - "exclude": ["node_modules", "frontend", "dist", "lstDocs","database/testFiles"] + "exclude": [ + "node_modules", + "frontend", + "dist", + "lstDocs", + "database/testFiles" + ] }