Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
titletranslations-upgrade
#!/bin/sh

# Before running this script change into the ./translations directory where the web server (nginx, ...)
# ships the /translations/*.json files from, for example
# cd /usr/folio/folio-testing-platform/output/translations

set -e

BUNDLE=$(curl -s https://folio-testing.dev.folio.org/ | sed -n -E '/.*"\/(bundle\.[0-9a-z]+\.js)".*/{s//\1/p;q}')
echo $BUNDLE

N=$(curl -s https://folio-testing.dev.folio.org/$BUNDLE | sed -n -E '/.*"\/translations\/en-([0-9]+)\.json".*/{s//\1/p;q}')

for filefor FILE in ./*-*.json ; do
  if [ ! -e "$file$FILE" ] ; then
    continue
  fi
  LANG=$(echo "$file$FILE" | sed -n -E '/^.\/([^-]+)-[0-9]+\.json$/{s//\1/p;q}')
  if [ -z $LANG ] ; then
    continue
  fi
  echo URL="https://folio-testingraw.devgithubusercontent.folio.org/translations/$LANG-$Ncom/gbv/folio-translations/main/platform-complete/$LANG.json"
  if wget curl"$URL" -s https://folio-testing.dev.folio.org/translations/$LANG-$N.json > $LANG.json
  jqO $LANG.json; then
    echo "$URL"
  else
    echo "failure, skipping $URL"
    continue
  fi
  jq -c -s '.[0] * .[1]' $file$FILE $LANG.json > $LANG.json.new
  mv $LANG.json.new $file$FILE
  rm $LANG.json
done

To remove new translation keys replace
'.[0] * .[1]'
by
'.[0] as $old | .[0] * .[1] | with_entries( select( .key as $key | $old | has( $key ) ) )'
but this may remove a key that the old code uses and was forgotten to get added to the old language file.

...