您如何处理带有标记的文本翻译? [英] How do you handle translation of text with markup?

查看:41
本文介绍了您如何处理带有标记的文本翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我们的网络应用开发多语言支持.我们在 gettext 库.一切都出乎意料地简单,除了如何处理包含重要 HTML 标记的句子的问题.这是一个简单的例子:

I'm developing multi-language support for our web app. We're using Django's helpers around the gettext library. Everything has been surprisingly easy, except for the question of how to handle sentences that include significant HTML markup. Here's a simple example:

Please <a href="/login/">log in</a> to continue.

以下是我能想到的方法:

Here are the approaches I can think of:

  1. 更改链接以包含整个句子.不管在这种情况下改变是否是一个好主意,这个解决方案的问题在于,当两者在理想情况下独立时,UI 变得依赖于 i18n 的需求.

  1. Change the link to include the whole sentence. Regardless of whether the change is a good idea in this case, the problem with this solution is that UI becomes dependent on the needs of i18n when the two are ideally independent.

将上面的整个字符串标记为翻译(包括格式).然后,翻译字符串也将直接包含 HTML.这样做的问题是更改 HTML 格式需要更改所有翻译.

Mark the whole string above for translation (formatting included). The translation strings would then also include the HTML directly. The problem with this is that changing the HTML formatting requires changing all the translation.

将多个翻译紧密耦合,然后使用字符串插值将它们组合起来.例如,短语请 %s 继续"和登录"可以分别标记为翻译,然后合并.登录"被本地化,然后包装在 HREF 中,然后插入到翻译的短语中,这使 %s 保持在翻译中以标记链接应该去哪里.这种方法使代码复杂化并破坏了翻译字符串的独立性.

Tightly couple multiple translations, then use string interpolation to combine them. For the example, the phrase "Please %s to continue" and "log in" could be marked separately for translation, then combined. The "log in" is localized, then wrapped in the HREF, then inserted into the translated phrase, which keeps the %s in translation to mark where the link should go. This approach complicates the code and breaks the independence of translation strings.

还有其他选择吗?其他人是如何解决这个问题的?

Are there any other options? How have others solved this problem?

推荐答案

解决方案 2 就是您想要的.将整个句子发送给他们,并嵌入 HTML 标记.

Solution 2 is what you want. Send them the whole sentence, with the HTML markup embedded.

原因:

  1. 主要的翻译工具 Trados 可以防止翻译人员无意中损坏标记.
  2. Trados 还可以自动翻译它以前见过的文本,即使标签的内容发生了变化(但标签的数量和它们在句子中的位置是一样的).最起码,译者会给你一个很好的折扣.
  3. 样式是特定于语言环境的.在某些情况下,粗体在中文或日文中是不合适的,例如,斜体在东亚语言中不太常用.译者应该有保留或删除样式的自由.
  4. 词序因语言而异.如果将上面的句子分割成片段,它可能适用于英语和法语,但在中文或日语中,当你连接时,单词顺序会不正确.因此,最好的做法是外化整个句子,而不是句子片段.

这篇关于您如何处理带有标记的文本翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆