<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>哇寶部落格 &#187; php</title>
	<atom:link href="http://blog.wabow.com/archives/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.wabow.com</link>
	<description>Wabow Information Inc. Blog</description>
	<lastBuildDate>Fri, 20 Jan 2012 09:19:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[PHP-ZF] Zend_Translate 試用報告</title>
		<link>http://blog.wabow.com/archives/1472</link>
		<comments>http://blog.wabow.com/archives/1472#comments</comments>
		<pubDate>Thu, 11 Jun 2009 06:09:43 +0000</pubDate>
		<dc:creator>abu</dc:creator>
				<category><![CDATA[技術分享]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.wabow.com/?p=1472</guid>
		<description><![CDATA[Zend_Translate 是Zend框架用來支援多語言開發的一個物件。 PS：以下試作是用Wacow Framework系統 ( 你可以在這裡找到他 ) 1. path\app\etc\config.ini，加上 locale = &#34;zh_TW&#34; localeMode = true 2. path\app\etc\defination.php,加上，位置隨意，但是要注意WF_LOCALE_PATH必須在WF_APP_PATH定義之後 define&#40;'WF_LOCALE_TYPE', 'ini'&#41;; define&#40;'WF_LOCALE_PATH', WF_APP_PATH . '/locale'&#41;; 3. 接著是path\app\lib\App\Bootstrap.php，找到run函式，在最後加上 $configIni = new Zend_Config_Ini&#40;self::$_setting&#91;'path'&#93;, null, null&#41;; $locale = $configIni-&#62;application-&#62;locale; Zend_Registry::set&#40;'Zend_Translate', new Zend_Translate&#40;WF_LOCALE_TYPE, WF_LOCALE_PATH.'/'.$locale.'.'.WF_LOCALE_TYPE, 'zh_TW'&#41;&#41;; 4. path\app\路徑下建立，資料夾"locale" 5. path\app\locale\路徑下，建立檔案"zh_TW.ini"，內容填入"hello_world = 您好" 6. 最後是path\app\lib\Wacow\View\Html\Smarty.php，將_run函式前段改寫 $this-&#62;strictVars&#40;true&#41;; &#160; $configIni = new Zend_Config_Ini&#40;WF_CONFIG_PATH, null, null&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>Zend_Translate 是Zend框架用來支援多語言開發的一個物件。<br />
<span id="more-1472"></span></p>
<p>PS：以下試作是用Wacow Framework系統   ( 你可以在<a href="http://code.google.com/p/wacowframework/">這裡</a>找到他 )</p>
<p>1. path\app\etc\config.ini，加上</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">locale        <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;zh_TW&quot;</span>
localeMode    <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span></pre></div></div>

<p>2. path\app\etc\defination.php,加上，位置隨意，但是要注意WF_LOCALE_PATH必須在WF_APP_PATH定義之後</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WF_LOCALE_TYPE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ini'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WF_LOCALE_PATH'</span><span style="color: #339933;">,</span> WF_APP_PATH  <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/locale'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>3. 接著是path\app\lib\App\Bootstrap.php，找到run函式，在最後加上</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$configIni</span>  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_setting</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$locale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$configIni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">locale</span><span style="color: #339933;">;</span>
Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Zend_Translate'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Translate<span style="color: #009900;">&#40;</span>WF_LOCALE_TYPE<span style="color: #339933;">,</span> WF_LOCALE_PATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$locale</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">.</span>WF_LOCALE_TYPE<span style="color: #339933;">,</span> <span style="color: #0000ff;">'zh_TW'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>4. path\app\路徑下建立，資料夾"locale"</p>
<p>5. path\app\locale\路徑下，建立檔案"zh_TW.ini"，內容填入"hello_world = 您好"</p>
<p>6. 最後是path\app\lib\Wacow\View\Html\Smarty.php，將_run函式前段改寫</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">strictVars</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$configIni</span>  <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Config_Ini<span style="color: #009900;">&#40;</span>WF_CONFIG_PATH<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$localeMode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$configIni</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">localeMode</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// assign variables to the template engine</span>
<span style="color: #000088;">$vars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_object_vars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$vars</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span> <span style="color: #339933;">!=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// for locale</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$localeMode</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_smarty<span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>7. 使用方式：樣板插入參數方式和之前一樣，$this-&gt;view-&gt;hello_world = 'hello_world'; 但此時樣板輸入的hello_world會自動轉為"您好"，不需要轉換語系時，只要將config.ini中localeMode設為false即可，若要加入其他語言，只要依樣畫葫蘆，設定local = '語系名稱'，並在path\app\locale\加入'語系.ini'，相當簡易。</p>
<p>- 以上報告完畢 -</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.wabow.com/archives/1472/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

