get_translation.lib.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* See license terms in /dokeos_license.txt */
  3. /**
  4. * Library for language translation from Dokeos language files to XML for videoconference
  5. * @uses main_api.lib.php for api_get_path()
  6. */
  7. /**
  8. * This function reads a Dokeos language file and transforms it into XML,
  9. * then returns the XML string to the caller.
  10. */
  11. function get_language_file_as_xml($language='english')
  12. {
  13. $path = api_get_path(SYS_LANG_PATH).$language.'/';
  14. if(!is_dir($path) or !is_readable($path))
  15. {
  16. if($language != 'english')
  17. {
  18. return get_language_file_as_xml('english');
  19. }
  20. else
  21. {
  22. return '';
  23. }
  24. }
  25. //error_log('Analysing path '.$path);
  26. $file = $path.'videoconf.inc.php';
  27. if(!is_file($file) or !is_readable($file))
  28. {
  29. if($language != 'english')
  30. {
  31. return get_language_file_as_xml('english');
  32. }
  33. else
  34. {
  35. return '';
  36. }
  37. }
  38. $convert = true;
  39. if(substr($language,-7,7) == 'unicode')
  40. {//do not convert if the language ends with 'unicode', which means it's in UTF-8
  41. $convert=false;
  42. }
  43. $list = file($file);
  44. $xml = '';
  45. foreach ( $list as $line )
  46. {
  47. if(substr($line,0,1)=='$')
  48. {
  49. $items = array();
  50. $match = preg_match('/^\$([^\s]*)\s*=\s*"(.*)";$/',$line,$items);
  51. if($match)
  52. {
  53. //todo: The following conversion should only happen for old language files (encoded in ISO-8859-1).
  54. if($convert)
  55. {
  56. $string = mb_convert_encoding($items[2],'UTF-8','ISO-8859-1');
  57. }
  58. else
  59. {
  60. $string = $items[2];
  61. }
  62. $xml .= '<labelfield><labelid>'.$items[1].'</labelid><labelvalue>'.stripslashes($string).'</labelvalue></labelfield>'."\n";
  63. }
  64. }
  65. }
  66. if(empty($xml) && $language!='english')
  67. {
  68. return get_language_file_as_xml('english');
  69. }
  70. return $xml;
  71. }
  72. ?>