Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @version $Id: language.php 14401 2010-01-26 14:10:00Z Zaharia $
- * @package Invoice.Framework
- * @subpackage LANGUAGE
- * @copyright Copyright (C) 2010 - 2011 Development for Future. All rights reserved.
- * @license GNU/GPL, see LICENSE.php
- * Acron Invoice! is free software. This version may have been modified pursuant
- * to the GNU General Public License, and as distributed it includes or
- * is derivative of works licensed under the GNU General Public License or
- * other free or open source software licenses.
- * See COPYRIGHT.php for copyright notices and details.
- */
- class inv_Lang
- {
- /**
- * Debug language, If true, highlights if string isn't found
- *
- * @var boolean
- * @access protected
- * @since 1.5
- */
- var $_debug = false;
- /**
- * The default language
- *
- * The default language is used when a language file in the requested language does not exist.
- *
- * @var string
- * @access protected
- * @since 1.5
- */
- var $_default = 'en-GB';
- function __construct(){
- $default_lang = inv_Lang::detect_lang();
- if( file_exists(APATH_LANGUAGE.DS."$default_lang.php")){
- require APATH_LANGUAGE.DS."$default_lang.php";
- }
- else{
- require APATH_LANGUAGE.DS.$this->_default.".php";
- }
- }
- /**
- * Gets the string from the array
- *
- * @param string $array_index
- * @param string $message
- * @return string
- * @access private
- */
- function _get( $array_index, $message ) {
- if( is_array( $message )) {
- return @$GLOBALS[$array_index][key($message)][current($message)];
- }
- return isset($GLOBALS[$array_index][$message]) ? $GLOBALS[$array_index][$message] : $message;
- }
- function detect_lang() {
- //$default = 'romanian';
- if( empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) return $this->_default;
- $_AL = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
- $_UA = strtolower($_SERVER['HTTP_USER_AGENT']);
- // Try to detect Primary language if several languages are accepted',
- foreach($GLOBALS['_LANG'] as $K => $lang) {
- if( strpos($_AL, $K) === 0 )
- return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
- }
- // Try to detect any language if not yet detected',
- foreach($GLOBALS['_LANG'] as $K => $lang) {
- if( strpos( $_AL, $K )!== false )
- return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
- }
- foreach($GLOBALS['_LANG'] as $K => $lang) {
- if(preg_match("/[\[\( ]{$K}[;,_\-\)]/",$_UA))
- return file_exists( APATH_LANGUAGE.DS.$lang.'.php' ) ? $lang : $this->_default;
- }
- // Return default language if language is not yet detected',
- return $this->_default;
- }
- }
- // Define all available languages',
- // WARNING: uncomment all available languages
- $GLOBALS['_LANG'] = array(
- 'af' => 'afrikaans',
- 'ar' => 'arabic',
- 'bg' => 'bulgarian',
- 'ca' => 'catalan',
- 'cs' => 'czech',
- 'da' => 'danish',
- 'de' => 'german',
- 'el' => 'greek',
- 'en' => 'english',
- 'es' => 'spanish',
- 'et' => 'estonian',
- 'fi' => 'finnish',
- 'fr' => 'french',
- 'gl' => 'galician',
- 'he' => 'hebrew',
- 'hi' => 'hindi',
- 'hr' => 'croatian',
- 'hu' => 'hungarian',
- 'id' => 'indonesian',
- 'it' => 'italian',
- 'ja' => 'japanese',
- 'ko' => 'korean',
- 'ka' => 'georgian',
- 'lt' => 'lithuanian',
- 'lv' => 'latvian',
- 'ms' => 'malay',
- 'nl' => 'dutch',
- 'no' => 'norwegian',
- 'pl' => 'polish',
- 'pt' => 'portuguese',
- 'ro' => 'romanian',
- 'ru' => 'russian',
- 'sk' => 'slovak',
- 'sl' => 'slovenian',
- 'sq' => 'albanian',
- 'sr' => 'serbian',
- 'sv' => 'swedish',
- 'th' => 'thai',
- 'tr' => 'turkish',
- 'uk' => 'ukrainian',
- 'zh-tw' => 'traditional_chinese',
- 'zh-cn' => 'simplified_chinese'
- );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement