Commit c6847ad5 authored by Peter Serwylo's avatar Peter Serwylo

Only render languages which are 100% translated in the "Website" project

parent 690f48ff
# This file is automatically generated by tools/update_langs.sh
SUPPORTED_LANGS="en ast bo de es es_AR fa fr sc tr zh_Hans zh_Hant"
SUPPORTED_LANGS="en de es es_AR fr sc tr zh_Hans zh_Hant"
......@@ -107,11 +107,19 @@ git merge weblate-website/master
```
Once the translations are available, we need to update the `_config.yml` to ensure it is aware of the translations which are available.
The following script will update the `languages: [ 'en', ... ]` attribute in the config file.
In addition, it will also attempt to download a flag for any new translations for the language chooser widget:
The following script will update the `languages: [ 'en', ... ]` attribute in the config file to those which are marked as 100% translated
in the ["Website" project on Weblate](https://hosted.weblate.org/projects/f-droid/website/):
```bash
./tools/update_langs.py
$ ./tools/update_langs.py
```
For development, you can also request all translations be included, regardless of how complete they are:
```bash
./tools/update_langs.py --partial
```
### Documentation + Website News
......@@ -157,4 +165,4 @@ instead of what it should be:
```
If so, the `hook-json_restore_hierarchy` [script needs to be configured correctly](https://docs.weblate.org/en/latest/formats.html#json-files) in Weblate.
This script can also be downloaded and run locally on the problem file, e.g. `hook-json_restore_hierarchy _data/[LANG]/strings.json`.
\ No newline at end of file
This script can also be downloaded and run locally on the problem file, e.g. `hook-json_restore_hierarchy _data/[LANG]/strings.json`.
......@@ -27,5 +27,5 @@ fdroid-repo: https://f-droid.org/repo
# The "languages" entry is automatically overridden by the tools/update_langs.sh script when
# new translations become available.
languages: [ "en", "ast", "bo", "de", "es", "es_AR", "fa", "fr", "sc", "tr", "zh_Hans", "zh_Hant" ]
languages: [ "en", "de", "es", "es_AR", "fr", "sc", "tr", "zh_Hans", "zh_Hant" ]
default_lang: "None. This forces jekyll polyglot to generate a en/ subdirectory too (with correct links)."
......@@ -133,7 +133,7 @@ This ensures that each `.html` file is replaced with an Apache2 [TypeMap](https:
The second is to add the following to the Apache2 server or VirtualHost config so that the TypeMaps are used correctly,
telling apache where to find the translated version of the file (replace `/var/www/html` with the actual webroot):
```apacheconfig
```
<Files *.html>
SetHandler type-map
</Files>
......@@ -152,4 +152,4 @@ If this is not done or done incorrectly, then you will see something like the fo
This is the result of the actual TypeMap being returned to the browser, rather than the translated file.
Note that this also depends on `mod_alias` and `mod_negotiation` being enabled, but this happens by default when
installing apache2 on Debian.
\ No newline at end of file
installing apache2 on Debian.
......@@ -6,6 +6,14 @@ set -eu -o pipefail
DIR=`dirname $0`
JEKYLL_DIR=${DIR}/../
# The default behaviour is to only include languages where `_data/LANG/strings.json` is 100% translated.
# This can be overriden by "--partial", to include any langugae with at least a single translation.
if [[ $# == 1 && $1 == "--partial" ]]; then
INCLUDE_PARTIAL=true
else
INCLUDE_PARTIAL=false
fi
#
# For each directory `_data/[LANG]/ which contains a `strings.json` file, we take LANG and add it to our config file so
# that Jekyll knows to generate a site for that language.
......@@ -14,6 +22,13 @@ function update_langs_in_config {
LANGS_FOR_YAML='"en"'
LANGS_FOR_SH='en'
if [ ${INCLUDE_PARTIAL} == true ]; then
echo "Including only partially translated languages"
else
echo "Consulting Weblate to figure out 100% transtlated languages"
FULLY_TRANSLATED_LANGS=`get_fully_translated_langs_from_weblate`
fi
for I18N_DIR in `find ${JEKYLL_DIR}/_data/*/ -name 'strings.json' -printf '%h\n' | sort -u`; do
# Check if string contains $LANG already or not: http://stackoverflow.com/a/229606/2391921
......@@ -22,32 +37,42 @@ function update_langs_in_config {
# Check the diff between original strings.json and translated one. If no difference, then bail.
DIFF2=`diff --ignore-all-space ${I18N_DIR}/strings.json ${JEKYLL_DIR}/_data/strings.json | wc -l || true`
if [ ${DIFF2} == "0" ]; then
echo "Ignoring untranslated ${LANG}/strings.json"
echo "Ignoring completely untranslated ${LANG}/strings.json"
continue;
fi
if [ ${INCLUDE_PARTIAL} == false ]; then
IN_WEBLATE=`echo ${FULLY_TRANSLATED_LANGS} | grep --only-matching "\<$LANG\>" | wc -l || true`
if [ ${IN_WEBLATE} == "0" ]; then
echo "Ignoring not-yet-fully-translated ${LANG}/strings.json"
continue;
fi
fi
if [[ ${LANGS_FOR_YAML} != *"$LANG"* ]]; then
LANGS_FOR_YAML="$LANGS_FOR_YAML, \"$LANG\""
LANGS_FOR_SH="$LANGS_FOR_SH $LANG"
fi
done
for PO in `ls ${JEKYLL_DIR}/po/*.*.po`; do
PO_FILE=`basename ${PO}`
LANG=`echo ${PO_FILE} | sed -e "s|.*\.\(.*\)\.po|\1|"`
if [ ${INCLUDE_PARTIAL} == true ]; then
for PO in `ls ${JEKYLL_DIR}/po/*.*.po`; do
PO_FILE=`basename ${PO}`
LANG=`echo ${PO_FILE} | sed -e "s|.*\.\(.*\)\.po|\1|"`
# Check the number of messages in the .po file which have been translated. If none, then bail.
TRANSLATED=`msgattrib --translated ${JEKYLL_DIR}/po/${PO_FILE} | wc -l`
if [ ${TRANSLATED} == "0" ]; then
echo "Ignoring untranslated $PO_FILE"
continue;
fi
# Check the number of messages in the .po file which have been translated. If none, then bail.
TRANSLATED=`msgattrib --translated ${JEKYLL_DIR}/po/${PO_FILE} | wc -l`
if [ ${TRANSLATED} == "0" ]; then
echo "Ignoring completely untranslated $PO_FILE"
continue;
fi
if [[ ${LANGS_FOR_YAML} != *"$LANG"* ]]; then
LANGS_FOR_YAML="$LANGS_FOR_YAML, \"$LANG\""
LANGS_FOR_SH="$LANGS_FOR_SH $LANG"
fi
done
if [[ ${LANGS_FOR_YAML} != *"$LANG"* ]]; then
LANGS_FOR_YAML="$LANGS_FOR_YAML, \"$LANG\""
LANGS_FOR_SH="$LANGS_FOR_SH $LANG"
fi
done
fi
echo "Updating languages to: ${LANGS_FOR_YAML}"
sed -i "s/^languages: \[.*\]/languages: [ ${LANGS_FOR_YAML} ]/" ${JEKYLL_DIR}/_config.yml
......@@ -59,4 +84,13 @@ SUPPORTED_LANGS="${LANGS_FOR_SH}"
SH
}
function get_fully_translated_langs_from_weblate {
# The CSV from Weblate contains the following header row:
# name,code,total,translated,translated_percent,total_words,translated_words,failing,failing_percent,fuzzy,fuzzy_percent,url_translate,url,last_change,last_author
# where the columns of interest are $5 (translated_percent) and $2 (code).
curl --silent https://hosted.weblate.org/exports/stats/f-droid/website/\?format\=csv | \
tail -n +2 | \
awk -F ',' '{ if ($5 == "100.0") print $2 }'
}
update_langs_in_config
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment