From 111b1da00d3d45d0708ca33036d33a2502b3f6a6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 11 Oct 2022 18:59:52 +0200 Subject: [PATCH 1/4] test jq to merge locale files --- docker/webapp.Dockerfile | 3 +++ tools/test/file1.json | 12 ++++++++++++ tools/test/file2.json | 11 +++++++++++ tools/test/result.json | 15 +++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tools/test/file1.json create mode 100644 tools/test/file2.json create mode 100644 tools/test/result.json diff --git a/docker/webapp.Dockerfile b/docker/webapp.Dockerfile index 81748e0..5c3f98f 100644 --- a/docker/webapp.Dockerfile +++ b/docker/webapp.Dockerfile @@ -15,6 +15,9 @@ COPY branding/constants/ constants/ COPY branding/locales/ locales/ COPY branding/assets/styles/imports/ assets/styles/imports/ +## Something like (bash, jq must be installed) +# for locale in `ls locales/*.json`; do jq -s '.[0] * .[1]' source/$locale $locale; done; + ################################################################################## # BUILD ########################################################################## ################################################################################## diff --git a/tools/test/file1.json b/tools/test/file1.json new file mode 100644 index 0000000..19ec4e1 --- /dev/null +++ b/tools/test/file1.json @@ -0,0 +1,12 @@ +{ + "a-key": "A", + "b-key": { + "a-subkey": "A", + "b-subkey": "B", + "c-subkey": { + "a-subsubkey": "A", + "b-subsubkey": "B" + } + }, + "c-key": "C" +} diff --git a/tools/test/file2.json b/tools/test/file2.json new file mode 100644 index 0000000..e4d7ade --- /dev/null +++ b/tools/test/file2.json @@ -0,0 +1,11 @@ +{ + "a-key": "AA", + "b-key": { + "b-subkey": "BB", + "c-subkey": { + "b-subsubkey": "BB", + "c-subsubkey": "C" + } + }, + "d-key": "D" +} diff --git a/tools/test/result.json b/tools/test/result.json new file mode 100644 index 0000000..843c235 --- /dev/null +++ b/tools/test/result.json @@ -0,0 +1,15 @@ +{ + "a-key": "AA", + "b-key": { + "a-subkey": "A", + "b-subkey": "BB", + "c-subkey": { + "a-subsubkey": "A", + "b-subsubkey": "BB", + "c-subsubkey": "C" + } + }, + "c-key": "C", + "d-key": "D" +} + From 9045ac3199545789ffd47ece6f5997371b0ebe0f Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 12 Oct 2022 15:33:07 +0200 Subject: [PATCH 2/4] add script to merge variables --- branding/locales/de.json | 3 +++ docker/webapp.Dockerfile | 8 +++++++- tools/merge-locales.sh | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 branding/locales/de.json create mode 100755 tools/merge-locales.sh diff --git a/branding/locales/de.json b/branding/locales/de.json new file mode 100644 index 0000000..7fa1f1b --- /dev/null +++ b/branding/locales/de.json @@ -0,0 +1,3 @@ +{ + "new-key": "This is a new key" +} diff --git a/docker/webapp.Dockerfile b/docker/webapp.Dockerfile index 5c3f98f..104b484 100644 --- a/docker/webapp.Dockerfile +++ b/docker/webapp.Dockerfile @@ -12,9 +12,15 @@ FROM $APP_IMAGE_CODE as code # copy public constants into the Docker image to brand it COPY branding/static/ static/ COPY branding/constants/ constants/ -COPY branding/locales/ locales/ +COPY branding/locales/html/ locales/html/ +# COPY branding/locales/index.js locales/index.js +COPY branding/locales/*.json locales/tmp/ COPY branding/assets/styles/imports/ assets/styles/imports/ +RUN apk add --no-cache bash jq + +RUN tools/merge-locales.sh + ## Something like (bash, jq must be installed) # for locale in `ls locales/*.json`; do jq -s '.[0] * .[1]' source/$locale $locale; done; diff --git a/tools/merge-locales.sh b/tools/merge-locales.sh new file mode 100755 index 0000000..8fc5c75 --- /dev/null +++ b/tools/merge-locales.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +for locale in `ls locales/*.json`; +do + file = basename $locale; + if [ -f locales/tmp/$file ]; then + jq -s '.[0] * .[1]' $locale locales/tmp/$file > locales/tmp/tmp.json; + mv locales/tmp/tmp.json $locale; + fi; +done; From ebf8894ca25b5dfeec032390ea42fc5c961891b4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 12 Oct 2022 15:58:28 +0200 Subject: [PATCH 3/4] remove tmp folder, test for override of existing locales --- branding/locales/de.json | 5 +++++ docker/webapp.Dockerfile | 4 +--- tools/merge-locales.sh | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/branding/locales/de.json b/branding/locales/de.json index 7fa1f1b..8f42e89 100644 --- a/branding/locales/de.json +++ b/branding/locales/de.json @@ -1,3 +1,8 @@ { +"user": { + "avatar": { + "submitted": "XXXXXXX" + } + }, "new-key": "This is a new key" } diff --git a/docker/webapp.Dockerfile b/docker/webapp.Dockerfile index 104b484..ba7cbff 100644 --- a/docker/webapp.Dockerfile +++ b/docker/webapp.Dockerfile @@ -10,6 +10,7 @@ ARG APP_IMAGE_CODE=${APP_IMAGE}:${APP_IMAGE_TAG_CODE} FROM $APP_IMAGE_CODE as code # copy public constants into the Docker image to brand it +COPY tools/ tools/ COPY branding/static/ static/ COPY branding/constants/ constants/ COPY branding/locales/html/ locales/html/ @@ -21,9 +22,6 @@ RUN apk add --no-cache bash jq RUN tools/merge-locales.sh -## Something like (bash, jq must be installed) -# for locale in `ls locales/*.json`; do jq -s '.[0] * .[1]' source/$locale $locale; done; - ################################################################################## # BUILD ########################################################################## ################################################################################## diff --git a/tools/merge-locales.sh b/tools/merge-locales.sh index 8fc5c75..21d2632 100755 --- a/tools/merge-locales.sh +++ b/tools/merge-locales.sh @@ -2,9 +2,11 @@ for locale in `ls locales/*.json`; do - file = basename $locale; + file=$(basename $locale); if [ -f locales/tmp/$file ]; then jq -s '.[0] * .[1]' $locale locales/tmp/$file > locales/tmp/tmp.json; mv locales/tmp/tmp.json $locale; fi; done; + +rm -r locales/tmp/ From a1ce8049957bfb4388a12f3cec64e1309ed6d15a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 12 Oct 2022 16:29:20 +0200 Subject: [PATCH 4/4] clean up --- branding/locales/de.json | 8 -------- tools/test/file1.json | 12 ------------ tools/test/file2.json | 11 ----------- tools/test/result.json | 15 --------------- 4 files changed, 46 deletions(-) delete mode 100644 branding/locales/de.json delete mode 100644 tools/test/file1.json delete mode 100644 tools/test/file2.json delete mode 100644 tools/test/result.json diff --git a/branding/locales/de.json b/branding/locales/de.json deleted file mode 100644 index 8f42e89..0000000 --- a/branding/locales/de.json +++ /dev/null @@ -1,8 +0,0 @@ -{ -"user": { - "avatar": { - "submitted": "XXXXXXX" - } - }, - "new-key": "This is a new key" -} diff --git a/tools/test/file1.json b/tools/test/file1.json deleted file mode 100644 index 19ec4e1..0000000 --- a/tools/test/file1.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "a-key": "A", - "b-key": { - "a-subkey": "A", - "b-subkey": "B", - "c-subkey": { - "a-subsubkey": "A", - "b-subsubkey": "B" - } - }, - "c-key": "C" -} diff --git a/tools/test/file2.json b/tools/test/file2.json deleted file mode 100644 index e4d7ade..0000000 --- a/tools/test/file2.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "a-key": "AA", - "b-key": { - "b-subkey": "BB", - "c-subkey": { - "b-subsubkey": "BB", - "c-subsubkey": "C" - } - }, - "d-key": "D" -} diff --git a/tools/test/result.json b/tools/test/result.json deleted file mode 100644 index 843c235..0000000 --- a/tools/test/result.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "a-key": "AA", - "b-key": { - "a-subkey": "A", - "b-subkey": "BB", - "c-subkey": { - "a-subsubkey": "A", - "b-subsubkey": "BB", - "c-subsubkey": "C" - } - }, - "c-key": "C", - "d-key": "D" -} -