diff --git a/admin/package.json b/admin/package.json index 9d70c0b06..c94d0a2b0 100644 --- a/admin/package.json +++ b/admin/package.json @@ -12,7 +12,8 @@ "dev": "yarn run serve", "build": "vue-cli-service build", "lint": "eslint --ext .js,.vue .", - "test": "jest --coverage" + "test": "jest --coverage", + "locales": "scripts/missing-keys.sh && scripts/sort.sh" }, "dependencies": { "@babel/core": "^7.15.8", diff --git a/admin/scripts/missing-keys.sh b/admin/scripts/missing-keys.sh new file mode 100755 index 000000000..6dbaee897 --- /dev/null +++ b/admin/scripts/missing-keys.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +ROOT_DIR=$(dirname "$0")/.. + +sorting="jq -f $ROOT_DIR/scripts/sort_filter.jq" +english="$sorting $ROOT_DIR/src/locales/en.json" +german="$sorting $ROOT_DIR/src/locales/de.json" +listPaths="jq -c 'path(..)|[.[]|tostring]|join(\".\")'" +diffString="<( $english | $listPaths ) <( $german | $listPaths )" +if eval "diff -q $diffString"; +then + : # all good +else + eval "diff -y $diffString | grep '[|<>]'"; + printf "\nEnglish and German translation keys do not match, see diff above.\n" + exit 1 +fi diff --git a/admin/scripts/sort.sh b/admin/scripts/sort.sh new file mode 100755 index 000000000..e5c5c41c6 --- /dev/null +++ b/admin/scripts/sort.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +ROOT_DIR=$(dirname "$0")/.. + +tmp=$(mktemp) +exit_code=0 + +for locale_file in $ROOT_DIR/src/locales/*.json +do + jq -f $(dirname "$0")/sort_filter.jq $locale_file > "$tmp" + if [ "$*" == "--fix" ] + then + mv "$tmp" $locale_file + else + if diff -q "$tmp" $locale_file > /dev/null ; + then + : # all good + else + exit_code=$? + echo "$(basename -- $locale_file) is not sorted by keys" + fi + fi +done + +exit $exit_code diff --git a/admin/scripts/sort_filter.jq b/admin/scripts/sort_filter.jq new file mode 100644 index 000000000..9d108f8f0 --- /dev/null +++ b/admin/scripts/sort_filter.jq @@ -0,0 +1,13 @@ +def walk(f): + . as $in + | if type == "object" then + reduce keys_unsorted[] as $key + ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f + elif type == "array" then map( walk(f) ) | f + else f + end; + +def keys_sort_by(f): + to_entries | sort_by(.key|f ) | from_entries; + +walk(if type == "object" then keys_sort_by(ascii_upcase) else . end) \ No newline at end of file diff --git a/admin/src/i18n.js b/admin/src/i18n.js index 7ccfec4c9..b72734d1f 100644 --- a/admin/src/i18n.js +++ b/admin/src/i18n.js @@ -5,8 +5,10 @@ Vue.use(VueI18n) const loadLocaleMessages = () => { const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i) + console.log(locales) const messages = {} locales.keys().forEach((key) => { + console.log(key) const matched = key.match(/([A-Za-z0-9-_]+)\./i) if (matched && matched.length > 1) { const locale = matched[1] diff --git a/admin/src/locales/de.json b/admin/src/locales/de.json index 0967ef424..72d5f685a 100644 --- a/admin/src/locales/de.json +++ b/admin/src/locales/de.json @@ -1 +1,4 @@ -{} +{ + "open_creations":"offene Schöpfungen", + "not_open_creations":"keine offene Schöpfungen" +} diff --git a/admin/src/locales/en.json b/admin/src/locales/en.json index 0967ef424..bbde7b043 100644 --- a/admin/src/locales/en.json +++ b/admin/src/locales/en.json @@ -1 +1,4 @@ -{} +{ + "open_creations":"open creations", + "not_open_creations":"not open creations" +} \ No newline at end of file diff --git a/admin/src/locales/index.js b/admin/src/locales/index.js new file mode 100644 index 000000000..4cb375b40 --- /dev/null +++ b/admin/src/locales/index.js @@ -0,0 +1,16 @@ +const locales = [ + { + name: 'English', + code: 'en', + iso: 'en-US', + enabled: true, + }, + { + name: 'Deutsch', + code: 'de', + iso: 'de-DE', + enabled: true, + }, +] + +export default locales diff --git a/admin/src/pages/Overview.vue b/admin/src/pages/Overview.vue index 9b609c3ef..ed7ac8ad7 100644 --- a/admin/src/pages/Overview.vue +++ b/admin/src/pages/Overview.vue @@ -3,7 +3,7 @@