Yii Framework v1.1.10 绫诲弬鑰

CGettextPoFile

system.i18n.gettext
缁ф壙 class CGettextPoFile » CGettextFile » CComponent
婧愯嚜 1.0
鐗堟湰 $Id: CGettextPoFile.php 2798 2011-01-01 19:29:03Z qiang.xue $
婧愮爜 framework/i18n/gettext/CGettextPoFile.php
CGettextPoFile浠h〃涓涓狿O鐨凣ettext淇℃伅鏂囦欢銆

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
load() 浠嶱O鏂囦欢鍔犺浇淇℃伅銆 CGettextPoFile
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
save() 淇濆瓨淇℃伅鍒癙O鏂囦欢銆 CGettextPoFile

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
decode() 淇℃伅涓殑鎸囧畾瀛楃杩涜瑙g爜銆 CGettextPoFile
encode() 淇℃伅涓殑鎸囧畾瀛楃杩涜缂栫爜銆 CGettextPoFile

鏂规硶璇︾粏

decode() 鏂规硶
protected string decode(string $string)
$string string 瑕佽В鐮佺殑淇℃伅
{return} string 杩斿洖宸茬粡瑙g爜鐨勪俊鎭
婧愮爜锛 framework/i18n/gettext/CGettextPoFile.php#85 (鏄剧ず)
protected function decode($string)
{
    return 
str_replace(array('\\"'"\\n"'\\t''\\r'),array('"'"\n""\t""\r"),$string);
}

淇℃伅涓殑鎸囧畾瀛楃杩涜瑙g爜銆

encode() 鏂规硶
protected string encode(string $string)
$string string 瑕佺紪鐮佺殑淇℃伅
{return} string 杩斿洖宸茬粡缂栫爜鐨勪俊鎭
婧愮爜锛 framework/i18n/gettext/CGettextPoFile.php#75 (鏄剧ず)
protected function encode($string)
{
    return 
str_replace(array('"'"\n""\t""\r"),array('\\"'"\\n"'\\t''\\r'),$string);
}

淇℃伅涓殑鎸囧畾瀛楃杩涜缂栫爜銆

load() 鏂规硶
public array load(string $file, string $context)
$file string 鏂囦欢璺緞
$context string 淇℃伅鍐呭
{return} array 缈昏瘧鐨勪俊鎭紙婧愪俊鎭 => 缈昏瘧鐨勪俊鎭級
婧愮爜锛 framework/i18n/gettext/CGettextPoFile.php#27 (鏄剧ず)
public function load($file,$context)
{
    
$pattern='/(msgctxt\s+"(.*?(?<!\\\\))")?'
        
'\s+msgid\s+"(.*?(?<!\\\\))"'
        
'\s+msgstr\s+"(.*?(?<!\\\\))"/';
    
$content=file_get_contents($file);
    
$n=preg_match_all($pattern,$content,$matches);
    
$messages=array();
    for(
$i=0;$i<$n;++$i)
    {
        if(
$matches[2][$i]===$context)
        {
            
$id=$this->decode($matches[3][$i]);
            
$message=$this->decode($matches[4][$i]);
            
$messages[$id]=$message;
        }
    }
    return 
$messages;
}

浠嶱O鏂囦欢鍔犺浇淇℃伅銆

save() 鏂规硶
public void save(string $file, array $messages)
$file string 鏂囦欢璺緞
$messages array 缈昏瘧鐨勪俊鎭紙淇℃伅ID => 缈昏瘧鐨勪俊鎭級銆 娉ㄦ剰锛 濡傛灉淇℃伅鏈変笂涓嬫枃锛屼俊鎭疘D涓瀹氳鐢ㄤ笂涓嬫枃鐨 chr(4) 鍓嶇紑浣滀负鍒嗛殧绗︺
婧愮爜锛 framework/i18n/gettext/CGettextPoFile.php#54 (鏄剧ず)
public function save($file,$messages)
{
    
$content='';
    foreach(
$messages as $id=>$message)
    {
        if((
$pos=strpos($id,chr(4)))!==false)
        {
            
$content.='msgctxt "'.substr($id,0,$pos)."\"\n";
            
$id=substr($id,$pos+1);
        }
        
$content.='msgid "'.$this->encode($id)."\"\n";
        
$content.='msgstr "'.$this->encode($message)."\"\n\n";
    }
    
file_put_contents($file,$content);
}

淇濆瓨淇℃伅鍒癙O鏂囦欢銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.