From b99e95304eb2819fdfb3552fbcd2f3ec312d24a9 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 10:36:15 +0200 Subject: [PATCH 01/13] remove pull-trans.sh, weblate is merged via merge requests now gitlab handles the squashing, then we have a publicly available history of the unsquashed commits in the merge request. --- tools/pull-trans.sh | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100755 tools/pull-trans.sh diff --git a/tools/pull-trans.sh b/tools/pull-trans.sh deleted file mode 100755 index c1144081c..000000000 --- a/tools/pull-trans.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -# This script pulls translations from weblate. -# -# It squashes all the changes into a single commit. This removes authorship -# from the changes, which is given to the Translatebot, so to keep the names -# they are grabbed from git log and added to the commit message. -# -# Note that this will apply changes and commit them! Make sure to not have -# uncommited changes when running this script. - -REMOTE="weblate" -REMOTE_URL="git://git.weblate.org/f-droid.git" -REMOTE_BRANCH="master" - -AUTHOR="F-Droid Translatebot " - -if ! git ls-remote --exit-code $REMOTE >/dev/null 2>/dev/null; then - echo "Remote doesn't exist! Try the following:" - echo " git remote add $REMOTE $REMOTE_URL" - echo " git fetch $REMOTE" - exit 1 -fi - -ref="${REMOTE}/${REMOTE_BRANCH}" -diff="HEAD...$ref -- */values-*/strings.xml" - -authors=$(git log --format="%s %an" $diff | \ - sed 's/.* using Weblate (\(.*\)) \(.*\)/\2||\1/' | sort -f -u | column -s '||' -t) - -git diff $diff | git apply - -git add */values-*/strings.xml - -git commit --author "$AUTHOR" -m "Pull translation updates from Weblate - -Translators: - -$authors" From 082b6091fc2038bc7ef3c02cf401ee122658b033 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 11:01:50 +0200 Subject: [PATCH 02/13] move all translation scripts to tools/ I think we should just move all the scripts to tools/, app/tools is confusing, not very visible, and non-standard. --- .gitlab-ci.yml | 2 +- .../check-format-strings.py | 0 .../remove-unused-and-blank-translations.py | 10 +++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) rename app/tools/check-string-format.py => tools/check-format-strings.py (100%) rename app/tools/remove-unused-trans.py => tools/remove-unused-and-blank-translations.py (65%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 23e1f7776..2a6ff1d88 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ before_script: test: script: - - ./app/tools/check-string-format.py + - ./tools/check-format-strings.py - ./gradlew assemble -PdisablePreDex # always report on lint errors to the build log - sed -i -e 's,textReport .*,textReport true,' app/build.gradle diff --git a/app/tools/check-string-format.py b/tools/check-format-strings.py similarity index 100% rename from app/tools/check-string-format.py rename to tools/check-format-strings.py diff --git a/app/tools/remove-unused-trans.py b/tools/remove-unused-and-blank-translations.py similarity index 65% rename from app/tools/remove-unused-trans.py rename to tools/remove-unused-and-blank-translations.py index 7863c2774..d623d7f56 100755 --- a/app/tools/remove-unused-trans.py +++ b/tools/remove-unused-and-blank-translations.py @@ -1,19 +1,23 @@ #!/usr/bin/env python3 -# Remove extra translations +# This script removes strings from the translated files that are not useful: +# * translations for strings that are no longer used +# * empty translated strings, English is better than no text at all import glob import os import re from xml.etree import ElementTree +resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res') + strings = set() -for e in ElementTree.parse(os.path.join('src', 'main', 'res', 'values', 'strings.xml')).getroot().findall('.//string'): +for e in ElementTree.parse(os.path.join(resdir, 'values', 'strings.xml')).getroot().findall('.//string'): name = e.attrib['name'] strings.add(name) -for d in glob.glob(os.path.join('src', 'main', 'res', 'values-*')): +for d in glob.glob(os.path.join(resdir, 'values-*')): str_path = os.path.join(d, 'strings.xml') if os.path.exists(str_path): From 3df626aed106d23a5a2090659141cb00dbf81dc8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 11:12:48 +0200 Subject: [PATCH 03/13] sync up translation scripts to use the same code To keep these scripts simple and readible, it makes sense to keep them as separate scripts. But they should use the same approach as much as possible. --- tools/check-format-strings.py | 4 +- tools/remove-unused-and-blank-translations.py | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tools/check-format-strings.py b/tools/check-format-strings.py index 00395e118..feb9af199 100755 --- a/tools/check-format-strings.py +++ b/tools/check-format-strings.py @@ -13,11 +13,11 @@ formatRe = re.compile(r'(%%|%[^%](\$.)?)') validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$') oddQuotingRe = re.compile(r'^"\s*(.+?)\s*"$') -projectdir = os.path.join(os.path.dirname(__file__), '..') +resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res') count = 0 -for d in sorted(glob.glob(os.path.join(projectdir, 'src', 'main', 'res', 'values-*'))): +for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))): str_path = os.path.join(d, 'strings.xml') if not os.path.exists(str_path): diff --git a/tools/remove-unused-and-blank-translations.py b/tools/remove-unused-and-blank-translations.py index d623d7f56..3ef71036d 100755 --- a/tools/remove-unused-and-blank-translations.py +++ b/tools/remove-unused-and-blank-translations.py @@ -10,34 +10,35 @@ import re from xml.etree import ElementTree resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res') +sourcepath = os.path.join(resdir, 'values', 'strings.xml') strings = set() - -for e in ElementTree.parse(os.path.join(resdir, 'values', 'strings.xml')).getroot().findall('.//string'): +for e in ElementTree.parse(sourcepath).getroot().findall('.//string'): name = e.attrib['name'] strings.add(name) -for d in glob.glob(os.path.join(resdir, 'values-*')): +for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))): str_path = os.path.join(d, 'strings.xml') - if os.path.exists(str_path): - header = '' - with open(str_path, 'r') as f: - header = f.readline() - tree = ElementTree.parse(str_path) - root = tree.getroot() + if not os.path.exists(str_path): + continue - elems = root.findall('.//string') - for e in elems: - name = e.attrib['name'] - if name not in strings: - root.remove(e) - if not e.text: - root.remove(e) + header = '' + with open(str_path, 'r') as f: + header = f.readline() + tree = ElementTree.parse(str_path) + root = tree.getroot() - result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8')) + for e in root.findall('.//string'): + name = e.attrib['name'] + if name not in strings: + root.remove(e) + if not e.text: + root.remove(e) - with open(str_path, 'w+') as f: - f.write(header) - f.write(result) - f.write('\n') + result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8')) + + with open(str_path, 'w+') as f: + f.write(header) + f.write(result) + f.write('\n') From 38403338da1ee858fb9fd53b206500c8cd7bce0b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 11:47:38 +0200 Subject: [PATCH 04/13] remove xmlns tools:ignore from translations XML namespaces are a massive pain to deal with in, and they are totally unneeded in the translation files. xmlns:tools is only needed in the source file to ignore some lint warnings. --- app/src/main/res/values-kn/strings.xml | 10 +++++----- tools/remove-unused-and-blank-translations.py | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/values-kn/strings.xml b/app/src/main/res/values-kn/strings.xml index ea8e0a014..cb719008f 100644 --- a/app/src/main/res/values-kn/strings.xml +++ b/app/src/main/res/values-kn/strings.xml @@ -1,5 +1,5 @@ -ಎಫ್-ಡ್ರಾಯ್ಡ್ +ಎಫ್-ಡ್ರಾಯ್ಡ್ ಆವೃತ್ತಿ ಅನುಸ್ಥಾಪಿಸು @@ -31,10 +31,10 @@ ನನ್ನ ಹತ್ತಿರವಿರುವ ಜನರನ್ನು ಹುಡುಕು ಅನುಸ್ಥಾಪಿಸಲಾಗುತ್ತಿದೆ… ಅನುಸ್ಥಾಪಿಸು - ಸಮಯ - ಸುರಕ್ಷತೆ - ಕ್ರೀಡೆ & ಆರೋಗ್ಯ - ಆಟಗಳು + ಸಮಯ + ಸುರಕ್ಷತೆ + ಕ್ರೀಡೆ & ಆರೋಗ್ಯ + ಆಟಗಳು ವೈ-ಫೈ ಭಾಷೆ ಹೆಸರು diff --git a/tools/remove-unused-and-blank-translations.py b/tools/remove-unused-and-blank-translations.py index 3ef71036d..811305bfa 100755 --- a/tools/remove-unused-and-blank-translations.py +++ b/tools/remove-unused-and-blank-translations.py @@ -26,8 +26,14 @@ for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))): header = '' with open(str_path, 'r') as f: header = f.readline() - tree = ElementTree.parse(str_path) - root = tree.getroot() + + # handling XML namespaces in Python is painful, just remove them, they + # should not be in the translation files anyway + with open(str_path, 'rb') as fp: + contents = fp.read() + contents = contents.replace(b' tools:ignore="UnusedResources"', b'') \ + .replace(b' xmlns:tools="http://schemas.android.com/tools"', b'') + root = ElementTree.fromstring(contents) for e in root.findall('.//string'): name = e.attrib['name'] From 2ef9b279a848b15ebea7790f8b8ac5074657dfb6 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 11:47:51 +0200 Subject: [PATCH 05/13] remove all blank items from plurals --- app/src/main/res/values-be/strings.xml | 15 +++++---------- app/src/main/res/values-pl/strings.xml | 15 +++++---------- app/src/main/res/values-ru/strings.xml | 15 +++++---------- app/src/main/res/values-uk/strings.xml | 3 +-- tools/remove-unused-and-blank-translations.py | 5 +++++ 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/app/src/main/res/values-be/strings.xml b/app/src/main/res/values-be/strings.xml index 297bf25c0..228d1455e 100644 --- a/app/src/main/res/values-be/strings.xml +++ b/app/src/main/res/values-be/strings.xml @@ -466,8 +466,7 @@ Убачыць %d праграму Убачыць усе %d праграмы Убачыць усе %d праграм - - + Версія %1$s (рэкамендуецца) Новая @@ -486,8 +485,7 @@ Паказаць %1$s праграму ў катэгорыі %2$s Паказаць %1$s праграмы ў катэгорыі %2$s Паказаць %1$s праграм ў катэгорыі %2$s - - + Абнавіць Абнавіць %1$s @@ -497,8 +495,7 @@ Выпушчана %1$d дзень таму Выпушчана %1$d дня таму Выпушчана %1$d дзён таму - - + Спампаваць Спампаваць усе абнаўленні @@ -510,8 +507,7 @@ Спампаваць абнаўленне для %1$d праграмы. Спампаваць абнаўленні для %1$d праграм. Спампаваць абнаўленні для %1$d праграм. - - + Навае ў версіі %s @@ -520,8 +516,7 @@ Абноўлена %1$s дзень таму Абноўлена %1$s дні таму Абноўлена %1$s дзён таму - - + Гэтая праграма мае функцыі, што могуць вам не спадабацца. %1$s паспяхова ўсталявана Няма інтэрнэту? Пампуйце праграмы ад людзей diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 2e09d63e2..c34768201 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -449,8 +449,7 @@ Zobacz %d aplikację Zobacz wszystkie %d aplikacje Zobacz wszystkich %d aplikacji - - + Wersja %1$s (zalecana) Nowa @@ -470,8 +469,7 @@ Pokaż %1$d aplikację w kategorii %2$s Pokaż wszystkie %1$s aplikacje w kategorii %2$s Pokaż wszystkich %1$s aplikacji w kategorii %2$s - - + Aktualizuj Aktualizuj %1$s @@ -481,8 +479,7 @@ Wydano %1$d dzień temu Wydano %1$d dni temu Wydano %1$d dni temu - - + Pobierz Pobierz wszystkie aktualizacje @@ -494,8 +491,7 @@ Pobierz aktualizację dla %1$d aplikacji. Pobierz aktualizacje dla %1$d aplikacji. Pobierz aktualizacje dla %1$d aplikacji. - - + Nowe w wersji %s @@ -506,8 +502,7 @@ Uaktualniono %1$s dzień temu Uaktualniono %1$s dni temu Uaktualniono %1$s dni temu - - + %1$s pomyślnie zainstalowano Brak internetu? Pobierz aplikacje od ludzi w pobliżu! diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 5f9818a36..decdb967c 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -454,8 +454,7 @@ Опубликовано %1$d день назад Опубликовано %1$d дня назад Опубликовано %1$d дней назад - - + Нет категорий для показа @@ -463,8 +462,7 @@ Посмотреть %d приложение Посмотреть %d приложения Посмотреть %d приложений - - + Нет интернета? Скачивайте приложения у людей рядом с вами! Готово к установке @@ -483,8 +481,7 @@ Обновлено %1$s день назад Обновлено %1$s дня назад Обновлено %1$s дней назад - - + %1$s создано %2$s. Купи им чашечку кофе! Версия %1$s (Рекомендуемая) @@ -494,8 +491,7 @@ Скачать обновления для %1$d приложения. Скачать обновления для %1$d приложений. Скачать обновления для %1$d приложений. - - + Обновить %1$s Установить %1$s @@ -521,8 +517,7 @@ Посмотреть %1$d приложение в категории %2$s Посмотреть %1$d приложения в категории %2$s Посмотреть %1$d приложений в категории %2$s - - + Нет недавних приложений Обоим участникам нужен %1$s чтобы передавать приложения. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 7e1654a35..5a6ceb3d9 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -508,8 +508,7 @@ Завантажити оновлення для %1$d додатку. Завантажити оновлення для %1$d додатка. Завантажити оновлення для %1$d додатків. - - + Нове у версії %s diff --git a/tools/remove-unused-and-blank-translations.py b/tools/remove-unused-and-blank-translations.py index 811305bfa..31f75679d 100755 --- a/tools/remove-unused-and-blank-translations.py +++ b/tools/remove-unused-and-blank-translations.py @@ -42,6 +42,11 @@ for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))): if not e.text: root.remove(e) + for e in root.findall('.//plurals'): + for item in e.findall('item'): + if not item.text: + e.remove(item) + result = re.sub(r' />', r'/>', ElementTree.tostring(root, encoding='utf-8').decode('utf-8')) with open(str_path, 'w+') as f: From eff483d73e877c552a60b395846fc7769eecc1b8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 11:51:26 +0200 Subject: [PATCH 06/13] gitlab-ci: fail if translation strings need corrections Since we have all these lovely scripts for cleaning up the translations, gitlab-ci is a handy way to enforce that they get used. Since weblate merges happen via merge requests, this will work nicely now. I can't think of any false positives that will arise, but we shall find out! --- .gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2a6ff1d88..afb30fd94 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,6 +13,8 @@ before_script: test: script: - ./tools/check-format-strings.py + - ./tools/remove-unused-and-blank-translations.py + - git diff | grep diff && false # there should be no changes - ./gradlew assemble -PdisablePreDex # always report on lint errors to the build log - sed -i -e 's,textReport .*,textReport true,' app/build.gradle From 151c83218c7ab016c51380ae8bd1369d1c39473c Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 13:24:20 +0200 Subject: [PATCH 07/13] do not crash if there are no cached APKs closes #1012 --- .../fdroid/fdroid/AppUpdateStatusService.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusService.java b/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusService.java index 76e2eb2a4..e6b821099 100644 --- a/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusService.java +++ b/app/src/main/java/org/fdroid/fdroid/AppUpdateStatusService.java @@ -44,11 +44,22 @@ public class AppUpdateStatusService extends IntentService { @Override protected void onHandleIntent(@Nullable Intent intent) { Utils.debugLog(TAG, "Scanning apk cache to see if we need to prompt the user to install any apks."); - List apksReadyToInstall = new ArrayList<>(); File cacheDir = ApkCache.getApkCacheDir(this); - for (String repoDirName : cacheDir.list()) { + if (cacheDir == null) { + return; + } + String[] cacheDirList = cacheDir.list(); + if (cacheDirList == null) { + return; + } + List apksReadyToInstall = new ArrayList<>(); + for (String repoDirName : cacheDirList) { File repoDir = new File(cacheDir, repoDirName); - for (String apkFileName : repoDir.list()) { + String[] apks = repoDir.list(); + if (apks == null) { + continue; + } + for (String apkFileName : apks) { Apk apk = processDownloadedApk(new File(repoDir, apkFileName)); if (apk != null) { Log.i(TAG, "Found downloaded apk " + apk.packageName + ". Notifying user that it should be installed."); From 7702e72acb514d41e5d4b13d6c7f085edcdd71da Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 13:45:50 +0200 Subject: [PATCH 08/13] move lint config to lint.xml to enable ignoring specific files --- app/build.gradle | 8 +------- app/lint.xml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 app/lint.xml diff --git a/app/build.gradle b/app/build.gradle index 4207db0ea..8d5a70fee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -245,13 +245,7 @@ android { xmlReport false textReport false - // Our translations are crowd-sourced - disable 'MissingTranslation' - - // to make CI fail on errors until this is fixed https://github.com/rtyley/spongycastle/issues/7 - warning 'InvalidPackage', 'ImpliedQuantity' - - error 'AppCompatMethod', 'NestedScrolling', 'StringFormatCount', 'UnsafeProtectedBroadcastReceiver' + lintConfig file("lint.xml") } packagingOptions { diff --git a/app/lint.xml b/app/lint.xml new file mode 100644 index 000000000..c0d2f2f10 --- /dev/null +++ b/app/lint.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + From 186d1dbabb89ab15600126b093da5a87b9e71b32 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 13:48:56 +0200 Subject: [PATCH 09/13] fix SetTextI18n lint warnings and set as error --- app/lint.xml | 6 ++++++ .../fdroid/fdroid/views/updates/items/AppNotification.java | 2 +- .../fdroid/fdroid/views/updates/items/DonationPrompt.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/lint.xml b/app/lint.xml index c0d2f2f10..4cbd014aa 100644 --- a/app/lint.xml +++ b/app/lint.xml @@ -13,4 +13,10 @@ + + + + + + diff --git a/app/src/main/java/org/fdroid/fdroid/views/updates/items/AppNotification.java b/app/src/main/java/org/fdroid/fdroid/views/updates/items/AppNotification.java index dadf209e5..6ae216250 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/updates/items/AppNotification.java +++ b/app/src/main/java/org/fdroid/fdroid/views/updates/items/AppNotification.java @@ -49,7 +49,7 @@ public class AppNotification extends AppUpdateData { } public void bindApp(AppNotification app) { - ((TextView) itemView).setText("Notification for app"); + ((TextView) itemView).setText(""); } } diff --git a/app/src/main/java/org/fdroid/fdroid/views/updates/items/DonationPrompt.java b/app/src/main/java/org/fdroid/fdroid/views/updates/items/DonationPrompt.java index 73e306b5f..697860703 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/updates/items/DonationPrompt.java +++ b/app/src/main/java/org/fdroid/fdroid/views/updates/items/DonationPrompt.java @@ -47,7 +47,7 @@ public class DonationPrompt extends AppUpdateData { } public void bindApp(DonationPrompt app) { - ((TextView) itemView).setText("Donation prompt for app"); + ((TextView) itemView).setText(""); } } From d1014f7b1f5243a51aa4a8feec7ce64fdb61adea Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 13:51:01 +0200 Subject: [PATCH 10/13] fix "Number formatting does not take into account locale settings." lint says "Consider using String.format instead." --- .../java/org/fdroid/fdroid/views/RepoDetailsActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java b/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java index 4a58aeac2..736655d2e 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java +++ b/app/src/main/java/org/fdroid/fdroid/views/RepoDetailsActivity.java @@ -27,7 +27,6 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; - import org.fdroid.fdroid.FDroidApp; import org.fdroid.fdroid.NfcHelper; import org.fdroid.fdroid.NfcNotEnabledActivity; @@ -39,6 +38,8 @@ import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.RepoProvider; import org.fdroid.fdroid.data.Schema.RepoTable; +import java.util.Locale; + public class RepoDetailsActivity extends ActionBarActivity { private static final String TAG = "RepoDetailsActivity"; @@ -323,7 +324,7 @@ public class RepoDetailsActivity extends ActionBarActivity { name.setText(repo.name); int appCount = RepoProvider.Helper.countAppsForRepo(this, repoId); - numApps.setText(Integer.toString(appCount)); + numApps.setText(String.format(Locale.getDefault(), "%d", appCount)); setupDescription(repoView, repo); setupRepoFingerprint(repoView, repo); From 6456f56ced97f9227cb8e80ac50397a47d0e338e Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 13:52:53 +0200 Subject: [PATCH 11/13] hide some lint warnings that cannot be fixed --- app/lint.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/lint.xml b/app/lint.xml index 4cbd014aa..52da393fb 100644 --- a/app/lint.xml +++ b/app/lint.xml @@ -14,6 +14,20 @@ + + + + + + + + + + + + + From 1b390cceca22a7919b9428668148d2f7c1c94fcb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 20:43:11 +0200 Subject: [PATCH 12/13] clear language setting if it matches the system-wide setting If the user can set the language using the Setting app, then there is not reason to use the Languages hack. This then clears the preference if it matches the language of the system-wide locale. This also removes the current system-wide language from the Languages menu. closes #943 --- app/src/main/java/org/fdroid/fdroid/Languages.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/fdroid/fdroid/Languages.java b/app/src/main/java/org/fdroid/fdroid/Languages.java index f7c47b368..30279c7ea 100644 --- a/app/src/main/java/org/fdroid/fdroid/Languages.java +++ b/app/src/main/java/org/fdroid/fdroid/Languages.java @@ -73,6 +73,9 @@ public final class Languages { } } + // remove the current system language from the menu + tmpMap.remove(currentLocale.getLanguage()); + /* SYSTEM_DEFAULT is a fake one for displaying in a chooser menu. */ tmpMap.put(USE_SYSTEM_DEFAULT, activity.getString(resId)); nameMap = Collections.unmodifiableMap(tmpMap); @@ -116,13 +119,21 @@ public final class Languages { } @TargetApi(17) + /** + * Handles setting the language if it is different than the current language, + * or different than the current system-wide locale. The preference is cleared + * if the language matches the system-wide locale or "System Default" is chosen. + */ public static void setLanguage(final ContextWrapper contextWrapper, String language, boolean refresh) { if (Build.VERSION.SDK_INT >= 24) { Utils.debugLog(TAG, "Languages.setLanguage() ignored on >= android-24"); Preferences.get().clearLanguage(); return; } - if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) { + if (TextUtils.equals(language, DEFAULT_LOCALE.getLanguage())) { + Preferences.get().clearLanguage(); + locale = DEFAULT_LOCALE; + } else if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) { return; // already configured } else if (language == null || language.equals(USE_SYSTEM_DEFAULT)) { Preferences.get().clearLanguage(); From 7c2125c248a064eeee14e1ab8a4e136526fbbbdd Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 10 May 2017 23:10:28 +0200 Subject: [PATCH 13/13] only remove incomplete translations if saved in a git remote --- ...rim-incomplete-translations-for-release.py | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/trim-incomplete-translations-for-release.py b/tools/trim-incomplete-translations-for-release.py index 75b6fd6ea..a56f173a2 100755 --- a/tools/trim-incomplete-translations-for-release.py +++ b/tools/trim-incomplete-translations-for-release.py @@ -1,9 +1,15 @@ #!/usr/bin/python3 +# +# WARNING! THIS DELETES TRANSLATIONS! +# +# The incomplete translations should be kept by rebasing the weblate +# remote on top of this commit, once its complete. import csv import git import os import requests +import sys projectbasedir = os.path.dirname(os.path.dirname(__file__)) @@ -11,7 +17,7 @@ print(projectbasedir) repo = git.Repo(projectbasedir) -msg = 'removing all translations less than 75% complete\n\n' +msg = 'removing all translations less than 70% complete\n\n' url = 'https://hosted.weblate.org/exports/stats/f-droid/f-droid/?format=csv' r = requests.get(url) @@ -19,7 +25,7 @@ stats = csv.reader(r.iter_lines(decode_unicode=True), delimiter=',') next(stats) # skip CSV header for row in stats: if len(row) > 4: - if float(row[4]) > 75.0: + if float(row[4]) > 70.0: continue locale = row[1] if '_' in locale: @@ -33,10 +39,22 @@ for row in stats: percent = str(int(float(row[4]))) + '%' print('Removing incomplete file: (' + percent + ')\t', translation_file) - os.remove(os.path.join(projectbasedir, translation_file)) - repo.index.remove([translation_file, ]) + delfile = os.path.join(projectbasedir, translation_file) + if os.path.exists(delfile): + os.remove(delfile) + repo.index.remove([translation_file, ]) if len(percent) == 2: msg += ' ' msg += percent + ' ' + row[1] + ' ' + row[0] + '\n' +found = False +for remote in repo.remotes: + if remote.name == 'weblate': + remote.fetch() + found = True + +if not found: + print('ERROR: there must be a weblate remote to preserve incomplete translations!') + sys.exit(1) + repo.index.commit(msg)