PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/i18n/src/locale/lmbLocaleSpec.class.php

http://github.com/limb-php-framework/limb
PHP | 94 lines | 65 code | 16 blank | 13 comment | 5 complexity | 9778b40e428460b73d73a3509527cad0 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. <?php
  2. /*
  3. * Limb PHP Framework
  4. *
  5. * @link http://limb-project.com
  6. * @copyright Copyright &copy; 2004-2009 BIT(http://bit-creative.com)
  7. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  8. */
  9. /**
  10. * class lmbLocaleSpec.
  11. *
  12. * @package i18n
  13. * @version $Id: lmbLocaleSpec.class.php 7486 2009-01-26 19:13:20Z pachanga $
  14. */
  15. class lmbLocaleSpec
  16. {
  17. const REGEX = "~^([a-zA-Z]+) #language identifier
  18. ([_]([a-zA-Z]+))? #separator and the country
  19. (\.([-a-zA-Z0-9]+))? #separator and the charset
  20. (@([a-zA-Z0-9]+))? #separator and the variation
  21. \$~x";
  22. protected $language = '';
  23. protected $country = '';
  24. protected $country_variation = '';
  25. protected $charset = '';
  26. protected $locale = '';
  27. protected $locale_string = '';
  28. function __construct($locale_string)
  29. {
  30. $this->locale_string = $locale_string;
  31. $this->_parse($locale_string);
  32. }
  33. function getLocaleString()
  34. {
  35. return $this->locale_string;
  36. }
  37. function getLanguage()
  38. {
  39. return $this->language;
  40. }
  41. function getCountry()
  42. {
  43. return $this->country;
  44. }
  45. function getCountryVariation()
  46. {
  47. return $this->country_variation;
  48. }
  49. function getCharset()
  50. {
  51. return $this->charset;
  52. }
  53. function getLocale()
  54. {
  55. return $this->locale;
  56. }
  57. protected function _parse($locale_string)
  58. {
  59. if(preg_match(self :: REGEX, $locale_string, $regs))
  60. {
  61. $this->language = strtolower($regs[1]);
  62. if(isset($regs[3]))
  63. $this->country = strtoupper($regs[3]);
  64. if(isset($regs[5]))
  65. $this->charset = strtolower($regs[5]);
  66. if(isset($regs[7]))
  67. $this->country_variation = strtolower($regs[7]);
  68. $this->locale = $this->language;
  69. if($this->country !== '')
  70. $this->locale .= '_' . $this->country;
  71. }
  72. else
  73. {
  74. $this->locale = strtolower($locale_string);
  75. $this->language = $this->locale;
  76. }
  77. }
  78. }