Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Word conjugation with Django i18n and gettext

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

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

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.

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".

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"

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

like image 396
miikkas Avatar asked Dec 25 '22 23:12

miikkas


1 Answers

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.

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

(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.

like image 141
Louis Avatar answered Jan 06 '23 14:01

Louis