Locale.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. class Application_Model_Locale
  3. {
  4. public static $locales = array(
  5. "en_CA" => "English (Canada)",
  6. "en_GB" => "English (Britain)",
  7. "en_US" => "English (USA)",
  8. "cs_CZ" => "Český",
  9. "de_DE" => "Deutsch",
  10. "de_AT" => "Deutsch (Österreich)",
  11. "el_GR" => "Ελληνικά",
  12. "es_ES" => "Español",
  13. "fr_FR" => "Français",
  14. "hr_HR" => "Hrvatski",
  15. "hu_HU" => "Magyar",
  16. "it_IT" => "Italiano",
  17. "ja_JP" => "日本語",
  18. "ko_KR" => "한국어",
  19. "pl_PL" => "Polski",
  20. "pt_BR" => "Português (Brasil)",
  21. "ru_RU" => "Русский",
  22. "sr_RS" => "Српски (Ћирилица)",
  23. "sr_RS@latin" => "Srpski (Latinica)",
  24. "zh_CN" => "简体中文"
  25. );
  26. public static function getLocales()
  27. {
  28. return self::$locales;
  29. }
  30. public static function configureLocalization($locale = null)
  31. {
  32. $codeset = 'UTF-8';
  33. if (is_null($locale)) {
  34. $lang = Application_Model_Preference::GetLocale().'.'.$codeset;
  35. } else {
  36. $lang = $locale.'.'.$codeset;
  37. }
  38. putenv("LC_ALL=$lang");
  39. putenv("LANG=$lang");
  40. $res = setlocale(LC_MESSAGES, $lang);
  41. $domain = 'airtime';
  42. bindtextdomain($domain, '../locale');
  43. textdomain($domain);
  44. bind_textdomain_codeset($domain, $codeset);
  45. }
  46. /**
  47. * We need this function for the case where a user has logged out, but
  48. * has an airtime_locale cookie containing their locale setting.
  49. *
  50. * If the user does not have an airtime_locale cookie set, we default
  51. * to the station locale.
  52. *
  53. * When the user logs in, the value set in the login form will be passed
  54. * into the airtime_locale cookie. This cookie is also updated when
  55. * a user updates their user settings.
  56. */
  57. public static function getUserLocale() {
  58. $request = Zend_Controller_Front::getInstance()->getRequest();
  59. $locale = $request->getCookie('airtime_locale', Application_Model_Preference::GetLocale());
  60. return $locale;
  61. }
  62. }