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淇℃伅鏂囦欢銆
鍏叡鏂规硶
鍙椾繚鎶ゆ柟娉
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
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鏂囦欢銆