Django i18n和gettext的词共轭 [英] Word conjugation with Django i18n and gettext

查看:59
本文介绍了Django i18n和gettext的词共轭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我在Django项目的模板文件中包含以下代码:

Currently, I have the following code in a template file in my Django project:

{% blocktrans with type=content.get_type %}Edit this {{ type }}{% endblocktrans %}

{{ type }}是一个字符串,可以具有诸如"lecture""exercise"的值.这是.po文件中的输出:

The {{ type }} is a string that can have values such as "lecture" and "exercise". Here is the output in the .po file:

msgid "Edit this %(type)s"
msgstr ""

这对于英语(例如英语)中不能与对象共轭的语言非常有效.对于像芬兰语这样的语言,这会引起问题.

This works fine for languages such as English that don't conjugate objects. For languages that do, such as Finnish, this will cause problems.

在芬兰语中,名词演讲"翻译为"luento",在此特定情况下所需要的表示形式与"luento a "共轭.名词运动"翻译为tehtävä"或"harjoitus",其代表形式为tehtävää"和"harjoitus ta ".

In Finnish, the noun "lecture" translates to "luento", and the partitive form required in this specific case is conjugated "luentoa". The noun "exercise" translates to "tehtävä" or "harjoitus", whose partitive forms are "tehtävää" and "harjoitusta".

在这种情况下,是否有办法为单词添加特定的翻译?还是有某种基于条件的方式来填充msgstr?

Is there a way to, for example, add specific translations for the words in cases such as this? Or maybe have some kind of condition based way to fill msgstr?

以下内容显然不起作用,因为单词的共轭形式以不同的字符结尾:

Obviously the following doesn't work, because the conjugated forms of the words end in different characters:

msgstr "Muokkaa tätä %(type)sa"

(这将正确导致"luentoa",但错误地导致tehtäväa".)

(Which would correctly result in "luentoa", but incorrectly result in "tehtäväa".)

推荐答案

GNU的

GNU's gettext manual advises that people translate whole sentences as much as possible:

整个句子也很重要,因为在许多语言中,句子中某个单词的偏斜度取决于句子另一部分的性别或数量(单/复数).单词之间的相互依存性通常比英语中更高.结果是,要求翻译人员翻译两个半个句子,然后通过哑字符串连接将这两个半个句子组合起来,这对许多语言都行不通,即使对英语来说也是如此.因此,翻译人员需要处理整个句子.

Entire sentences are also important because in many languages, the declination of some word in a sentence depends on the gender or the number (singular/plural) of another part of the sentence. There are usually more interdependencies between words than in English. The consequence is that asking a translator to translate two half-sentences and then combining these two half-sentences through dumb string concatenation will not work, for many languages, even though it would work for English. That’s why translators need to handle entire sentences.

让我们假设您使用的结构"Edit this %(type)s"适用于芬兰语.例如,一旦您想支持法语,它就不会起作用.对于您提到的类型,您必须用法语使用以下句子:

Let's suppose you get the structure "Edit this %(type)s" to work for Finnish. As soon as you want to support French, for instance, it won't work. With the types you mentioned you'd have to have these sentences in French:

Éditer cette leçon
Éditer cet exercice

(第一句话可能必须翻译为Éditer ce cours.leçon"或"cours"中哪一个最好取决于英语中"lecture"在您使用上下文中的确切指称.)您会发现问题所在,具体取决于您使用的是哪个单词,在type前面可能需要"cet","cette"或"ce".

(The first sentence might have to be translated as Éditer ce cours. Which of "leçon" or "cours" is best depends on what "lecture" in English refers to precisely in the context in which you are using it.) You see the problem, depending on what word you use, you may need "cet", "cette", or "ce" in front of your type.

这篇关于Django i18n和gettext的词共轭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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