在 gettext 中使用链接处理文本的好方法?
我目前正在使用 PHP 进行 gettext 国际化。我想知道这个例子有没有什么好的方法:
By using this website, you accept the <a href="<?php print($dir); ?>/tos/">Terms of Use</a>.
对于en_US,这句话会遵循这样的格式。然而,在另一种语言中,“使用条款”链接可能位于句子的开头。有没有一种优雅的方法来做到这一点?感谢您抽出时间。
I'm currently doing internationalization with gettext using PHP. I was wondering if there were any good methods for this example:
By using this website, you accept the <a href="<?php print($dir); ?>/tos/">Terms of Use</a>.
For en_US, this sentence would follow such a format. However, in another language, the link "Terms of Use" could be at the beginning of the sentence. Is there an elegant way to do this? Thanks for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于简单的国际化,我将简单地为每种语言创建一个数组,包含适当的文件,然后访问该数组,而不是执行您正在执行的操作。
en.php:
index.php:
dirname()
调用至关重要;否则用户可以未经审查地访问文件系统上的任何 php 文件。For simple internationalization, I'll simply create an array per language, include the proper file, and access that array rather than do what you are doing.
en.php:
index.php:
The
dirname()
call is critical; otherwise users get unvetted access to any php file on your filesystem.我就是这样做的。要翻译的短语是
然后我会在短语本地化后替换链接,例如
当然您可以替换
和
任何对您和您的翻译人员有意义的内容。想想看,因为你必须转义你的输出以防止翻译者弄乱你的 HTML(有意或无意),我可能会选择类似的东西
Here's how I'd do it. The phrase to be translated would be
Then I'd replace the link after the phrase is localised, e.g.
Of course you can replace
<a>
and</a>
with whatever makes sense to you and your translators. Come to think of it, since you have to escape your output to prevent translators from messing up with your HTML (intentionally or not) I'd probably go with something like