Make sure translation are in sync

The new script makes sure that strings files don't contain obsolete
strings but also ease the job of contributors by adding missing
translations as comments.

A Github Action ensures that translations stay in sync over time.
This commit is contained in:
Jules Aguillon 2022-11-26 18:11:28 +01:00
parent 122a9c23d0
commit ebdacbc2b2
13 changed files with 157 additions and 6 deletions

View File

@ -0,0 +1,16 @@
name: Check translations
on:
workflow_dispatch:
push:
pull_request:
jobs:
check-translations:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- run: python3 sync_translations.py
- name: Check that strings files are uptodate, run python3 sync_translations.py otherwise
run: git diff --exit-code

View File

@ -4,14 +4,21 @@
<string name="app_name" product="default">Klávesnice Unexpected</string>
<string name="settings_activity_label">Nastavení Klávesnice Unexpected</string>
<string name="pref_category_layout">Rozvržení</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Změnit rozvržení klávesnice</string>
<string name="pref_layout_e_system">V nastavení systému</string>
<string name="pref_accents_title">(Univerzální) Diakritická znaménka</string>
<string name="pref_accents_e_all_installed">Zobrazovat znaménka pro všechny instalované systémové jazyky</string>
<string name="pref_accents_e_selected">Zobrazovat znaménka pouze pro současně zvolený jazyk</string>
<string name="pref_accents_e_none">Skrýt (univerzální) diakritická znaménka</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<string name="pref_autocapitalisation_title">Automatická kapitalizace</string>
<string name="pref_autocapitalisation_summary">Stiskne Shift na začátku věty</string>
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Žádné</string>
<string name="pref_category_typing">Psaní</string>
<string name="pref_swipe_dist_title">Vzdálenost posunutí prstem</string>
@ -36,6 +43,7 @@
<string name="pref_theme_e_dark">Tmavý</string>
<string name="pref_theme_e_light">Světlý</string>
<string name="pref_theme_e_black">Černý</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Velmi krátká</string>
<string name="pref_swipe_dist_e_short">Krátká</string>
<string name="pref_swipe_dist_e_default">Běžná</string>

View File

@ -4,6 +4,7 @@
<string name="app_name" product="default">Unexpected Keyboard</string>
<string name="settings_activity_label">Unexpected Keyboard - Einstellungen</string>
<string name="pref_category_layout">Layout</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Tastaturlayout ändern</string>
<string name="pref_layout_e_system">Systemeinstellung</string>
<string name="pref_accents_title">Akzente</string>
@ -14,11 +15,12 @@
<string name="pref_show_numpad_never">Nie</string>
<string name="pref_show_numpad_landscape">Nur im Querformat</string>
<string name="pref_show_numpad_always">Immer</string>
<string name="pref_extra_keys_title">Zusätzliche Zeichen zur Tastatur hinzufügen</string>
<string name="pref_second_layout_none">Keines</string>
<string name="pref_category_typing">Tippen</string>
<string name="pref_autocapitalisation_title">Automatische Großschreibung</string>
<string name="pref_autocapitalisation_summary">Shift-Taste am Satzanfang aktivieren</string>
<string name="pref_extra_keys_title">Zusätzliche Zeichen zur Tastatur hinzufügen</string>
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Keines</string>
<string name="pref_category_typing">Tippen</string>
<string name="pref_swipe_dist_title">Länge der Wischgeste</string>
<string name="pref_swipe_dist_summary">Abstand der Zeichen in den Ecken der Tasten (%s)</string>
<string name="pref_long_timeout_title">Zeitüberschreitung bei Tastenwiederholung</string>

View File

@ -1,13 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- <string name="app_name" product="debug">Unexpected Keyboard (debug)</string> -->
<!-- <string name="app_name" product="default">Unexpected Keyboard</string> -->
<string name="settings_activity_label">Ajustes de Unexpected Keyboard</string>
<string name="pref_category_layout">Formato</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Cambiar formato de teclado</string>
<string name="pref_layout_e_system">Ajustes del sistema</string>
<string name="pref_accents_title">Acentos</string>
<string name="pref_accents_e_all_installed">Mostrar acentos para todos los lenguajes instalados</string>
<string name="pref_accents_e_selected">Solo mostrar acentos para el lenguaje seleccionado</string>
<string name="pref_accents_e_none">Ocultar acentos</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_autocapitalisation_title">Automatic capitalisation</string> -->
<!-- <string name="pref_autocapitalisation_summary">Press Shift at the beginning of a sentence</string> -->
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<!-- <string name="pref_second_layout_none">None</string> -->
<string name="pref_category_typing">Escribiendo</string>
<string name="pref_swipe_dist_title">Distancia para deslizar</string>
<string name="pref_swipe_dist_summary">Distancia de caracteres en las esquinas de las letras (%s)</string>
@ -17,9 +29,12 @@
<string name="pref_vibrate_summary">Habilitar/deshabilitar vibración al presionar una tecla</string>
<string name="pref_precise_repeat_title">Movimientos de cursor preciso</string>
<string name="pref_precise_repeat_summary">Modular la velocidad de repetición de teclas según si se desliza más o menos</string>
<!-- <string name="pref_lock_double_tap_title">Double tap on shift for caps lock</string> -->
<!-- <string name="pref_lock_double_tap_summary">You can lock any modifier by holding it</string> -->
<string name="pref_category_style">Estilo</string>
<string name="pref_margin_bottom_title">Margen del pie</string>
<string name="pref_keyboard_height_title">Altura del teclado</string>
<!-- <string name="pref_keyboard_height_landscape_title">Keyboard height in landscape mode</string> -->
<string name="pref_horizontal_margin_title">Margen horizontal</string>
<string name="pref_character_size_title">Tamaño de etiqueta</string>
<string name="pref_character_size_summary">Tamaño de caracteres mostrados en el teclado (%.2fx)</string>
@ -28,6 +43,7 @@
<string name="pref_theme_e_dark">Oscuro</string>
<string name="pref_theme_e_light">Claro</string>
<string name="pref_theme_e_black">Negro</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Muy corto</string>
<string name="pref_swipe_dist_e_short">Corto</string>
<string name="pref_swipe_dist_e_default">Normal</string>

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- <string name="app_name" product="debug">Unexpected Keyboard (debug)</string> -->
<!-- <string name="app_name" product="default">Unexpected Keyboard</string> -->
<string name="settings_activity_label">Unexpected Keyboard Paramètres</string>
<string name="pref_category_layout">Disposition</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Disposition des touches</string>
<string name="pref_layout_e_system">Paramètre système</string>
<string name="pref_accents_title">Accents</string>
@ -14,6 +17,9 @@
<string name="pref_show_numpad_always">Toujour</string>
<string name="pref_autocapitalisation_title">Majuscule automatique</string>
<string name="pref_autocapitalisation_summary">Active Shift au début des phrases</string>
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<!-- <string name="pref_second_layout_none">None</string> -->
<string name="pref_category_typing">Saisie</string>
<string name="pref_swipe_dist_title">Distance de swipe</string>
<string name="pref_swipe_dist_summary">La distance des caractères dans les coins (%s)</string>
@ -23,6 +29,8 @@
<string name="pref_vibrate_summary">Vibration a chaque touche</string>
<string name="pref_precise_repeat_title">Mouvement précis du curseur</string>
<string name="pref_precise_repeat_summary">Modifier la vitesse de répétition en bougeant le doigt</string>
<!-- <string name="pref_lock_double_tap_title">Double tap on shift for caps lock</string> -->
<!-- <string name="pref_lock_double_tap_summary">You can lock any modifier by holding it</string> -->
<string name="pref_category_style">Style</string>
<string name="pref_margin_bottom_title">Marge du bas</string>
<string name="pref_keyboard_height_title">Hauteur du clavier</string>

View File

@ -4,14 +4,21 @@
<string name="app_name" product="default">Unexpected Keyboard</string>
<string name="settings_activity_label">Impostazioni di Unexpected Keyboard</string>
<string name="pref_category_layout">Layout</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Cambia layout tastiera</string>
<string name="pref_layout_e_system">Impostazioni di sistema</string>
<string name="pref_accents_title">Accenti</string>
<string name="pref_accents_e_all_installed">Mostra accenti per tutte le lingue installate</string>
<string name="pref_accents_e_selected">Mostra accenti solo per le lingue selezionate</string>
<string name="pref_accents_e_none">Nascondi accenti</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<string name="pref_autocapitalisation_title">Maiuscole Automatiche</string>
<string name="pref_autocapitalisation_summary">Premi Shift all\'inizio di una frase</string>
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Nessuno</string>
<string name="pref_category_typing">Digitando</string>
<string name="pref_swipe_dist_title">Distanza swipe</string>
@ -36,6 +43,7 @@
<string name="pref_theme_e_dark">Scuro</string>
<string name="pref_theme_e_light">Chiaro</string>
<string name="pref_theme_e_black">Nero</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Veramente breve</string>
<string name="pref_swipe_dist_e_short">Breve</string>
<string name="pref_swipe_dist_e_default">Normale</string>

View File

@ -1,13 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- <string name="app_name" product="debug">Unexpected Keyboard (debug)</string> -->
<!-- <string name="app_name" product="default">Unexpected Keyboard</string> -->
<string name="settings_activity_label">Unexpected Keyboard 설정</string>
<string name="pref_category_layout">레이아웃</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">키보드 레이아웃 변경</string>
<string name="pref_layout_e_system">시스템 세팅</string>
<string name="pref_accents_title">악센트</string>
<string name="pref_accents_e_all_installed">설치된 모든 언어의 악센트 표시</string>
<string name="pref_accents_e_selected">선택한 언어의 악센트만 표시</string>
<string name="pref_accents_e_none">모든 언어의 악센트 숨기기</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_autocapitalisation_title">Automatic capitalisation</string> -->
<!-- <string name="pref_autocapitalisation_summary">Press Shift at the beginning of a sentence</string> -->
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<!-- <string name="pref_second_layout_none">None</string> -->
<string name="pref_category_typing">타자</string>
<string name="pref_swipe_dist_title">스와이프 범위</string>
<string name="pref_swipe_dist_summary">키 모서리 문자의 입력 범위 (%s)</string>
@ -17,9 +29,12 @@
<string name="pref_vibrate_summary">키 누를 때 진동 키거/끄기</string>
<string name="pref_precise_repeat_title">정확한 커서 움직임</string>
<string name="pref_precise_repeat_summary">더 많거나 적은 스와이프로 키 반복 조절</string>
<!-- <string name="pref_lock_double_tap_title">Double tap on shift for caps lock</string> -->
<!-- <string name="pref_lock_double_tap_summary">You can lock any modifier by holding it</string> -->
<string name="pref_category_style">스타일</string>
<string name="pref_margin_bottom_title">아래 넓이</string>
<string name="pref_keyboard_height_title">키보드 높이</string>
<!-- <string name="pref_keyboard_height_landscape_title">Keyboard height in landscape mode</string> -->
<string name="pref_horizontal_margin_title">양 옆 넓이</string>
<string name="pref_character_size_title">폰트 크기</string>
<string name="pref_character_size_summary">키보드의 표시되는 폰트 크기 (%.2fx)</string>
@ -28,6 +43,7 @@
<string name="pref_theme_e_dark">Dark</string>
<string name="pref_theme_e_light">Light</string>
<string name="pref_theme_e_black">Black</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">매우 짧음</string>
<string name="pref_swipe_dist_e_short">짧음</string>
<string name="pref_swipe_dist_e_default">보통</string>

View File

@ -4,6 +4,7 @@
<string name="app_name" product="default">Unexpected Keyboard</string>
<string name="settings_activity_label">Unexpected Keyboard iestatījumi</string>
<string name="pref_category_layout">Izkārtojums</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Mainīt tastatūras izkārtojumu</string>
<string name="pref_layout_e_system">Ierīces iestatījumi</string>
<string name="pref_accents_title">Uzsvara zīmes</string>
@ -17,6 +18,7 @@
<string name="pref_autocapitalisation_title">Automātiski lielie burti</string>
<string name="pref_autocapitalisation_summary">Piespiest Shift teikuma sākumā</string>
<string name="pref_extra_keys_title">Pievienot tastatūrai taustiņus</string>
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Neviens</string>
<string name="pref_category_typing">Rakstīšana</string>
<string name="pref_swipe_dist_title">Pavilkšanas attālums</string>

View File

@ -4,14 +4,21 @@
<string name="app_name" product="default">Teclado Unexpected</string>
<string name="settings_activity_label">Configurar Teclado Unexpected</string>
<string name="pref_category_layout">Layout</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Mudar layout do teclado</string>
<string name="pref_layout_e_system">Mesmo do sistema</string>
<string name="pref_accents_title">Acentos</string>
<string name="pref_accents_e_all_installed">Mostrar acentos para todos os idiomas instalados</string>
<string name="pref_accents_e_selected">Mostrar acentos só para o idioma selecionado</string>
<string name="pref_accents_e_none">Ocultar acentos</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<string name="pref_autocapitalisation_title">Maiusculização automática</string>
<string name="pref_autocapitalisation_summary">Aciona o shift no início de cada frase</string>
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Nenhum</string>
<string name="pref_category_typing">Digitação</string>
<string name="pref_swipe_dist_title">Distância a deslizar</string>
@ -36,6 +43,7 @@
<string name="pref_theme_e_dark">Escuro</string>
<string name="pref_theme_e_light">Claro</string>
<string name="pref_theme_e_black">Preto</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Muito curto</string>
<string name="pref_swipe_dist_e_short">Curto</string>
<string name="pref_swipe_dist_e_default">Normal</string>

View File

@ -1,14 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Unexpected Keyboard</string>
<!-- <string name="app_name" product="debug">Unexpected Keyboard (debug)</string> -->
<!-- <string name="app_name" product="default">Unexpected Keyboard</string> -->
<string name="settings_activity_label">Unexpected Keyboard Настройки</string>
<string name="pref_category_layout">Расположение</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Изменить раскладку клавиатуры</string>
<string name="pref_layout_e_system">Системные настройки</string>
<string name="pref_accents_title">Акцент</string>
<string name="pref_accents_e_all_installed">Показывать акценты для всех установленных языков</string>
<string name="pref_accents_e_selected">Показывать акценты только для выбранного языка</string>
<string name="pref_accents_e_none">Скрыть акценты</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_autocapitalisation_title">Automatic capitalisation</string> -->
<!-- <string name="pref_autocapitalisation_summary">Press Shift at the beginning of a sentence</string> -->
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Нету</string>
<string name="pref_category_typing">Печатание</string>
<string name="pref_swipe_dist_title">Расстояние пролистывания</string>
@ -19,6 +29,8 @@
<string name="pref_vibrate_summary">Включение/выключение вибрации при нажатии клавиши</string>
<string name="pref_precise_repeat_title">Точные перемещения курсора</string>
<string name="pref_precise_repeat_summary">Модулируйте скорость повторения клавиш, проводя пальцем больше или меньше</string>
<!-- <string name="pref_lock_double_tap_title">Double tap on shift for caps lock</string> -->
<!-- <string name="pref_lock_double_tap_summary">You can lock any modifier by holding it</string> -->
<string name="pref_category_style">Стиль</string>
<string name="pref_margin_bottom_title">Нижняя граница поля</string>
<string name="pref_keyboard_height_title">Высота клавиатуры</string>
@ -31,6 +43,7 @@
<string name="pref_theme_e_dark">Темный</string>
<string name="pref_theme_e_light">Светлый</string>
<string name="pref_theme_e_black">Черный</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Очень короткий</string>
<string name="pref_swipe_dist_e_short">Короткий</string>
<string name="pref_swipe_dist_e_default">Обычный</string>

View File

@ -4,12 +4,21 @@
<string name="app_name" product="default">Unexpected Keyboard</string>
<string name="settings_activity_label">Unexpected Keyboard Ayarları</string>
<string name="pref_category_layout">Düzen</string>
<!-- <string name="pref_label_brightness">Adjust label brightness</string> -->
<string name="pref_layout_title">Klavye Düzenini Değiştir</string>
<string name="pref_layout_e_system">Sistem Ayarları</string>
<string name="pref_accents_title">Aksanlar</string>
<string name="pref_accents_e_all_installed">Yüklü tüm dillerin aksanlarını göster</string>
<string name="pref_accents_e_selected">Sadece seçili dilin aksanlarını göster</string>
<string name="pref_accents_e_none">Aksanları gizle</string>
<!-- <string name="pref_show_numpad_title">Show NumPad</string> -->
<!-- <string name="pref_show_numpad_never">Never</string> -->
<!-- <string name="pref_show_numpad_landscape">Only in landscape mode</string> -->
<!-- <string name="pref_show_numpad_always">Always</string> -->
<!-- <string name="pref_autocapitalisation_title">Automatic capitalisation</string> -->
<!-- <string name="pref_autocapitalisation_summary">Press Shift at the beginning of a sentence</string> -->
<!-- <string name="pref_extra_keys_title">Add keys to the keyboard</string> -->
<!-- <string name="pref_second_layout_title">Secondary layout</string> -->
<string name="pref_second_layout_none">Hiçbiri</string>
<string name="pref_category_typing">Yazma</string>
<string name="pref_swipe_dist_title">Kaydırma mesafesi</string>
@ -20,9 +29,12 @@
<string name="pref_vibrate_summary">Tuşa basıldığında titreşimi etkinleştir</string>
<string name="pref_precise_repeat_title">İmleç hareketini ayarla</string>
<string name="pref_precise_repeat_summary">Tuş tekrar hızını az ya da çok kaydırarak ayarla</string>
<!-- <string name="pref_lock_double_tap_title">Double tap on shift for caps lock</string> -->
<!-- <string name="pref_lock_double_tap_summary">You can lock any modifier by holding it</string> -->
<string name="pref_category_style">Stil</string>
<string name="pref_margin_bottom_title">Alt boşluk</string>
<string name="pref_keyboard_height_title">Klavye yüksekliği</string>
<!-- <string name="pref_keyboard_height_landscape_title">Keyboard height in landscape mode</string> -->
<string name="pref_horizontal_margin_title">Yatay boşluk</string>
<string name="pref_character_size_title">Etiket boyutu</string>
<string name="pref_character_size_summary">Klavye üzerinde gösterilecek karakter boyutu (%.2fx)</string>
@ -31,6 +43,7 @@
<string name="pref_theme_e_dark">Koyu</string>
<string name="pref_theme_e_light">ık</string>
<string name="pref_theme_e_black">Siyah</string>
<!-- <string name="pref_theme_e_white">White</string> -->
<string name="pref_swipe_dist_e_very_short">Çok kısa</string>
<string name="pref_swipe_dist_e_short">Kısa</string>
<string name="pref_swipe_dist_e_default">Normal</string>

View File

@ -3,8 +3,8 @@
<string name="app_name" product="debug">Unexpected Keyboard (debug)</string>
<string name="app_name" product="default">Unexpected Keyboard</string>
<string name="settings_activity_label">Unexpected Keyboard 设置</string>
<string name="pref_label_brightness">调整字母亮度</string>
<string name="pref_category_layout">布局</string>
<string name="pref_label_brightness">调整字母亮度</string>
<string name="pref_layout_title">改变键盘布局</string>
<string name="pref_layout_e_system">系统设置</string>
<string name="pref_accents_title">声调</string>

41
sync_translations.py Normal file
View File

@ -0,0 +1,41 @@
import xml.etree.ElementTree as ET
from xml.sax import saxutils
import glob
# Edit every strings.xml files:
# - Add missing translation as comments
# - Remove obsolete strings
# - Sort in the same order as the baseline
# The baseline is 'values/strings.xml', which is english.
def parse_strings_file(file):
resources = ET.parse(file).getroot()
return [
((ent.get("name"), ent.get("product")), ent.text)
for ent in resources if ent.tag == "string"
]
def string_entry_str(name, text, product):
product_attr = ' product="%s"' % product if product != None else ""
text_encoded = saxutils.escape(text)
return '<string name="%s"%s>%s</string>' % (name, product_attr, text_encoded)
def write_updated_strings(out, baseline, strings):
out.write('<?xml version="1.0" encoding="utf-8"?>\n<resources>\n')
for key, default_text in baseline:
name, product = key
if key in strings:
ent = string_entry_str(name, strings[key], product)
out.write(" %s\n" % ent)
else:
def_ent = string_entry_str(name, default_text, product)
out.write(" <!-- %s -->\n" % def_ent)
out.write('</resources>\n')
baseline = parse_strings_file("res/values/strings.xml")
for strings_file in glob.glob("res/values-*/strings.xml"):
print(strings_file)
strings = dict(parse_strings_file(strings_file))
with open(strings_file, "w") as out:
write_updated_strings(out, baseline, strings)