3afa2fcdf3
In the GUIs, on the language-select screen, show e.g.
Czech (100%), Danish (13%), Dutch (54%)
instead of
Czech, Danish, Dutch
- we count the source strings when creating the .pot PO-template file
and add an "X-Electrum-SourceStringCount" header to it, in the push_locale.py script that uploads the .pot file to crowdin.
- later, when we run electrum-locale/update.py to download the translations in .po files, these files will also contain the same header.
- then when the build_locale.sh script compiles those .po files, we can read the header and use it to populate a new "stats.json" file
that we place in electrum/locale/locale/ and bundle in the all release binaries/distributables.
- stats.json also includes the number of translated strings for each lang
- at runtime we simply read stats.json and use the values to calculate the percentages
- a prior implementation did not pre-calc stats.json but did all calculations at runtime (by opening all .mo translations)
- however that was deemed to slow, hence the build-time pre-calc
- runtime calc took 40 ms on my laptop, so I guess it could easily take 10x that on an old phone
- just as we have always been very tolerant of any locale files or even the whole locale/ dir missing, we also tolerate stats.json missing
37 lines
888 B
Bash
Executable File
37 lines
888 B
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# This script converts human-readable (.po) locale files to compiled (.mo) locale files.
|
|
|
|
set -e
|
|
|
|
CONTRIB_LOCALE="$(dirname "$(realpath "$0" 2> /dev/null || grealpath "$0")")"
|
|
|
|
|
|
if [[ ! -d "$1" || -z "$2" ]]; then
|
|
echo "usage: $0 locale_source_dir locale_dest_dir"
|
|
echo " The dirs can match, to build in place."
|
|
# ^ note: these are the paths to the "inner" locale/ dir
|
|
exit 1
|
|
fi
|
|
|
|
# convert $1 and $2 to abs paths
|
|
SRC_DIR="$(realpath "$1" 2> /dev/null || grealpath "$1")"
|
|
DST_DIR="$(realpath "$2" 2> /dev/null || grealpath "$2")"
|
|
|
|
if ! which msgfmt > /dev/null 2>&1; then
|
|
echo "Please install gettext"
|
|
exit 1
|
|
fi
|
|
|
|
cd "$SRC_DIR"
|
|
mkdir -p "$DST_DIR"
|
|
|
|
for i in *; do
|
|
dir="$DST_DIR/$i/LC_MESSAGES"
|
|
mkdir -p "$dir"
|
|
(msgfmt --output-file="$dir/electrum.mo" "$i/electrum.po" || true)
|
|
done
|
|
|
|
echo "running stats.py"
|
|
"$CONTRIB_LOCALE/stats.py"
|