函式用於設定默認域。此功能設定領域內進行搜尋時調用的gettext() ,通常命名後的應用程式。
基本介紹
- 中文名:textdomain
- 定義:函式用於設定默認域
- 語法:此功能設定領域內進行搜尋時
- 示例:設定語言包的選項
定義和用法,語法,示例,PHP語言介紹,
定義和用法
textdomain()函式用於設定默認域。
如果成阿晚棕您功的話,這個函式返回當前的訊息域,然後可能改變它。
語法
此功能設定領域內進行搜尋時調用的gettext() ,通常命名店鑽紙良後的應用程式。
string textdomain( string$text_domain)
示例
<?php
classDh_Locale {
/**
* _options 設定語言包的選項
*
* $this->_options['lang'] 應用程式使用什麼語言包.php-gettext支持的所有語言都可以.
* 在ubuntu下使用sudo vim /usr/share/i18n/SUPPORTED 主要是utf8編碼
* $this->_options['domain'] 生成的.mo檔案的名字.一般是應用程式名
*
* @var array
* @access protected
*/
protected$_options;
/**
* __construct 構造函式 對象初始化時設定語言包的參數
*
* @access public
* @return void
*/
publicfunction __construct($lang=null) {
switch( $lang ) {
case'cn':
$this->_options = array('lang'=> 'zh_CN.utf8','domain'=>'Dh');
break;
case'en':
case'us':
case'eu':
$this->_options = array('lang'章槓=> 'en_US.utf8','domain'=>'Dh');
break;
case'de':
$this->_options = array('lang'=> 'de_DE.utf8','domain'=>'Dh');
break;
case'fr':
$this->_options = array('lang'=> 'fr_FR.utf8','domain'=>'Dh');
default:
$this->_options = array('lang'=> 'zh_CN.utf8','domain'=>'企犁阿Dh');
break;
}
$this->setApplicationLocale();
}
/**
* setOptions 設定應用程式語言包的參數 放在在數組$this->_options中
*
* @param mixed $options
* @access public
* @return void
*/
publicfunction setOptions($options) {
if(!empty($options)) {
foreach ($options as $key => $option) {
$this->_options[$key] = $option;
}
}
}
/**
* setApplicationLocale 設定應用程式語言包
*
* @access public
* @return void
*/
publicfunction setApplicationLocale() {
putenv('LANG='.$this->_options['lang']);
setlocale(LC_ALL,$this->_options['lang']);
bindtextdomain($this->_options['domain'],dirname(__FILE__).'/Locale/');
textdomain($this->_options['domain']);
bind_textdomain_codeset($this->_options['domain'],'UTF-8');
}
}
?>
<?php
require_once dirname(__FILE__).'/Locale.php';
//cn or en
$Lang = 'cn';
$Locale = newDh_Locale($Lang);
$Checkout['AddressFields'] = array
(
'慨罪拔Email'=> array
(
'Type'=> 'text',
'Label'=> _('信箱'),
'Title'=> _('請填寫整朵灶信箱'),
'Class'市鍵擊=> 'required',
'Filter'=> 'string',
),
'PostCode'=> array
(
'Type'=> 'text',
'Label'=> _('郵政編碼'),
'Title'=> _('請填寫郵政編碼'),
'Class'=> 'required',
'Filter'=> 'int',
),
);
echo '<pre>';print_r($Checkout);echo '</pre>';
?>
PHP語言介紹
PHP(PHP:Hypertext Preprocessor)是一種在電腦上運行的腳本語言,主要用途是在於處理動態網頁,也包含了命令行運行接口(command line interface),或者產生圖形用戶界面(GUI)程式。PHP最早由Rasmus Lerdorf在1995年發明,而現在PHP的標準由PHP Group和開放原始碼社區維護。PHP以PHP License作為許可協定,不過因為這個協定限制了PHP名稱的使用,所以和開放原始碼許可協定GPL不兼容。PHP的套用範圍相當廣泛,尤其是在網頁程式的開發上。一般來說PHP大多運行在網頁伺服器上,通過運行PHP代碼來產生用戶瀏覽的網頁。PHP可以在多數的伺服器和作業系統上運行,而且使用PHP完全是免費的。
break;
}
$this->setApplicationLocale();
}
/**
* setOptions 設定應用程式語言包的參數 放在在數組$this->_options中
*
* @param mixed $options
* @access public
* @return void
*/
publicfunction setOptions($options) {
if(!empty($options)) {
foreach ($options as $key => $option) {
$this->_options[$key] = $option;
}
}
}
/**
* setApplicationLocale 設定應用程式語言包
*
* @access public
* @return void
*/
publicfunction setApplicationLocale() {
putenv('LANG='.$this->_options['lang']);
setlocale(LC_ALL,$this->_options['lang']);
bindtextdomain($this->_options['domain'],dirname(__FILE__).'/Locale/');
textdomain($this->_options['domain']);
bind_textdomain_codeset($this->_options['domain'],'UTF-8');
}
}
?>
<?php
require_once dirname(__FILE__).'/Locale.php';
//cn or en
$Lang = 'cn';
$Locale = newDh_Locale($Lang);
$Checkout['AddressFields'] = array
(
'Email'=> array
(
'Type'=> 'text',
'Label'=> _('信箱'),
'Title'=> _('請填寫信箱'),
'Class'=> 'required',
'Filter'=> 'string',
),
'PostCode'=> array
(
'Type'=> 'text',
'Label'=> _('郵政編碼'),
'Title'=> _('請填寫郵政編碼'),
'Class'=> 'required',
'Filter'=> 'int',
),
);
echo '<pre>';print_r($Checkout);echo '</pre>';
?>
PHP語言介紹
PHP(PHP:Hypertext Preprocessor)是一種在電腦上運行的腳本語言,主要用途是在於處理動態網頁,也包含了命令行運行接口(command line interface),或者產生圖形用戶界面(GUI)程式。PHP最早由Rasmus Lerdorf在1995年發明,而現在PHP的標準由PHP Group和開放原始碼社區維護。PHP以PHP License作為許可協定,不過因為這個協定限制了PHP名稱的使用,所以和開放原始碼許可協定GPL不兼容。PHP的套用範圍相當廣泛,尤其是在網頁程式的開發上。一般來說PHP大多運行在網頁伺服器上,通過運行PHP代碼來產生用戶瀏覽的網頁。PHP可以在多數的伺服器和作業系統上運行,而且使用PHP完全是免費的。