Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. <?php
  2. /**
  3. * @version $Id: language.php 14401 2010-01-26 14:10:00Z Zaharia $
  4. * @package Invoice.Framework
  5. * @subpackage LANGUAGE
  6. * @copyright Copyright (C) 2010 - 2011 Development for Future. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Acron Invoice! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14.  
  15. class inv_Lang
  16. {
  17. /**
  18. * Debug language, If true, highlights if string isn't found
  19. *
  20. * @var boolean
  21. * @access protected
  22. * @since 1.5
  23. */
  24. var $_debug = false;
  25.  
  26. /**
  27. * The default language
  28. *
  29. * The default language is used when a language file in the requested language does not exist.
  30. *
  31. * @var string
  32. * @access protected
  33. * @since 1.5
  34. */
  35. var $_default = 'en-GB';
  36.  
  37. function __construct(){
  38.  
  39. $default_lang = inv_Lang::detect_lang();
  40.  
  41. if( file_exists(APATH_LANGUAGE.DS."$default_lang.php")){
  42. require APATH_LANGUAGE.DS."$default_lang.php";
  43. }
  44. else{
  45. require APATH_LANGUAGE.DS.$this->_default.".php";
  46. }
  47. }
  48.  
  49. /**
  50. * Gets the string from the array
  51. *
  52. * @param string $array_index
  53. * @param string $message
  54. * @return string
  55. * @access private
  56. */
  57. function _get( $array_index, $message ) {
  58. if( is_array( $message )) {
  59. return @$GLOBALS[$array_index][key($message)][current($message)];
  60. }
  61. return isset($GLOBALS[$array_index][$message]) ? $GLOBALS[$array_index][$message] : $message;
  62. }
  63.  
  64. function detect_lang() {
  65. //$default = 'romanian';
  66.  
  67. if( empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return $this->_default;
  68.  
  69. $_AL = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
  70. $_UA = strtolower($_SERVER['HTTP_USER_AGENT']);
  71.  
  72. // Try to detect Primary language if several languages are accepted',
  73. foreach($GLOBALS['_LANG'] as $K => $lang) {
  74. if( strpos($_AL, $K) === 0 )
  75. return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
  76. }
  77.  
  78. // Try to detect any language if not yet detected',
  79. foreach($GLOBALS['_LANG'] as $K => $lang) {
  80. if( strpos( $_AL, $K )!== false )
  81. return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
  82. }
  83. foreach($GLOBALS['_LANG'] as $K => $lang) {
  84. if(preg_match("/[\[\( ]{$K}[;,_\-\)]/",$_UA))
  85. return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
  86. }
  87.  
  88. // Return default language if language is not yet detected',
  89. return $this->_default;
  90. }
  91. }
  92.  
  93. // Define all available languages',
  94. // WARNING: uncomment all available languages
  95.  
  96. $GLOBALS['_LANG'] = array(
  97. 'af' => 'afrikaans',
  98. 'ar' => 'arabic',
  99. 'bg' => 'bulgarian',
  100. 'ca' => 'catalan',
  101. 'cs' => 'czech',
  102. 'da' => 'danish',
  103. 'de' => 'german',
  104. 'el' => 'greek',
  105. 'en' => 'english',
  106. 'es' => 'spanish',
  107. 'et' => 'estonian',
  108. 'fi' => 'finnish',
  109. 'fr' => 'french',
  110. 'gl' => 'galician',
  111. 'he' => 'hebrew',
  112. 'hi' => 'hindi',
  113. 'hr' => 'croatian',
  114. 'hu' => 'hungarian',
  115. 'id' => 'indonesian',
  116. 'it' => 'italian',
  117. 'ja' => 'japanese',
  118. 'ko' => 'korean',
  119. 'ka' => 'georgian',
  120. 'lt' => 'lithuanian',
  121. 'lv' => 'latvian',
  122. 'ms' => 'malay',
  123. 'nl' => 'dutch',
  124. 'no' => 'norwegian',
  125. 'pl' => 'polish',
  126. 'pt' => 'portuguese',
  127. 'ro' => 'romanian',
  128. 'ru' => 'russian',
  129. 'sk' => 'slovak',
  130. 'sl' => 'slovenian',
  131. 'sq' => 'albanian',
  132. 'sr' => 'serbian',
  133. 'sv' => 'swedish',
  134. 'th' => 'thai',
  135. 'tr' => 'turkish',
  136. 'uk' => 'ukrainian',
  137. 'zh-tw' => 'traditional_chinese',
  138. 'zh-cn' => 'simplified_chinese'
  139. );
  140.  
  141. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement