dongta5621 2009-12-04 17:08
浏览 92
已采纳

Gettext:用HTML翻译字符串?

My current implementation, which is array based stores keys and values in a dictionary, example:

$arr = array(
    'message' => 'Paste a <a href="http://flickr.com/">flickr</a> URL below.',
);

I realize that it was probably a bad idea storing html inside of a string such as this, but if I'm using gettext then in my .mo/.po files how should I handle storing a similar string? Should I just store words, such as 'Paste a' and 'URL below' and 'flickr' separately?

  • 写回答

2条回答 默认 最新

  • dsdtszi0520538 2009-12-04 17:24
    关注

    You should store something like

    "Paste a %1 URL below"
    

    and replace all 'vars' using something simple like str_replace('%1', $link, $message);

    $link can also be translatable

    "<a href="http://flickr.com/">%1</a>"
    

    although that might be overkill (does flickr translate between languages?)

    rationale behind this is that different languages have different grammatical structures and the ordering of the words wont always be the same.

    Update:

    as @alex and @chelmertz mention in the comments, try using the sprintf function, which is built for this very thing.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记