1

我的多語種網站已成功使用Zend翻譯的「數組」方法。如何將Zend本地化/翻譯數組轉換爲gettext?

我想從該方法轉換到「gettext」方法,因爲我已經讀過gettext是優越的。

我試過使用http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/php2po.html,但無法使其正常工作。

我認爲這並不意味着要處理Zend數組作爲輸入。

我的Zend的文件(工作)看起來是這樣的:

<?php 

return array( 
    'choose your favorite stores' => 'Choose your %1$sfavorite stores%2$s', 
    'P.S. If you ever have question' => 'P.S. If you ever have questions, %1$semail us%2$s any time.', 
    'You can also find quick answer' => 'You can also find quick answers on our %1$sHelp page%2$s.', 
    'Earn X cash' => '%1$sEarn 1-30%% cash back%2$s, get money-saving coupons, and find the best price on every purchase at %3$s2,500+ stores%4$s.' 
); 

(但它更長的時間,我有多種語言,各自在自己的PHP文件)。

+0

我也擔心有序的變量,特別是在閱讀http://stackoverflow.com/questions/1888487後。因爲我需要能夠做到以下幾點。請注意英文和中文變數的順序如何: ''賺取X現金'=>'%1 $ s賺取1-30 %%現金返還%2 $ s,獲得省錢優惠券,並找到最好的每次購物的價格爲%3 $ s2,500 +商店%4 $ s.'' 和 ''賺取X個現金'=>'您可以從%3 $ s2500個商家%4 $ s中,找到省錢的優惠券,輕鬆比價,更可獲取%1 $ s1-30 %%的返利%2 $ s.'' – Ryan

回答

0

隨着片斷你已經爲我提供了轉換作品。

$ php2po en.php en.po -t en.php 
processing 1 files... 
[###########################################] 100% 

$ cat en.po 
#. extracted from en.php, en.php 
msgid "" 
msgstr "" 
"Project-Id-Version: PACKAGE VERSION\n" 
"Report-Msgid-Bugs-To: \n" 
"POT-Creation-Date: 2012-12-19 10:08+0200\n" 
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 
"Last-Translator: FULL NAME <[email protected]>\n" 
"Language-Team: LANGUAGE <[email protected]>\n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=UTF-8\n" 
"Content-Transfer-Encoding: 8bit\n" 
"X-Generator: Translate Toolkit 1.9.1-pre\n" 

#: return+array%28-%3E%27choose+your+favorite+stores%27 
msgid "Choose your %1$sfavorite stores%2$s" 
msgstr "Choose your %1$sfavorite stores%2$s" 

#: return+array%28-%3E%27P.S.+If+you+ever+have+question%27 
msgid "P.S. If you ever have questions, %1$semail us%2$s any time." 
msgstr "P.S. If you ever have questions, %1$semail us%2$s any time." 

#: return+array%28-%3E%27You+can+also+find+quick+answer%27 
msgid "You can also find quick answers on our %1$sHelp page%2$s." 
msgstr "You can also find quick answers on our %1$sHelp page%2$s." 

我使用的翻譯工具包版本從git master,也許你應該嘗試。

+0

感謝您指點我,但不幸的是,它跳過了數組中的第4個鍵/值對('賺取X現金')。 – Ryan

+1

此外,它無法使用數組鍵作爲msgid。 – Ryan

+0

如果在將包含的數組的最後一個元素中添加逗號。數組的關鍵字不會被用作「msgid」,你爲什麼要這麼做?您正在從單語言格式轉換爲雙語格式。 PO文件將始終在「msgid」中包含源文本(本例中爲英文);這就是你期望的本地化者本地化。 – julen