Added script to generate translation reports

This commit is contained in:
Akash Yadav
2022-03-18 09:34:36 +05:30
parent e2a572a999
commit 323beda7c0
12 changed files with 597 additions and 19 deletions
+15 -2
View File
@@ -35,9 +35,22 @@ jobs:
dependencies-cache-enabled: true
configuration-cache-enabled: true
- name: Upload artifact
- name: Generate translation report
run: |
chmod +x ./gradlew
./gradlew :app:checkTranslations
shell: bash
- name: Upload APK
uses: actions/upload-artifact@v2
if: ${{ !github.head_ref }}
with:
name: apk-debug
path: app/build/outputs/apk/debug/app-debug.apk
path: app/build/outputs/apk/debug/app-debug.apk
- name: Upload translation report
uses: actions/upload-artifact@v2
if: ${{ !github.head_ref }}
with:
name: translation-report
path: build/translation-reports/
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GoogleJavaFormatSettings">
<option name="enabled" value="true" />
</component>
</project>
+157
View File
@@ -0,0 +1,157 @@
#!/usr/bin/php -q
<?php
// Android translation helper tool
// cross checks two strings.xml files to find diffs
//
// usage: ./strings-check.php values/base.xml values-lang/translated.xml
//
// Written by Marcin Orlowski <mail (@) marcinorlowski (.) com>
//
// 2010-07-03: Initial release
// 2017-04-25: Code cleanup; Added exit code
class Convert {
public function XmlToArray( $n )
{
$xml_array = array();
$occurance = array();
foreach($n->childNodes as $nc) {
if (isset($occurance[$nc->nodeName])) {
$occurance[$nc->nodeName]++;
} else {
$occurance[$nc->nodeName] = 1;
}
}
foreach($n->childNodes as $nc) {
if( $nc->hasChildNodes() ) {
$childNodes = $nc->childNodes;
$children = $childNodes->length;
if ($children>1) {
$xml_array[$nc->nodeName][] = $this->XmlToArray($nc);
$counter = count($xml_array[$nc->nodeName])-1;
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][$counter]['attribute'][$attrs->item($k)->nodeName] = $attrs->item($k)->nodeValue;
}
//$counter++;
} else {
$xml_array[$nc->nodeName][]['cdata'] = $nc->nodeValue;
$counter = count($xml_array[$nc->nodeName])-1;
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][$counter]['attribute'][$attrs->item($k)->nodeName] = $attrs->item($k)->nodeValue;
}
}
} else {
if( $nc->hasAttributes() ) {
$attrs = $nc->attributes;
for ($k = 0; $k < $attrs->length; $k++) {
$xml_array[$nc->nodeName][0]['attribute'][$attrs->item($k)->nodeName]= $attrs->item($k)->nodeValue;
}
}
}
}
return $xml_array;
}
public function GetLabels( $fileName )
{
$xml = new DOMDocument('1.0','UTF-8');
$xml->load( $fileName );
$data = $this->XmlToArray( $xml );
$result = array();
foreach( $data['resources'][0]['string'] AS $entry ) {
$tmp = sprintf("%s", trim($entry['attribute']['name']));
$result[$tmp] = $tmp;
}
return $result;
}
// class convert
}
if( $_SERVER['argc'] != 3 ) {
printf("Usage: %s strings-BASE.xml string-LANG.xml\n", $_SERVER['argv'][0] );
die( "*** Aborted\n");
}
$fileBase = $_SERVER['argv'][1];
$fileLang = $_SERVER['argv'][2];
if( file_exists( $fileBase ) == FALSE ) {
die( sprintf("*** Missing BASE file '%s'\n", $fileBase ));
}
if( file_exists( $fileLang ) == FALSE ) {
die( sprintf("*** Missing LANG file '%s'\n", $fileLang ) );
}
$convert = new Convert();
$dataLang = $convert->GetLabels( $fileLang );
$dataBase = $convert->GetLabels( $fileBase );
$cntLang = $cntBase = 0;
echo "\n";
// comparing
printf("Missing in LANG (You need to translate these)\n");
printf("File: %s\n", $fileLang);
printf("------------------------- BEGIN ----------------------\n");
foreach( $dataBase as $string ) {
if( !array_key_exists($string, $dataLang)) {
printf("%s\n", $string);
$cntLang++;
}
}
printf("-------------------------- END -----------------------\n");
echo "\n\n";
printf("Not present in BASE (you need to remove it from LANG)\n");
printf("File: %s\n", $fileBase);
printf("------------------------- BEGIN ----------------------\n");
foreach( $dataLang as $string ) {
if( !array_key_exists($string, $dataBase)) {
printf("%s\n", $string);
$cntBase++;
}
}
printf("-------------------------- END -----------------------\n");
echo "\n\nSummary\n----------------\n";
echo "BASE file: '{$fileBase}'\n";
echo "LANG file: '{$fileLang}'\n";
echo "\n";
$rc = 1;
if( ($cntLang == 0) && ($cntBase==0) ) {
echo "OK. Files seem to be up to date.\n";
$rc = 0;
} else {
if( $cntLang > 0 ) {
printf( "%4d missing strings.\n", $cntLang );
}
if( $cntBase > 0 ) {
printf("%4d orphaned strings.\n", $cntBase );
}
}
echo "\n";
exit($rc);
+1 -5
View File
@@ -134,8 +134,4 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
}
+58 -12
View File
@@ -8,7 +8,7 @@ buildscript {
versionCode = 200
versionName = "2.0-beta"
packageName = "com.itsaky.androidide"
javaSourceVersion = JavaVersion.VERSION_11
javaTargetVersion = JavaVersion.VERSION_11
}
@@ -17,9 +17,9 @@ buildscript {
google()
mavenLocal()
mavenCentral()
maven { url 'https://jitpack.io'}
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.google.gms:google-services:4.3.10'
@@ -30,6 +30,59 @@ buildscript {
subprojects {
apply from: "${rootDir}/gradle/dependencies.gradle"
task checkTranslations() {
def php = new File ("/usr/bin/php")
if (!php.exists()) {
project.logger.lifecycle("'${php.absolutePath}' not found. Skipping translation check.")
return
}
def resDir = project.file("src/main/res")
def strings = new File(resDir, "values/strings.xml")
def reportDir = new File(project.rootProject.buildDir, "translation-reports")
reportDir.delete()
if (resDir.exists() && strings.exists()) {
def translationDirs = resDir.listFiles((FileFilter) (file -> {
return file.isDirectory() && file.getName().startsWith("values-") }))
for (def dir : translationDirs) {
final var translation = new File(dir, "strings.xml")
if (translation.exists()) {
def out = new File(reportDir, "${project.path.replace(':', '/')}/${dir.name}.txt")
if (!out.parentFile.exists()) {
out.parentFile.mkdirs()
}
if (out.exists()) {
out.delete()
}
out.createNewFile()
def result = exec {
ignoreExitValue true
standardOutput new FileOutputStream(out)
commandLine "${php.absolutePath}",
"${project.rootProject.file(".tools/strings-check.php")}",
"${strings.absolutePath}",
"${translation.absolutePath}"
}
if (result.getExitValue() == 0) {
out.delete()
} else {
project.logger.lifecycle("Translation report for '${project.path}/${dir.name}' is written to '${out.absolutePath}'")
}
} else {
project.logger.info("No translation file specifed for '${dir.name}'. Skipping..")
}
}
} else {
project.logger.info("Default strings.xml file does not exist for project '${project.name}'")
}
}
}
allprojects {
@@ -37,17 +90,10 @@ allprojects {
google()
mavenLocal()
mavenCentral()
maven { url 'https://jitpack.io'}
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
}
@@ -0,0 +1,79 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-de/strings.xml
------------------------- BEGIN ----------------------
template_libgdx
template_description_libgdx
idepref_editor_ligatures_title
idepref_editor_ligatures_summary
yes
no
title_use_popup_actions
msg_use_popup_actions
title_use_horizontal_popup
msg_use_horizontal_popup
msg_apk_install_intent_failed
msg_viewaction_add_attr
msg_search_attrs
msg_attr_added
msg_attr_not_updated
hint_dimension_val
hint_dimension_res
hint_boolean_res
msg_file_tree
hint_color_resource
title_color_picker
hint_string_value
hint_string_resource
hint_resource_reference
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
title_developers
msg_developers
cancel
msg_sdk_info_load_failed
msg_no_code_actions
msg_starting_completion_failed
menu_project_info
header_module_info
msg_module_count
msg_task_count
msg_dependency_count
msg_package_name
msg_min_sdk
msg_target_sdk
show_files
msg_failed_save
idepref_build_editgradleproperties_title
idepref_build_editgradleproperties_summary
err_completion
err_no_server_implementation
err_init_server
err_cannot_save_files
err_cannot_start_server
err_cannot_write_socket
err_server_disconnected
msg_attr_edit_hint
sym_equal
msg_attr_namespace
msg_unknown_package
msg_attr_editor_select_view
msg_attr_editor_no_attrs
msg_enter_attr_value
msg_enter_dimension_value
msg_attr_editor_null
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-de/strings.xml'
24 missing strings.
34 orphaned strings.
@@ -0,0 +1,94 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-fr/strings.xml
------------------------- BEGIN ----------------------
template_kotlin_basic
template_description_kotlin_basic
template_libgdx
template_description_libgdx
title_compiler_module_install
msg_compiler_module_install
msg_compiler_module_install_failed
msg_compiler_module_installed
action_expand_selection
idepref_java_matchLower_title
idepref_editor_category_common
idepref_editor_category_java
title_files_unsaved
msg_files_unsaved
idepref_editor_autoSave_title
idepref_editor_autoSave_summary
idepref_java_matchLower_summary
idepref_editor_ligatures_title
idepref_editor_ligatures_summary
yes
no
title_use_popup_actions
msg_use_popup_actions
title_use_horizontal_popup
msg_use_horizontal_popup
msg_apk_install_intent_failed
msg_viewaction_add_attr
msg_search_attrs
msg_attr_added
msg_attr_not_updated
hint_dimension_val
hint_dimension_res
hint_boolean_res
msg_file_tree
hint_color_resource
title_color_picker
hint_string_value
hint_string_resource
hint_resource_reference
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
title_developers
msg_developers
cancel
msg_sdk_info_load_failed
msg_no_code_actions
msg_starting_completion_failed
menu_project_info
header_module_info
msg_module_count
msg_task_count
msg_dependency_count
msg_package_name
msg_min_sdk
msg_target_sdk
show_files
msg_failed_save
idepref_build_editgradleproperties_title
idepref_build_editgradleproperties_summary
err_completion
err_no_server_implementation
err_init_server
err_cannot_save_files
err_cannot_start_server
err_cannot_write_socket
err_server_disconnected
msg_attr_edit_hint
sym_equal
msg_attr_namespace
msg_unknown_package
msg_attr_editor_select_view
msg_attr_editor_no_attrs
msg_enter_attr_value
msg_enter_dimension_value
msg_attr_editor_null
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-fr/strings.xml'
39 missing strings.
34 orphaned strings.
@@ -0,0 +1,21 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-hi/strings.xml
------------------------- BEGIN ----------------------
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
cancel
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-hi/strings.xml'
1 orphaned strings.
@@ -0,0 +1,21 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-in/strings.xml
------------------------- BEGIN ----------------------
msg_fix_diagnostic
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-in/strings.xml'
1 missing strings.
@@ -0,0 +1,69 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-ru/strings.xml
------------------------- BEGIN ----------------------
msg_apk_install_intent_failed
msg_viewaction_add_attr
msg_search_attrs
msg_attr_added
msg_attr_not_updated
hint_dimension_val
hint_dimension_res
hint_boolean_res
msg_file_tree
hint_color_resource
title_color_picker
hint_string_value
hint_string_resource
hint_resource_reference
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
title_developers
msg_developers
cancel
msg_sdk_info_load_failed
msg_no_code_actions
msg_starting_completion_failed
menu_project_info
header_module_info
msg_module_count
msg_task_count
msg_dependency_count
msg_package_name
msg_min_sdk
msg_target_sdk
show_files
msg_failed_save
idepref_build_editgradleproperties_title
idepref_build_editgradleproperties_summary
err_completion
err_no_server_implementation
err_init_server
err_cannot_save_files
err_cannot_start_server
err_cannot_write_socket
err_server_disconnected
msg_attr_edit_hint
sym_equal
msg_attr_namespace
msg_unknown_package
msg_attr_editor_select_view
msg_attr_editor_no_attrs
msg_enter_attr_value
msg_enter_dimension_value
msg_attr_editor_null
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-ru/strings.xml'
14 missing strings.
34 orphaned strings.
@@ -0,0 +1,54 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-zh/strings.xml
------------------------- BEGIN ----------------------
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
title_developers
msg_developers
cancel
msg_sdk_info_load_failed
msg_no_code_actions
msg_starting_completion_failed
menu_project_info
header_module_info
msg_module_count
msg_task_count
msg_dependency_count
msg_package_name
msg_min_sdk
msg_target_sdk
show_files
msg_failed_save
idepref_build_editgradleproperties_title
idepref_build_editgradleproperties_summary
err_completion
err_no_server_implementation
err_init_server
err_cannot_save_files
err_cannot_start_server
err_cannot_write_socket
err_server_disconnected
msg_attr_edit_hint
sym_equal
msg_attr_namespace
msg_unknown_package
msg_attr_editor_select_view
msg_attr_editor_no_attrs
msg_enter_attr_value
msg_enter_dimension_value
msg_attr_editor_null
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/app/src/main/res/values-zh/strings.xml'
34 orphaned strings.
@@ -0,0 +1,22 @@
Missing in LANG (You need to translate these)
File: /mnt/d/projects/androidstudioprojects/androidide/common/src/main/res/values-in/strings.xml
------------------------- BEGIN ----------------------
cms_channel_id_devs
cms_channel_id_update
-------------------------- END -----------------------
Not present in BASE (you need to remove it from LANG)
File: /mnt/d/projects/androidstudioprojects/androidide/common/src/main/res/values/strings.xml
------------------------- BEGIN ----------------------
-------------------------- END -----------------------
Summary
----------------
BASE file: '/mnt/d/projects/androidstudioprojects/androidide/common/src/main/res/values/strings.xml'
LANG file: '/mnt/d/projects/androidstudioprojects/androidide/common/src/main/res/values-in/strings.xml'
2 missing strings.