可翻译的内容和 HTML 标签

发布于 2024-12-17 06:17:28 字数 577 浏览 1 评论 0原文

我使用 Twig,我想让以下内容可翻译:

{% trans %}
You have actually <span class='messageNumber'>{{messageNumber}} message(s)</span> in your mailbox. 
{% endtrans %}

但是当 POEdit 解析此可翻译内容并将其发送给翻译人员时,他们将看到 标签和属性。我可以做什么来避免这种情况?

我想过这样做:

{% messageNumberFormatted = "<span class='messageNumber'>"~messageNumber~"message(s)</span>" %}

{% trans %}
You have actually {{messageNumberFormatted}} in your mailbox.
{% endtrans %}

但这对译者来说是不是有点重,甚至是不好的做法?那样的话,他们连“消息”两个字都看不到。

I use Twig and I want to make the following content translatable :

{% trans %}
You have actually <span class='messageNumber'>{{messageNumber}} message(s)</span> in your mailbox. 
{% endtrans %}

But when this translatable content will be parsed by POEdit and sent to translators, they will see the <span> tags and attributes. What can I do to avoid this ?

I thought about doing this way :

{% messageNumberFormatted = "<span class='messageNumber'>"~messageNumber~"message(s)</span>" %}

{% trans %}
You have actually {{messageNumberFormatted}} in your mailbox.
{% endtrans %}

But isn't it a bit heavy or even bad practice for the translators ? In that case, they can't even see the word "message".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅倚清风 2024-12-24 06:17:28

首先,您应该将 transchoice 与显式区间复数结合使用,像这样:

{% transchoice message_count %}
   {0}You have {{no messages}} yet|{1}You have {{one message}}|]1,+Inf]You have {{%count% messages}}.
{% endtranschoice %}

那么也许你可以使用 replace 来替换{{ 带有开始标记,}} 带有结束标记。我不知道你是否可以像这样直接链接

{% transchoice message_count | replace('...') %}

或者是否必须使用 设置首先。

First, you should use transchoice with explicit interval pluralization, like this :

{% transchoice message_count %}
   {0}You have {{no messages}} yet|{1}You have {{one message}}|]1,+Inf]You have {{%count% messages}}.
{% endtranschoice %}

Then maybe you could use replace to replace {{ with the opening tag, and }} with the closing tag. I don't know whether you can directly chain like this

{% transchoice message_count | replace('...') %}

Or if you must store in a variable by using set first.

原野 2024-12-24 06:17:28

您可以使用 trans twig filer 和代表您的句子的键。

{{ you.have.actually|trans }} <span class='messageNumber'> {{ messageNumber message|trans }} </span> {{ in.your.mailbox|trans }}

You can use the trans twig filer with keys representing your sentences.

{{ you.have.actually|trans }} <span class='messageNumber'> {{ messageNumber message|trans }} </span> {{ in.your.mailbox|trans }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文