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.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?