1

My multi-lingual site already successfully uses the "array" method of Zend translations.

I want to convert from that method to the "gettext" method because I've read that gettext is superior.

I've tried using http://docs.translatehouse.org/projects/translate-toolkit/en/latest/commands/php2po.html but can't get it to work.

I think it's not meant to handle Zend arrays as the input.

My Zend file (which works) looks like this:

<?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.'
);

(But it's much longer, and I have multiple languages, each in their own PHP file.)

Ryan
  • 22,332
  • 31
  • 176
  • 357
  • And I'm worried about the ordered variables, too, especially after reading http://stackoverflow.com/questions/1888487. Because I need to be able to do the following. Notice how the order of the variables is different in English and Chinese: `'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.'` and `'Earn X cash' => '您可从%3$s2500个商家%4$s中,找到省钱的优惠券,轻松比价,更可获取%1$s1-30%%的返利%2$s。'` – Ryan Dec 17 '12 at 21:59

1 Answers1

0

With the snippet you have given the conversion works for me.

$ 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@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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."

I'm using a Translate Toolkit version from git master, maybe you should try that.

julen
  • 4,959
  • 1
  • 23
  • 31
  • Thanks for pointing me to that, but unfortunately it skips the 4th key/value pair in the array ('Earn X cash'). – Ryan Dec 19 '12 at 14:47
  • 1
    Also, it fails to use the array key as the msgid. – Ryan Dec 19 '12 at 20:09
  • If you add a comma in the last element of the array that will be included too. The key of the array won't be used as a `msgid`, why would you want that? You are converting from a monolingual format to a bilingual format. PO files will always have the source text (English in this case) in the `msgid`; that's what you expect localizers to localize. – julen Dec 19 '12 at 21:25
  • There are many cases where you'd want the "key" (msgid) to be different from the source text (English). For example, in the HTML view, I might want to say [yyyy] where the destination and label of that anchor tag depend on the locale of the user. E.g. it might be a link to a social network, and in US it would be Facebook but in China it would be Weibo. So the MsgIds might be something like socialSiteUrl and socialSiteLabel. I am trying to get poeditor.com to work. That might be my approach going forward. – Ryan Dec 20 '12 at 18:49
  • I ignore if the Zend framework forces you a specific format... but what I don't understand is the reason why you want to convert this to PO if you are not going to use the result as a bilingual format. – julen Dec 20 '12 at 18:59