PHP Classes

File: rbib/util/i18n/Language.php

Recommend this page to a friend!
  Classes of Zhao   Parse the User Language   rbib/util/i18n/Language.php   Download  
File: rbib/util/i18n/Language.php
Role: Class source
Content type: text/plain
Description: Language class
Class: Parse the User Language
Determine the language supported by the browser
Author: By
Last change: Change the error code for non-ASCII string
Date: 9 years ago
Size: 1,885 bytes
 

Contents

Class file image Download
<?php

/**
 * rbib/util/i18n/Language.php
 * $Date:: #$
 * @version $
 * @package rbib\util\i18n
 */

namespace rbib\util\i18n;

class
Language
{

   
/**
     * Language parameter
     */
   
const LANGUAGE = 'hl';

   
/**
     * Default Language
     */
   
const DEFAULT_LANGUAGE = 'en';

   
/**
     * Supported Language List
     *
     * @var array
     */
   
private $supportedLanguage = array(
       
'en' => 'English',
       
'ja' => '&#26085;&#26412;&#35486;',
       
'cn' => '&#20013;&#25991;',
    );

   
/**
     *
     * @var string
     */
   
private $languge = 'ja';

   
/**
     * Constructor
     */
   
public function __construct()
    {
       
$hl = isset($_GET[self::LANGUAGE]) ? $_GET[self::LANGUAGE] : @$_COOKIE[self::LANGUAGE];

        if (!
$hl) {
           
$hl = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
        }

       
$this->setLanguage($hl);
    }

   
/**
     * Change the browser language
     *
     * @param string $hl
     * @return Language
     */
   
public function setLanguage($hl)
    {
        if (!isset(
$this->supportedLanguage[$hl])) {
           
$hl = self::DEFAULT_LANGUAGE;
        }
       
$this->languge = $hl;

        return
$this;
    }

   
/**
     * Return the browser default language
     *
     * @return string
     */
   
public function getLanauge()
    {
        return
$this->languge;
    }

   
/**
     * Return the default langauge name
     *
     * @return string
     */
   
public function getLanguageName()
    {
        return
$this->supportedLanguage[$this->languge];
    }

   
/**
     * Return the supported language list of application
     *
     * @return array
     */
   
public function getSupportedLanguage()
    {
        return
$this->supportedLanguage;
    }

}