Automatically migrated from Gitolite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB

10 years ago
  1. <?php
  2. if($_CPHP !== true) { die(); }
  3. class Localizer
  4. {
  5. public $strings = array();
  6. public $locale = "";
  7. public $datetime_short = "";
  8. public $datetime_long = "";
  9. public $date_short = "";
  10. public $date_long = "";
  11. public $time = "";
  12. public function Load($locale)
  13. {
  14. global $cphp_locale_path, $cphp_locale_ext;
  15. $this->strings = array();
  16. $lng_contents = file_get_contents("{$cphp_locale_path}/{$locale}.{$cphp_locale_ext}");
  17. if($lng_contents !== false)
  18. {
  19. $lines = explode("\n", $lng_contents);
  20. foreach($lines as $line)
  21. {
  22. $line = str_replace("\r", "", $line);
  23. if(preg_match("/(.+?[^\\\]);(.+)/", $line, $matches))
  24. {
  25. $key = trim(str_replace("\;", ";", $matches[1]));
  26. $value = trim(str_replace("\;", ";", $matches[2]));
  27. switch($key)
  28. {
  29. case "_locale":
  30. $this->locale = explode(",", $value);
  31. break;
  32. case "_datetime_short":
  33. $this->datetime_short = $value;
  34. break;
  35. case "_datetime_long":
  36. $this->datetime_long = $value;
  37. break;
  38. case "_date_short":
  39. $this->date_short = $value;
  40. break;
  41. case "_date_long":
  42. $this->date_long = $value;
  43. break;
  44. case "_time":
  45. $this->time = $value;
  46. break;
  47. default:
  48. $this->strings[$key] = $value;
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. else
  55. {
  56. Throw new Exception("Failed to load locale {$locale}.");
  57. }
  58. }
  59. }
  60. ?>