From a71489a102eec81742878220a6e927cbfcdd245c Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner <hans@eds.org> Date: Fri, 3 May 2019 15:44:40 +0200 Subject: [PATCH] set max width on places where the translations get too long closes #1678 --- app/src/full/res/layout/main_tab_swap.xml | 2 + .../full/res/layout/swap_app_list_item.xml | 3 ++ .../res/layout/app_details2_version_item.xml | 3 ++ app/src/main/res/layout/updates_header.xml | 3 ++ tools/check-string-maxlength.py | 48 +++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100755 tools/check-string-maxlength.py diff --git a/app/src/full/res/layout/main_tab_swap.xml b/app/src/full/res/layout/main_tab_swap.xml index 03c35548e..3db7d5eee 100644 --- a/app/src/full/res/layout/main_tab_swap.xml +++ b/app/src/full/res/layout/main_tab_swap.xml @@ -42,6 +42,7 @@ android:id="@+id/find_people_button" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:maxEms="16" android:text="@string/nearby_splash__find_people_button" style="@style/DetailsSecondaryButtonStyle" app:layout_constraintTop_toBottomOf="@+id/title" @@ -85,6 +86,7 @@ android:id="@+id/request_read_external_storage_button" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:maxEms="16" android:text="@string/nearby_splash__request_permission" style="@style/DetailsSecondaryButtonStyle" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/full/res/layout/swap_app_list_item.xml b/app/src/full/res/layout/swap_app_list_item.xml index f4d1b069d..84aedf51c 100644 --- a/app/src/full/res/layout/swap_app_list_item.xml +++ b/app/src/full/res/layout/swap_app_list_item.xml @@ -37,6 +37,9 @@ android:layout_height="wrap_content" android:backgroundTint="@color/swap_light_blue" android:textColor="@android:color/white" + android:maxEms="10" + android:ellipsize="end" + android:singleLine="true" android:text="@string/menu_install" tools:ignore="UnusedAttribute" /> diff --git a/app/src/main/res/layout/app_details2_version_item.xml b/app/src/main/res/layout/app_details2_version_item.xml index 935c03b35..194a08489 100644 --- a/app/src/main/res/layout/app_details2_version_item.xml +++ b/app/src/main/res/layout/app_details2_version_item.xml @@ -143,6 +143,9 @@ android:layout_marginTop="5dp" android:layout_marginRight="4dp" android:layout_marginEnd="4dp" + android:maxEms="10" + android:ellipsize="end" + android:singleLine="true" tools:text="@string/menu_install"/> <Button diff --git a/app/src/main/res/layout/updates_header.xml b/app/src/main/res/layout/updates_header.xml index 58b655ffa..c3c2e9c12 100644 --- a/app/src/main/res/layout/updates_header.xml +++ b/app/src/main/res/layout/updates_header.xml @@ -42,6 +42,7 @@ android:layout_height="wrap_content" android:layout_marginEnd="16dp" android:layout_marginRight="16dp" + android:maxEms="10" android:text="@string/update_all" style="@style/DetailsPrimaryButtonStyle" app:layout_constraintEnd_toEndOf="parent" @@ -54,6 +55,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="8dp" + android:ellipsize="middle" + android:singleLine="true" tools:text="Show apps" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" diff --git a/tools/check-string-maxlength.py b/tools/check-string-maxlength.py new file mode 100755 index 000000000..8be69cc0a --- /dev/null +++ b/tools/check-string-maxlength.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +# Remove extra translations + +import glob +import os +import sys +import re +from xml.etree import ElementTree + +maxlengths = { + "menu_install": 20, + "menu_uninstall": 20, + "nearby_splash__find_people_button": 30, + "nearby_splash__request_permission": 30, + "update_all": 20, + "updates__hide_updateable_apps": 35, + "updates__show_updateable_apps": 35, +} + + +resdir = os.path.join(os.path.dirname(__file__), '..', 'app', 'src', 'main', 'res') + +count = 0 + +for d in sorted(glob.glob(os.path.join(resdir, 'values-*'))): + locale = d.split('/')[-1][7:] + + str_path = os.path.join(d, 'strings.xml') + if not os.path.exists(str_path): + continue + + with open(str_path, encoding='utf-8') as fp: + fulltext = fp.read() + + tree = ElementTree.parse(str_path) + root = tree.getroot() + + for e in root.findall('.//string'): + + if maxlengths.get(e.attrib['name']) is not None \ + and len(e.text) > maxlengths.get(e.attrib['name']): + print(e.attrib['name'], locale, str(len(e.text)) + ':\t\t"' + e.text + '"') + +if count > 0: + print("%d over-long strings found!" % count) + sys.exit(count) +