langstats.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script prints a list of most used language terms. The registration of
  5. * frequency for language variables is a very heavy operation.
  6. * To enable, add "$_configuration['language_measure_frequency' ] = 1;" at the
  7. * end of main/inc/conf/configuration.php. Remove when done.
  8. * Add ?output=1 to the URL to generate languag files in /tmp/lang/ with just
  9. * the number of terms you want.
  10. */
  11. /**
  12. * Requires
  13. */
  14. die();
  15. $language_file = array(
  16. 'accessibility', 'gradebook', 'registration', 'admin', 'group', 'reportlib',
  17. 'agenda', 'help', 'reservation', 'announcements', 'hotspot', 'resourcelinker',
  18. 'blog', 'import', 'scormbuilder', 'chat', 'scormdocument', 'coursebackup',
  19. 'index', 'scorm', 'course_description', 'install', 'shibboleth',
  20. 'course_home', 'learnpath', 'slideshow', 'course_info', 'link', 'survey',
  21. 'courses', 'md_document', 'tracking', 'create_course', 'md_link',
  22. 'trad4all', 'document', 'md_mix', 'userInfo', 'dropbox', 'md_scorm',
  23. 'videoconf', 'exercice', 'messages', 'wiki', 'external_module', 'myagenda',
  24. 'work', 'forum', 'notebook', 'glossary', 'notification'
  25. );
  26. require_once '../../inc/global.inc.php';
  27. require_once 'langstats.class.php';
  28. /**
  29. * Init
  30. */
  31. $terms_limit = 10000 + 50;
  32. $x_most_popular = 2000;
  33. $output = false;
  34. $ls = new langstats();
  35. if ($ls === false) {
  36. exit($ls->error);
  37. }
  38. $list = $ls->get_popular_terms($x_most_popular);
  39. if ($_GET['output'] == 1) {
  40. $output = true;
  41. $variables_origin = $ls->get_variables_origin();
  42. }
  43. /**
  44. * Display
  45. */
  46. if (count($list)==0) { echo 'No terms loaded so far'; }
  47. if (count($list)>0) {
  48. $i = 1;
  49. $j = 1;
  50. $k = 0;
  51. $files = array();
  52. $trans = array();
  53. echo 'Number of records: '.count($list).'<br />';
  54. echo '<table><tr><th>Index</th><th>Registration order</th><th>Term</th>'.($output==1?'<th>Origin</th>':'').'<th>Count</th></tr>';
  55. foreach($list as $elem) {
  56. if ($k > $terms_limit) { break; }
  57. $fixed_elem = $elem;
  58. if ($output) {
  59. if (empty($variables_origin[$elem['term_name']]) && !empty($variables_origin['lang'.$elem['term_name']])) {
  60. $fixed_elem = array('id' => $elem['id'], 'term_name' => 'lang'.$elem['term_name'], 'term_count' => $elem['term_count']);
  61. }
  62. if (empty($variables_origin[$fixed_elem['term_name']])) {
  63. continue;
  64. }
  65. $files[$variables_origin[$fixed_elem['term_name']]][] = $fixed_elem['term_name'];
  66. $translation = get_lang($fixed_elem['term_name']);
  67. $k += str_word_count($translation);
  68. $trans[$fixed_elem['term_name']] = $translation;
  69. $j++;
  70. }
  71. echo '<tr><td>',$i,
  72. '</td><td>',$fixed_elem['id'],
  73. '</td><td>',$fixed_elem['term_name'];
  74. if ($output) {
  75. echo '</td><td>'.$variables_origin[$fixed_elem['term_name']];
  76. }
  77. echo '</td><td>',$fixed_elem['term_count'],'</td></tr>';
  78. $i++;
  79. }
  80. echo '</table>';
  81. if ($output) {
  82. @mkdir('/tmp/lang');
  83. foreach ($files as $file => $terms) {
  84. @touch('/tmp/lang/'.$file);
  85. file_put_contents('/tmp/lang/'.$file,"<?php".PHP_EOL);
  86. foreach ($terms as $term) {
  87. file_put_contents('/tmp/lang/'.$file,'$'.$term.' = "'.str_replace('"','\"',$trans[$term]).'";'.PHP_EOL, FILE_APPEND);
  88. }
  89. }
  90. }
  91. }