diff --git a/app.ini b/app.ini index 4a7558e..536380c 100644 --- a/app.ini +++ b/app.ini @@ -180,7 +180,7 @@ IS_INPUT_FILE = false [oauth2] ENABLE = true -JWT_SECRET = u4MdWtHbCQRH_d_VPfwijAsIr2vaBf7y2OhrT1JN3Cs +JWT_SECRET = sTE2-4pYnp9VUhgIk1LTiT-nCEWl5nEXt_GUssKXYOo [default] RUN_MODE = dev diff --git a/wacs-gitea/Dockerfile b/wacs-gitea/Dockerfile index 8b0be0a..c107a69 100644 --- a/wacs-gitea/Dockerfile +++ b/wacs-gitea/Dockerfile @@ -5,26 +5,34 @@ FROM gitea/gitea:${GITEA_VERSION}-rootless as LOCALE_SOURCE RUN gitea embedded extract --destination /var/lib/gitea/ options/locale/**.* # Build locale files from gitea, with WA's overrides and new keys -FROM node:20-slim as LOCALE_BUILDER +FROM golang:1.20 as LOCALE_BUILDER # copy gitea's locale files -COPY --from=LOCALE_SOURCE /var/lib/gitea/options/locale /gitea-locale WORKDIR /merge-locale +COPY --from=LOCALE_SOURCE /var/lib/gitea/options/locale /gitea-locale COPY merge-locale /merge-locale COPY custom/options/locale /wa-locale # output files to /output-locale/*.ini RUN mkdir /output-locale -RUN npm install -ci -RUN node localeMerge.js +RUN go build -o localeMerger + +# RUN npm install -ci +# RUN node localeMerge.js FROM gitea/gitea:${GITEA_VERSION}-rootless ENV GITEA_CUSTOM=/custom +COPY --from=LOCALE_BUILDER /merge-locale/localeMerger /merge-locale/localeMerger +COPY --from=LOCALE_SOURCE /var/lib/gitea/options/locale /gitea-locale +COPY merge-locale /merge-locale +COPY custom/options/locale /wa-locale -COPY --chown=git:git --from=LOCALE_BUILDER /output-locale/*.ini /custom/options/locale/ +# COPY --from=LOCALE_BUILDER /output-locale/*.ini /custom/options/locale/ COPY --chown=git:git ./custom/templates /custom/templates +COPY --chown=git:git ./custom/options/locale /custom/options/locale COPY ./custom/public /custom/public + ENV READER_BASE_LINK=read-dev.bibleineverylanguage.org ENTRYPOINT ["/usr/bin/dumb-init", "--"] -CMD ["sh", "-c", "cat /custom/templates/custom/extra_tabs.tmpl | envsubst > /tmp/extra_tabs.tmpl && mv /tmp/extra_tabs.tmpl /custom/templates/custom/extra_tabs.tmpl && /usr/local/bin/docker-entrypoint.sh"] \ No newline at end of file +CMD ["bash", "-c", "cat /custom/templates/custom/extra_tabs.tmpl | envsubst > /tmp/extra_tabs.tmpl && mv /tmp/extra_tabs.tmpl /custom/templates/custom/extra_tabs.tmpl && /merge-locale/localeMerger && /usr/local/bin/docker-entrypoint.sh"] diff --git a/wacs-gitea/custom/templates/custom/extra_links_footer.tmpl b/wacs-gitea/custom/templates/custom/extra_links_footer.tmpl index 20fdb49..2ceed0a 100644 --- a/wacs-gitea/custom/templates/custom/extra_links_footer.tmpl +++ b/wacs-gitea/custom/templates/custom/extra_links_footer.tmpl @@ -1,2 +1 @@ -{ - {.locale.Tr "wa.footer_agreement" | Str2html}} \ No newline at end of file +{{.locale.Tr "wa.footer_agreement" | Str2html}} \ No newline at end of file diff --git a/wacs-gitea/merge-locale/go.mod b/wacs-gitea/merge-locale/go.mod new file mode 100644 index 0000000..9d0c8dd --- /dev/null +++ b/wacs-gitea/merge-locale/go.mod @@ -0,0 +1,5 @@ +module example/locale + +go 1.20 + +require github.com/go-ini/ini v1.67.0 // indirect diff --git a/wacs-gitea/merge-locale/go.sum b/wacs-gitea/merge-locale/go.sum new file mode 100644 index 0000000..0e8d04e --- /dev/null +++ b/wacs-gitea/merge-locale/go.sum @@ -0,0 +1,2 @@ +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= diff --git a/wacs-gitea/merge-locale/localeMerge.js b/wacs-gitea/merge-locale/localeMerge.js deleted file mode 100644 index ee71b84..0000000 --- a/wacs-gitea/merge-locale/localeMerge.js +++ /dev/null @@ -1,45 +0,0 @@ -import fs from "fs"; -import ini from "ini"; -import path from "path"; - -const waLocaleDir = "/wa-locale"; -const giteaLocaleDir = "/gitea-locale"; -const outputDir = "/output-locale"; -const waLocaleFiles = fs.readdirSync(waLocaleDir); - -// Loop through each custom locale -waLocaleFiles.forEach((waLocale) => { - const waLocalePath = path.join(waLocaleDir, waLocale); - const giteaLocalePath = path.join(giteaLocaleDir, waLocale); - - // Check if the gitea locale file exists - if (fs.existsSync(giteaLocalePath)) { - const waData = ini.parse(fs.readFileSync(waLocalePath, "utf-8")); - console.log({waLocalePath}); - const giteaData = ini.parse(fs.readFileSync(giteaLocalePath, "utf-8")); - - // Combine keys as specified - for (const key in waData) { - if (typeof waData[key] == "object") { - for (const nestedKey in waData[key]) { - if (!giteaData[key]) { - giteaData[key] = {} - } - // Add if not exists, and overwrite if does - giteaData[key][nestedKey] = waData[key][nestedKey]; - } - } else { - // Add if not exists, and overwrite if does - giteaData[key] = waData[key]; - } - } - - // Write the combined data to the output directory - const outputPath = path.join(outputDir, waLocale); - - fs.writeFileSync(outputPath, ini.stringify(giteaData)); - console.log(`Combined and saved ${waLocale} to ${outputPath}`); - } else { - console.log(`gitea locale file not found for ${waLocale}`); - } -}); diff --git a/wacs-gitea/merge-locale/merge.go b/wacs-gitea/merge-locale/merge.go new file mode 100644 index 0000000..a831eb8 --- /dev/null +++ b/wacs-gitea/merge-locale/merge.go @@ -0,0 +1,71 @@ +package main + +import ( + "fmt" + "os" + "path" + + "github.com/go-ini/ini" +) + +func main() { + + // Define directory paths + waLocalesDir := "/wa-locale" + giteaLocalesDir := "/gitea-locale" + outputDir := ("/custom/options/locale/") + + // Read custom locales + customLocales, err := os.ReadDir(waLocalesDir) + if err != nil { + fmt.Println("Error reading custom locales directory:", err) + os.Exit(1) + } + + // Loop through each custom locale + for _, waLocale := range customLocales { + waLocalePath := path.Join(waLocalesDir, waLocale.Name()) + giteaLocalePath := path.Join(giteaLocalesDir, waLocale.Name()) + + // Check if the base locale file exists + if _, err := os.Stat(giteaLocalePath); err == nil { + // Read custom data + waLocaleData, err := ini.Load(waLocalePath) + if err != nil { + fmt.Println("Error loading custom data:", err) + continue + } + + // Read base data + giteaLocaleData, err := ini.Load(giteaLocalePath) + if err != nil { + fmt.Println("Error loading base data:", err) + continue + } + + // Combine keys as specified + for _, section := range waLocaleData.Sections() { + for _, key := range section.Keys() { + fmt.Println(key) + // Add if not exists, and overwrite if does + giteaLocaleData.Section(section.Name()).Key(key.Name()).SetValue(key.Value()) + } + } + + // Write the combined data to the output directory + outputPath := path.Join(outputDir, waLocale.Name()) + + + + err = giteaLocaleData.SaveTo(outputPath) + if err != nil { + fmt.Println("Error saving combined data:", err) + continue + } + + fmt.Printf("Combined and saved %s to %s\n", waLocale.Name(), outputPath) + } else { + fmt.Printf("Base locale file not found for %s\n", waLocale.Name()) + } + } +} diff --git a/wacs-gitea/merge-locale/package-lock.json b/wacs-gitea/merge-locale/package-lock.json deleted file mode 100644 index f662918..0000000 --- a/wacs-gitea/merge-locale/package-lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "merge-locales", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "merge-locales", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "ini": "^4.1.1" - } - }, - "node_modules/ini": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.1.tgz", - "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==", - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - } - } -} diff --git a/wacs-gitea/merge-locale/package.json b/wacs-gitea/merge-locale/package.json deleted file mode 100644 index 8c81be2..0000000 --- a/wacs-gitea/merge-locale/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "merge-locales", - "version": "1.0.0", - "description": "", - "main": "localeMerge.js", - "type": "module", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "ini": "^4.1.1" - } -}