diff --git a/.gitignore b/.gitignore index e0e3fc21b..b1746282e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ gradle.properties *~ .weblate +*.class diff --git a/CheckTranslations.java b/CheckTranslations.java new file mode 100644 index 000000000..fba4fa998 --- /dev/null +++ b/CheckTranslations.java @@ -0,0 +1,131 @@ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.regex.*; +import java.util.Arrays; +import java.util.List; +import java.util.ArrayList; +import java.nio.file.Files; +import java.nio.charset.Charset; + +public final class CheckTranslations { + + private static boolean debug = false; + private static boolean plurals = false; + private static boolean empty = false; + private static boolean remove = false; + private static int checks = 0; + private static int matches = 0; + private static Pattern p, e; + + /** + * Search translated strings.xml files for empty item / plural tags + * and remove them. + * @param args directories which contain string.xml files (in any subdirectory) + * -e option to find all empty string tags + * -p option to find all empty plurals and item tags + * -r option to remove all occurrences from the files + * -d option to see more details + */ + public static void main(String[] args) { + if (args.length < 1 || (args[0].equals("-d") && args.length < 2)) { + System.out.println("Not enough arguments"); + return; + } + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case "-d": + debug = true; + break; + case "-p": + plurals = true; + break; + case "-e": + empty = true; + break; + case "-r": + remove = true; + break; + } + } + + if (!plurals && !empty) { + plurals = true; + empty = true; + } + + p = Pattern.compile("(<item quantity=\")(zero|one|two|three|few|many|other)(\"></item>|\"/>)"); + e = Pattern.compile("(<string[\\sa-z_\\\"=]*)((><\\/string>|\\/>){1})"); + + for (int i = 0; i < args.length; i++) { + if (!args[i].equals("-d") && !args[i].equals("-p") && !args[i].equals("-e") && !args[i].equals("-r")) { + File f = new File(args[i]); + if (f.exists() && !f.isDirectory()) { + checkFile(f); + } else if (f.isDirectory()) { + checkFiles(f.listFiles()); + } else { + System.out.println("'" + args[i] + "' does not exist!"); + } + } + } + + System.out.println(checks + " files were checked."); + System.out.println(matches + " corrupt lines detected."); + if (remove) System.out.println(matches + " corrupt lines removed."); + } + + + private static void checkFiles(File[] f) { + for (int i = 0; i < f.length; i++) { + if (f[i].exists() && !f[i].isDirectory()) { + if (f[i].toString().contains("strings.xml")) { + checkFile(f[i]); + } + } else if (f[i].isDirectory()) { + checkFiles(f[i].listFiles()); + } + } + } + + private static void checkFile(File f) { + // Do not check our original English strings to cause no unwanted changes + // Btw. there should not be empty plural/item tags + if (f.toString().contains("values/strings.xml")) { + return; + } + if (debug) System.out.println("Checking " + f.toString()); + checks++; + + + List<String> lines = new ArrayList<String>(); + boolean checkFailed = false; + + try (BufferedReader br = new BufferedReader(new FileReader(f))) { + String line; + int ln = 0; + while ((line = br.readLine()) != null) { + ln++; + if (plurals && p.matcher(line).find()) { + matches++; + if (debug) System.out.println(" Line " + ln + " was " + ((remove) ? "removed" : "detected") + ": '" + line + "'"); + checkFailed = true; + } else if (empty && e.matcher(line).find()) { + matches++; + checkFailed = true; + if (debug) System.out.println(" Line " + ln + " was " + ((remove) ? "removed" : "detected") + ": '" + line + "'"); + } else { + if (remove) lines.add(line); + } + } + br.close(); + if (remove && checkFailed) { + Files.write(f.toPath(), lines, Charset.forName("UTF-8")); + } + } catch (IOException e) { + System.out.println(e); + } + } +} + diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index a02be21fd..0c70de999 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -154,7 +154,6 @@ <string name="error_snackbar_action">تقرير</string> <string name="what_device_headline">معلومات:</string> <string name="what_happened_headline">ماذا حدث:</string> - <string name="info_labels"/> <string name="your_comment">تعليقك (باللغة الإنجليزية):</string> <string name="error_details_headline">تفاصيل:</string> @@ -176,12 +175,6 @@ <string name="no_subscribers">صفر لا تقم با الإختيار (في بعض اللغات) لأنها ليست \"حالة خاصة\" للأندرويد</string> <plurals name="subscribers"> - <item quantity="zero"></item> - <item quantity="one"></item> - <item quantity="two"></item> - <item quantity="few"></item> - <item quantity="many"></item> - <item quantity="other"></item> </plurals> <string name="no_views">لاتوجد مشاهدات</string> diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 55434038d..4d17ade32 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -205,7 +205,6 @@ otevření ve vyskakovacím okně</string> <item quantity="one">%s odběratel</item> <item quantity="few">%s odběratelé</item> <item quantity="many">%s odběratelů</item> - <item quantity="other"/> </plurals> <string name="no_views">Žádná zhlédnutí</string> @@ -220,7 +219,6 @@ otevření ve vyskakovacím okně</string> <item quantity="one">%s video</item> <item quantity="few">%s videa</item> <item quantity="many">%s videí</item> - <item quantity="other"/> </plurals> <string name="settings_category_downloads_title">Stahování</string> diff --git a/app/src/main/res/values-he/strings.xml b/app/src/main/res/values-he/strings.xml index c28a742c8..25aed9cd8 100644 --- a/app/src/main/res/values-he/strings.xml +++ b/app/src/main/res/values-he/strings.xml @@ -178,24 +178,18 @@ <plurals name="subscribers"> <item quantity="one">%s עוקב</item> <item quantity="two">%s עוקבים</item> - <item quantity="many"></item> - <item quantity="other"></item> </plurals> <string name="no_views">אין תצוגות</string> <plurals name="views"> <item quantity="one">תצוגה %s</item> <item quantity="two">%s תצוגות</item> - <item quantity="many"></item> - <item quantity="other"></item> </plurals> <string name="no_videos">אין סרטונים</string> <plurals name="videos"> <item quantity="one">סרטון %s</item> <item quantity="two">%s סרטונים</item> - <item quantity="many"></item> - <item quantity="other"></item> </plurals> <string name="start">התחל</string> diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 1e465458f..e51e71e46 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -128,15 +128,10 @@ <plurals name="subscribers"> <item quantity="one">%s prenumeratorius</item> <item quantity="few">%s prenumeratoriai</item> - <item quantity="many"/> - <item quantity="other"/> </plurals> <plurals name="videos"> <item quantity="one">Vaizdo įrašai</item> - <item quantity="few"/> - <item quantity="many"/> - <item quantity="other"/> </plurals> <string name="start">Pradėti</string> @@ -214,9 +209,6 @@ <string name="no_views">Nėra peržiūrų</string> <plurals name="views"> <item quantity="one">%a peržiūra</item> - <item quantity="few"></item> - <item quantity="many"></item> - <item quantity="other"></item> </plurals> <string name="no_videos">Nėra vaizdo įrašų</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index aa3672a36..1b27469ff 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -248,22 +248,17 @@ <item quantity="one">%s subskrybent</item> <item quantity="few">%s subskrybentów</item> <item quantity="many">%s subskrybentów</item> - <item quantity="other"/> </plurals> <plurals name="views"> <item quantity="one">%s odtworzenie</item> - <item quantity="few"/> <item quantity="many">%s odtworzeń</item> - <item quantity="other"/> </plurals> <string name="no_videos">Brak filmów</string> <plurals name="videos"> <item quantity="one">%s film</item> <item quantity="few">%s filmów</item> - <item quantity="many"/> - <item quantity="other"/> </plurals> <string name="charset_most_special_characters">Większość znaków specjalnych</string> diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index a1c979665..36c25f5cf 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -237,7 +237,6 @@ <item quantity="one">%s подписчик</item> <item quantity="few">%s подписчика</item> <item quantity="many">%s подписчиков</item> - <item quantity="other"/> </plurals> <string name="no_views">Нет просмотров</string> @@ -245,7 +244,6 @@ <item quantity="one">%s просмотр</item> <item quantity="few">%s просмотра</item> <item quantity="many">%s просмотров</item> - <item quantity="other"/> </plurals> <string name="no_videos">Нет видео</string> @@ -253,7 +251,6 @@ <item quantity="one">%s видео</item> <item quantity="few">%s видео</item> <item quantity="many">%s видео</item> - <item quantity="other"/> </plurals> <string name="item_deleted">Элемент удалён</string> diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index eaa8cb48f..653e54dbe 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -248,7 +248,6 @@ otvorenie okna na popredí</string> <item quantity="one">%s odberateľ</item> <item quantity="few">%s odberatelia</item> <item quantity="many">%s odberateľov</item> - <item quantity="other"></item> </plurals> <string name="no_views">Žiadne zobrazenia</string> @@ -256,7 +255,6 @@ otvorenie okna na popredí</string> <item quantity="one">%s zobrazenie</item> <item quantity="few">%s zobrazenia</item> <item quantity="many">%s zobrazení</item> - <item quantity="other"></item> </plurals> <string name="no_videos">Žiadne videá</string> @@ -264,7 +262,6 @@ otvorenie okna na popredí</string> <item quantity="one">%s video</item> <item quantity="few">%s videá</item> <item quantity="many">%s videí</item> - <item quantity="other"></item> </plurals> <string name="item_deleted">Položka bola odstránená</string> diff --git a/fixplurals.sh b/fixplurals.sh new file mode 100755 index 000000000..331a01240 --- /dev/null +++ b/fixplurals.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +javac CheckTranslations.java +find app/src -name "*.xml" | grep values | xargs java CheckTranslations -r