du7133 2012-05-20 11:26
浏览 27
已采纳

将echo调用转换为gettext调用

I'm in charge of a project that needs to be *i18n*ed. The only problem is that the original developer didn't think of this when writing the code so all the strings are just "hard-coded".

It's quite a mess, I've been looking the code and found all these cases:

  • Strings in echo calls:

    echo "I'm a string";

  • Strings in echo calls and mixed with HTML:

    echo "<div><span href=''>I'm a string</span></div>";

  • Strings in non-PHP (plain HTML) portions of the code.

  • Strings in echo calls with PHP variables inside:

    echo "There are $number items in this list";

My question is: do you know of any program that could automate a bit the tedious work of converting all these into gettext _() calls?

The project is quite big and I'm thinking of writing it myself (I'm sure I'll face this problem again in the future) but I don't want to reinvent the wheel.

Thanks a lot!

  • 写回答

1条回答 默认 最新

  • dpnv33177 2012-05-20 11:46
    关注

    You could use regular expressions and sed to replace at least some of those echo messages. But keep in mind that you can break more than you wanted to fix when you use automatic text replacement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?