ngg_locale

Install locale files from WordPress.org plugin repository.

Defined (1)

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

/lib/locale.php  
  1. class ngg_locale { 
  2.  
  3. /** 
  4. * Current locale 
  5. * @var string 
  6. */ 
  7. var $locale = ''; 
  8.  
  9. /** 
  10. * Plugin domain name 
  11. * @var string 
  12. */ 
  13. var $domain = 'nggallery'; 
  14.  
  15. /** 
  16. * URL to the translation files 
  17. * @var string 
  18. */ 
  19. var $remote_locale_url = 'http://nextgen-gallery.googlecode.com/files/'; 
  20.  
  21. /** 
  22. * Plugin path to the langauage files  
  23. * @var string 
  24. */ 
  25. var $plugin_locale_path = 'lang'; 
  26.  
  27. /** 
  28. * Server path to the locale file on the server 
  29. * @var string 
  30. */ 
  31. var $mo_file = ''; 
  32.  
  33. /** 
  34. * URL to the locale file from the remote server 
  35. * @var string 
  36. */ 
  37. var $mo_url = ''; 
  38.  
  39. /** 
  40. * Repsonse code for request 
  41. * @var array 
  42. */ 
  43. var $repsonse = ''; 
  44.  
  45. /** 
  46. * Init the Database Abstraction layer for NextGEN Gallery 
  47. *  
  48. */  
  49. function __construct() { 
  50. $this->plugin_locale_path = NGGALLERY_ABSPATH . 'lang/'; 
  51. $this->locale = get_locale(); 
  52.  
  53. $this->mo_file = trailingslashit($this->plugin_locale_path) . $this->domain . '-' . $this->locale . '.mo'; 
  54. $this->mo_url = trailingslashit($this->remote_locale_url) . $this->domain . '-' . $this->locale . '.mo'; 
  55.  
  56. /** 
  57. * This functions checks if a translation is at wp.org available 
  58. * Please note, if a language file is already loaded it exits as well 
  59. * @return string result of check ( default | installed | not_exist | available ) 
  60. */ 
  61. function check() { 
  62.  
  63. // we do not need to check for translation if you use english 
  64. if ( ($this->locale == 'en_US') ) 
  65. return 'default'; 
  66.  
  67. $this->response = wp_remote_get($this->mo_url, array('timeout' => 300)); 
  68.  
  69. // if a language file exist, do not load it again 
  70. if ( is_readable( $this->mo_file ) )  
  71. return 'installed'; 
  72.  
  73. // if no translation file exists exit the check 
  74. if ( is_wp_error($this->response) || $this->response['response']['code'] != '200' ) 
  75. return 'not_exist'; 
  76.  
  77. return 'available';  
  78.  
  79. /** 
  80. * Downloads a locale to the plugin folder using the WordPress HTTP Class. 
  81. * @author taken from WP core  
  82. * @return mixed WP_Error on failure, true on success. 
  83. */ 
  84. function download_locale() { 
  85.  
  86. $url = $this->mo_url; 
  87.  
  88. if ( ! $url ) 
  89. return new WP_Error('http_no_url', __('Invalid URL Provided.')); 
  90.  
  91. $filename = $this->mo_file; 
  92. if ( ! $filename ) 
  93. return new WP_Error('http_no_file', __('Could not create Temporary file.')); 
  94.  
  95. $handle = @fopen($filename, 'wb'); 
  96. if ( ! $handle ) 
  97. return new WP_Error('http_no_file', __('Could not create Temporary file.')); 
  98.  
  99. $response = wp_remote_get($url, array('timeout' => 300)); 
  100.  
  101. if ( is_wp_error($response) ) { 
  102. fclose($handle); 
  103. unlink($filename); 
  104. return $response; 
  105.  
  106. if ( $response['response']['code'] != '200' ) { 
  107. fclose($handle); 
  108. unlink($filename); 
  109. return new WP_Error('http_404', trim($response['response']['message'])); 
  110.  
  111. fwrite($handle, $response['body']); 
  112. fclose($handle); 
  113.  
  114. return true; 
  115.