2022-07-13 09:55:29 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-27 09:29:05 +00:00
|
|
|
# Format and update translations from a source file (en_US.json by default).
|
|
|
|
# Requires jq (https://stedolan.github.io/jq/)
|
2022-07-13 09:55:29 +00:00
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
SOURCE=en_US.json
|
|
|
|
PREFIX=_TSTR_
|
|
|
|
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
LOCALES_DIR="${SCRIPT_DIR}/../src/musikcube/data/locales"
|
|
|
|
TEMPFILE=$(mktemp -p ${TMPDIR:-/tmp} $(basename "${0}").XXXXX)
|
2022-07-27 09:29:05 +00:00
|
|
|
PREFIXDFILE=$(mktemp -p ${TMPDIR:-/tmp} $(basename "${0}").XXXXX)
|
2022-07-13 09:55:29 +00:00
|
|
|
|
|
|
|
trap cleanup 0 1 2 3 5
|
|
|
|
|
|
|
|
cleanup() {
|
2022-07-27 09:29:05 +00:00
|
|
|
rm -f "${PREFIXDFILE}" "${TEMPFILE}"
|
2022-07-13 09:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Sort $SOURCE translations file alphabetically by keys.
|
2022-07-27 09:29:05 +00:00
|
|
|
jq -S . "${LOCALES_DIR}/${SOURCE}" > "${TEMPFILE}"
|
|
|
|
mv "${TEMPFILE}" "${LOCALES_DIR}/${SOURCE}"
|
2022-07-13 09:55:29 +00:00
|
|
|
|
|
|
|
# Generate a temporary translations file prefixing all values with ${PREFIX}
|
|
|
|
# to indicate missing translations.
|
|
|
|
awk -F'": ' -v prefix="${PREFIX}" \
|
|
|
|
'/: "/{sub("\"", "\"" prefix, $2);print $1 "\": " $2;next} {print}' \
|
|
|
|
"${LOCALES_DIR}/${SOURCE}" \
|
2022-07-27 09:29:05 +00:00
|
|
|
> "${PREFIXDFILE}" \
|
|
|
|
# awk > $PREFIXDFILE
|
2022-07-13 09:55:29 +00:00
|
|
|
|
|
|
|
# Merge language specific translations fle with temporary translations file,
|
|
|
|
# adding any missing translations from ${SOURCE}, prefixed with ${PREFIX}.
|
|
|
|
for JSON in $(git ls-files "${LOCALES_DIR}" | grep -v "${SOURCE}"); do
|
2022-07-27 09:29:05 +00:00
|
|
|
jq -Ss '.[0] * .[1]' "${PREFIXDFILE}" "${JSON}" > "${TEMPFILE}"
|
|
|
|
mv "${TEMPFILE}" "${JSON}"
|
2022-07-13 09:55:29 +00:00
|
|
|
done
|