3

I wrote a website, with several pages, in PHP and now need it translated to a different language.

I've been searching ages for how I can just automatically extract all the strings and HTML text in my php source code, manually translate each, and then insert them back in.

I don't want multi-language support, and I've checked translation solutions such as Translate2, but they all seem to require you to manually go in and replace code.

I'd modify the code myself, but I don't know the language and this needs to be passed on to a translator.

Surely, there's a ready made solution for this?

If not, can anyone recommend some solid regex for string or HTML text searching?

Thank you

TheSuperbian
  • 33
  • 1
  • 3

1 Answers1

3

Declare strings like:

$someString = _('Some text that needs to be translated');

PHP Gettext

Extract them to a .po file.

Send them off to a translator, who will translate the strings with Poedit.

Once you get your .po back, put it in an appropriately named directory, such as /your/file/path/zh_CN/LC_MESSAGES/messages.po

Change the locale in PHP:

 setlocale(LC_ALL,  'zh_CN' . '.UTF8') ;
 bindtextdomain('messages', "/your/file/path/");
 textdomain('messages') ;
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
  • Thank you very much for your helpful reply. I was hoping there'd be something as nice as "pop in unmodified source code and out pops translation file". From your answer, I found this: http://stackoverflow.com/questions/1465752/php-source-code-to-po-file-generator I'm pretty sure it's possible, just too difficult. Oh well, I'll go with modifying my hundreds of lines of code to work with gettext then. Thanks again – TheSuperbian Aug 17 '10 at 10:41