您如何处理带有标记的文本翻译?

2023-08-01前端开发问题
3

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

问题描述

我正在为我们的网络应用开发多语言支持.我们在 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. 词序因语言而异.如果将上面的句子分割成片段,它可能适用于英语和法语,但在中文或日语中,当你连接时,单词顺序会不正确.因此,最好的做法是外化整个句子,而不是句子片段.

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

The End

相关推荐

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125

“数组中的每个孩子都应该有一个唯一的 key prop"仅在第一次呈现页面时
quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)...
2024-04-20 前端开发问题
5

如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?
How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社...
2024-04-20 前端开发问题
6

缩放背景图像以适合 ie8 窗口
Scale background image to fit ie8 window(缩放背景图像以适合 ie8 窗口)...
2024-04-19 前端开发问题
11