国际化django模板中的多个可多元变量

时间:2022-01-04 19:38:20

I am internationalizing (i18n) our django project, i.e. adding {% blocktrans %} to our templates. I know about using count and {% plural %} to have different strings for varaibles. However I have a string that has two variables that each need to be pluralized, i.e. 4 possible options.

我正在国际化(i18n)我们的django项目,即向我们的模板添加{% blocktrans %}。我知道使用count和{%复数%}来为varaibles设置不同的字符串。但是,我有一个字符串,它有两个变量,每个变量都需要被复数化,即4个可能的选项。

For example, my string is "You have {{ num_unread }} unread message{{ num_unread|pluralize }} out of {{ total }} total message{{ total|pluralize }}"

例如,我的字符串是“您有{{num_unread} {{{{num_unread} {{{{{{{num_unread|pluralize} {{{total}消息{{{total|pluralize}}}”

How would I convert that to blocktrans tags?

如何将它转换为blocktrans标签?

1 个解决方案

#1


2  

After doing some more research and reading, specifically about gettext, I don't think this is possible. gettext documentation only allows one variable to control the pluralization. There are probably problems with having 2 variable pluralization, since in arabic, you'd have to have 36 different strings to translate.

在做了更多的研究和阅读之后,特别是关于gettext,我认为这是不可能的。gettext文档只允许一个变量控制复数。可能有两个变量复数的问题,因为在阿拉伯语中,你需要有36个不同的字符串来翻译。

In the end I just worked around my original problem, and split it into two strings.

最后我解决了我最初的问题,把它分成两根弦。

#1


2  

After doing some more research and reading, specifically about gettext, I don't think this is possible. gettext documentation only allows one variable to control the pluralization. There are probably problems with having 2 variable pluralization, since in arabic, you'd have to have 36 different strings to translate.

在做了更多的研究和阅读之后,特别是关于gettext,我认为这是不可能的。gettext文档只允许一个变量控制复数。可能有两个变量复数的问题,因为在阿拉伯语中,你需要有36个不同的字符串来翻译。

In the end I just worked around my original problem, and split it into two strings.

最后我解决了我最初的问题,把它分成两根弦。