aboutsummaryrefslogtreecommitdiffstats
path: root/langs/lib.php
diff options
context:
space:
mode:
authorfilip <filip.komar@gmail.com>2014-11-30 16:27:34 +0100
committerfilip <filip.komar@gmail.com>2014-11-30 16:27:34 +0100
commit070c7f127bc814ad6123df4d643df2e50b907886 (patch)
tree58f26f3b493655dcbd7c0c1e3e166a3d4fc5b218 /langs/lib.php
parentde66e8b545d769161bbf41e518ccd5b60172b985 (diff)
downloadwww-070c7f127bc814ad6123df4d643df2e50b907886.tar
www-070c7f127bc814ad6123df4d643df2e50b907886.tar.gz
www-070c7f127bc814ad6123df4d643df2e50b907886.tar.bz2
www-070c7f127bc814ad6123df4d643df2e50b907886.tar.xz
www-070c7f127bc814ad6123df4d643df2e50b907886.zip
First push of report about differences between Transifex and our git repository
Diffstat (limited to 'langs/lib.php')
-rw-r--r--langs/lib.php104
1 files changed, 104 insertions, 0 deletions
diff --git a/langs/lib.php b/langs/lib.php
index b238cdd4c..03520e317 100644
--- a/langs/lib.php
+++ b/langs/lib.php
@@ -269,3 +269,107 @@ function aproximate_number_of_untranslated_constitution_lines($app_root, $lang,
'aproximate_number_of_untranslated_lines' => $aproximate_number_of_untranslated_lines,
);
}
+
+function build_language_and_resource_summary($report, $all_languages_only_one_resource = FALSE, $one_resource = NULL, $one_language_all_resources = FALSE, $one_language = NULL)
+{
+ $total_num_of_strings = 0; // total of all source strings
+ $language_summary = array();
+ $resource_summary = array();
+ foreach ($report as $resource_data) {
+ if ($resource_data['language'] == 'en') {
+ $total_num_of_strings += $resource_data['num_of_all_strings'];
+ }
+ // don't add if there is a need to store languages only for one resource
+ if(!$all_languages_only_one_resource || $resource_data['resource_filename'] == $one_resource) {
+ $key_exists = recursive_array_search($resource_data['language'], $language_summary); // is language already in the $language_summary array?
+ if($resource_data['resource_filename'] == $one_resource) {
+ $temp_var[0]['language'] = $resource_data['language'];
+ $temp_var[0]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
+ $temp_var[0]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
+ $temp_var[0]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
+ $temp_var[0]['references'] = $resource_data['references'];
+ $language_summary[] = $temp_var[0];
+ unset($temp_var[0]); // clear var
+ } else {
+ if ($key_exists !== FALSE) {
+ $language_summary[$key_exists]['num_of_all_strings'] += $resource_data['num_of_all_strings'];
+ $language_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] += $resource_data['num_of_fuzzy_or_missing_strings'];
+ $language_summary[$key_exists]['num_of_untranslated_strings'] += $resource_data['num_of_untranslated_strings'];
+ } else {
+ if($key_exists === FALSE) {
+ $key_exists = count($language_summary);
+ }
+ $language_summary[$key_exists]['language'] = $resource_data['language'];
+ $language_summary[$key_exists]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
+ $language_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
+ $language_summary[$key_exists]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
+ $language_summary[$key_exists]['references'] = $resource_data['references'];
+ }
+ }
+ }
+
+ // don't add if there is a need to store resources only for one language
+ if(!$one_language_all_resources || ($resource_data['language'] == $one_language || $resource_data['language'] == 'en')) {
+ $key_exists = recursive_array_search($resource_data['resource_filename'], $resource_summary); // is resource already in the $resource_summary array?
+ if($resource_data['language'] == 'en') {
+ $temp_var[0]['resource_filename'] = $resource_data['resource_filename'];
+ $temp_var[0]['num_of_all_strings'] = $resource_data['num_of_all_strings'];
+ $temp_var[0]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
+ $temp_var[0]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
+ $temp_var[0]['references'] = $resource_data['references'];
+ $resource_summary[] = $temp_var[0];
+ unset($temp_var[0]); // clear var
+ } else {
+ if($one_language_all_resources) {
+ if($key_exists === FALSE) {
+ $key_exists = count($resource_summary);
+ }
+ $resource_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] = $resource_data['num_of_fuzzy_or_missing_strings'];
+ $resource_summary[$key_exists]['num_of_untranslated_strings'] = $resource_data['num_of_untranslated_strings'];
+ $resource_summary[$key_exists]['references'] = $resource_data['references'];
+ } else if ($key_exists !== FALSE) {
+ $resource_summary[$key_exists]['num_of_all_strings'] += $resource_data['num_of_all_strings'];
+ $resource_summary[$key_exists]['num_of_fuzzy_or_missing_strings'] += $resource_data['num_of_fuzzy_or_missing_strings'];
+ $resource_summary[$key_exists]['num_of_untranslated_strings'] += $resource_data['num_of_untranslated_strings'];
+ }
+ }
+ }
+ }
+ foreach ($language_summary as &$single_language_summary) {
+ $single_language_summary['num_of_translated_strings'] =
+ $single_language_summary['num_of_all_strings'] -
+ $single_language_summary['num_of_fuzzy_or_missing_strings'] -
+ $single_language_summary['num_of_untranslated_strings'];
+ }
+ unset($single_language_summary); // foreach by reference
+ foreach ($resource_summary as &$single_resource_summary) {
+ $single_resource_summary['num_of_translated_strings'] =
+ $single_resource_summary['num_of_all_strings'] -
+ $single_resource_summary['num_of_fuzzy_or_missing_strings'] -
+ $single_resource_summary['num_of_untranslated_strings'];
+ }
+ unset($single_resource_summary); // foreach by reference
+
+ return array(
+ 'total_num_of_strings' => $total_num_of_strings, // total of all source strings
+ 'language_summary' => $language_summary,
+ 'resource_summary' => $resource_summary,
+ );
+}
+
+/**
+ * from http://www.php.net/manual/en/function.array-search.php#91365
+ *
+ * copyright (c) the PHP Documentation
+ * covered by the Creative Commons Attribution 3.0 License (http://creativecommons.org/licenses/by/3.0/legalcode)
+*/
+function recursive_array_search($needle, $haystack)
+{
+ foreach ($haystack as $key => $value) {
+ $current_key = $key;
+ if ($needle === $value OR (is_array($value) && recursive_array_search($needle, $value) !== FALSE)) {
+ return $current_key;
+ }
+ }
+ return FALSE;
+}