GP_Locale

The Jetpack by WordPress.com GP Locale class.

Defined (1)

The class is defined in the following location(s).

/locales.php  
  1. class GP_Locale { 
  2. public $english_name; 
  3. public $native_name; 
  4. public $text_direction = 'ltr'; 
  5. public $lang_code_iso_639_1 = null; 
  6. public $lang_code_iso_639_2 = null; 
  7. public $lang_code_iso_639_3 = null; 
  8. public $country_code; 
  9. public $wp_locale; 
  10. public $slug; 
  11. public $nplurals = 2; 
  12. public $plural_expression = 'n != 1'; 
  13. public $google_code = null; 
  14. public $preferred_sans_serif_font_family = null; 
  15. public $facebook_locale = null; 
  16. // TODO: days, months, decimals, quotes 
  17.  
  18. public function __construct( $args = array() ) { 
  19. foreach( $args as $key => $value ) { 
  20. $this->$key = $value; 
  21.  
  22. public static function __set_state( $state ) { 
  23. return new GP_Locale( $state ); 
  24.  
  25. /** 
  26. * Make deprecated properties checkable for backwards compatibility. 
  27. * @param string $name Property to check if set. 
  28. * @return bool Whether the property is set. 
  29. */ 
  30. public function __isset( $name ) { 
  31. if ( 'rtl' == $name ) { 
  32. return isset( $this->text_direction ); 
  33.  
  34. /** 
  35. * Make deprecated properties readable for backwards compatibility. 
  36. * @param string $name Property to get. 
  37. * @return mixed Property. 
  38. */ 
  39. public function __get( $name ) { 
  40. if ( 'rtl' == $name ) { 
  41. return ( 'rtl' === $this->text_direction ); 
  42.  
  43. public function combined_name() { 
  44. /** translators: combined name for locales: 1: name in English, 2: native name */ 
  45. return sprintf( _x( '%1$s/%2$s', 'locales' ), $this->english_name, $this->native_name ); 
  46.  
  47. public function numbers_for_index( $index, $how_many = 3, $test_up_to = 1000 ) { 
  48. $numbers = array(); 
  49.  
  50. for( $number = 0; $number < $test_up_to; ++$number ) { 
  51. if ( $this->index_for_number( $number ) == $index ) { 
  52. $numbers[] = $number; 
  53.  
  54. if ( count( $numbers ) >= $how_many ) { 
  55. break; 
  56.  
  57. return $numbers; 
  58.  
  59. public function index_for_number( $number ) { 
  60. if ( ! isset( $this->_index_for_number ) ) { 
  61. $gettext = new Gettext_Translations; 
  62. $expression = $gettext->parenthesize_plural_exression( $this->plural_expression ); 
  63. $this->_index_for_number = $gettext->make_plural_form_function( $this->nplurals, $expression ); 
  64.  
  65. $f = $this->_index_for_number; 
  66.  
  67. return $f( $number ); 
  68.