translate_all_languages_array_to_po.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $sysPath = __DIR__.'/../../';
  4. require_once $sysPath.'main/inc/global.inc.php';
  5. //Source language do not change
  6. $dir = $sysPath.'main/lang/';
  7. //Destination
  8. $save_path = $sysPath.'src/Chamilo/CoreBundle/Resources/translations/';
  9. //The new po files will be saved in $dir.'/LC_MESSAGES/';
  10. if (!is_dir($save_path)) {
  11. mkdir($save_path);
  12. }
  13. /*
  14. if (!is_dir($save_dir_path).'/LC_MESSAGES') {
  15. mkdir($save_dir_path.'/LC_MESSAGES');
  16. }*/
  17. $englishDir = $sysPath.'main/lang/english';
  18. $languages = [
  19. 'arabic' => 'ar',
  20. 'asturian' => 'ast',
  21. 'basque' => 'eu',
  22. 'bengali' => 'bn',
  23. 'bosnian' => 'bs',
  24. 'brazilian' => 'pt-BR',
  25. 'bulgarian' => 'bg',
  26. 'catalan' => 'ca',
  27. 'croatian' => 'hr',
  28. 'czech' => 'cs',
  29. 'danish' => 'da',
  30. 'dari' => 'prs',
  31. 'dutch' => 'nl',
  32. 'english' => 'en',
  33. 'esperanto' => 'eo',
  34. 'faroese' => 'fo',
  35. 'finnish' => 'fi',
  36. 'french' => 'fr',
  37. 'friulian' => 'fur',
  38. 'galician' => 'gl',
  39. 'georgian' => 'ka',
  40. 'german' => 'de',
  41. 'greek' => 'el',
  42. 'hebrew' => 'he',
  43. 'hindi' => 'hi',
  44. 'hungarian' => 'hu',
  45. 'indonesian' => 'id',
  46. 'italian' => 'it',
  47. 'japanese' => 'ja',
  48. 'korean' => 'ko',
  49. 'latvian' => 'lv',
  50. 'lithuanian' => 'lt',
  51. 'macedonian' => 'mk',
  52. 'malay' => 'ms',
  53. 'norwegian' => 'no',
  54. 'occitan' => 'oc',
  55. 'pashto' => 'ps',
  56. 'persian' => 'fa',
  57. 'polish' => 'pl',
  58. 'portuguese' => 'pt',
  59. 'quechua_cusco' => 'qu',
  60. 'romanian' => 'ro',
  61. 'russian' => 'ru',
  62. 'serbian' => 'sr',
  63. 'simpl_chinese' => 'zh',
  64. 'slovak' => 'sk',
  65. 'slovenian' => 'sl',
  66. 'somali' => 'so',
  67. 'spanish' => 'es',
  68. 'swahili' => 'sw',
  69. 'swedish' => 'sv',
  70. 'tagalog' => 'tl',
  71. 'thai' => 'th',
  72. 'tibetan' => 'bo',
  73. 'trad_chinese' => 'zh-TW',
  74. 'turkish' => 'tr',
  75. 'ukrainian' => 'uk',
  76. 'vietnamese' => 'vi',
  77. 'xhosa' => 'xh',
  78. 'yoruba' => 'yo',
  79. ];
  80. $simple = ['spanish', 'french', 'english'];
  81. $iterator = new FilesystemIterator($dir);
  82. foreach ($iterator as $folder) {
  83. if ($folder->isDir()) {
  84. $langPath = $folder->getPathname();
  85. if (!in_array($folder->getBasename(), $simple)) {
  86. continue;
  87. }
  88. $langIterator = new FilesystemIterator($langPath);
  89. $filter = new RegexIterator($langIterator, '/\.(php)$/');
  90. foreach ($filter as $phpFile) {
  91. $phpFilePath = $phpFile->getPathname();
  92. if ($phpFile->getBasename() != 'trad4all.inc.php') {
  93. continue;
  94. }
  95. $po = file($phpFilePath);
  96. $translations = array();
  97. $englishFile = $englishDir.'/'.$phpFile->getBasename();
  98. echo $englishFile.PHP_EOL;
  99. foreach ($po as $line) {
  100. $pos = strpos($line, '=');
  101. if ($pos) {
  102. $variable = (substr($line, 1, $pos - 1));
  103. $variable = trim($variable);
  104. if ($variable == 'NameOfLang' || $variable == '0') {
  105. continue;
  106. }
  107. require $englishFile;
  108. $my_variable_in_english = $variable;
  109. require $phpFilePath;
  110. $my_variable = $$variable;
  111. $translations[] = array(
  112. 'msgid' => $my_variable_in_english,
  113. 'msgstr' => $my_variable
  114. );
  115. }
  116. }
  117. //$code = api_get_language_isocode($folder->getBasename());
  118. $code = isset($languages[$folder->getBasename(
  119. )]) ? $languages[$folder->getBasename()] : 'what';
  120. //LC_MESSAGES
  121. $fileName = $phpFile->getBasename('.php');
  122. $fileName = 'messages';
  123. $new_po_file = $save_path.'/'.$fileName.'.'.$code.'.po';
  124. /*if (!is_dir($save_path.$folder->getBasename())) {
  125. mkdir($save_path.$folder->getBasename());
  126. }*/
  127. $fp = fopen($new_po_file, 'w');
  128. foreach ($translations as $item) {
  129. $line = 'msgid "'.$item['msgid'].'"'."\n";
  130. $line .= 'msgstr "'.nl2br(str_replace(array("\r\n", "\n"), "<br />", addcslashes($item['msgstr'], '"'))).'"'."\n\n";
  131. fwrite($fp, $line);
  132. }
  133. fclose($fp);
  134. echo $new_po_file.PHP_EOL;
  135. echo 'finish' .PHP_EOL;
  136. }
  137. }
  138. }