build_translation_request_file.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php /* For licensing terms, see /license.txt */
  2. /**
  3. * Generate a file with the undefined terms of one language and another file with the existing English terms.
  4. * Copy-paste the resulting page in an Excel spreasheet to have it ready to go for translators
  5. * @package chamilo.cron
  6. */
  7. /**
  8. * Includes and declarations
  9. */
  10. die();
  11. require_once '../../main/inc/global.inc.php';
  12. $path = api_get_path(SYS_LANG_PATH);
  13. $referenceLanguage = 'english';
  14. $language = 'german';
  15. ini_set('memory_limit','128M');
  16. /**
  17. * Main code
  18. */
  19. $referenceTerms = array();
  20. $file = $path . $referenceLanguage . '/trad4all.inc.php';
  21. if (is_file($file)) {
  22. $referenceTerms = array_merge($referenceTerms, SubLanguageManager::get_all_language_variable_in_file($file,true));
  23. }
  24. // get only the array keys (the language variables defined in language files)
  25. $definedTerms = array_keys($referenceTerms);
  26. //print_r($definedTerms);
  27. //$referenceTerms = null;
  28. // now get all terms found in the destination language files of Chamilo (this takes some time and memory)
  29. $missingTerms = array();
  30. $nonMissingTerms = array();
  31. $l = strlen(api_get_path(SYS_PATH));
  32. $file = $path . $language . '/trad4all.inc.php';
  33. if (is_file($file)) {
  34. $nonMissingTerms = array_merge($nonMissingTerms, SubLanguageManager::get_all_language_variable_in_file($file,true));
  35. }
  36. $nonMissingTerms = array_keys($nonMissingTerms);
  37. //print_r($nonMissingTerms);
  38. $missingTerms = array_diff($definedTerms, $nonMissingTerms);
  39. //print_r($missingTerms);
  40. echo "<table border='1'>\n";
  41. echo "<tr><th>Count</th><th>Term</th><th>English</th><th>German</th></tr>";
  42. $i = 1;
  43. $countWords = 0;
  44. foreach ($missingTerms as $key => $term) {
  45. if (isset($referenceTerms[$term])) {
  46. $trimmed = trim($referenceTerms[$term],';" ');
  47. $countWords += str_word_count($trimmed);
  48. echo "<tr><td>$i</td><td>$term</td><td>".$trimmed."</td><td></td></tr>\n";
  49. }
  50. $i++;
  51. }
  52. echo "</table>\n";
  53. echo "Total words to be translated: ".$countWords.PHP_EOL;