Translation into languages ​​with irregular rules

To create an extensible PHP content management system , language translations are crucial. I studied software approaches to the translation system, and I thought that Qt Linguist is a good example.

This is an example usage from the Qt documentation:

int n = messages.count(); showMessage(tr("%n message(s) saved", "", n)); 

Qt uses well-known language rules to determine if " message " " s " is in English.

When I brought this example to my development team, they discovered a problem that jeopardizes the extensibility of Qt tr() function modeling.

This is a similar example, except that now something is seriously wrong.

 int n = deadBacteria.count(); showMessage(tr("%n bacterium(s) killed", "", n)); 

The set of " bacterium " is equal to " bacteria ". Incorrectly add " s ".

I do not have much experience with Qt Linguist, but I have not seen how it handles irregular conjugations and forms.

A more complex phrase might be "%n cactus(s) have grown." . The plural must be " cactii " and " have " must be conjugated with " has " if there is one cactus.

You might think that a logical correction is to avoid these irregular words because they are not used in programming. Well, this is not useful in two ways:

  • Perhaps there is a language that changes nouns irregularly, although the source string works in English, for example, "%n message(s) saved" . In MyImaginaryLanguage, the correct way to form the translated string could be "1Message saved", "M2essage saved", "Me3ssage saved" for %n values 1 , 2 and 3 , respectively, and it doesn Look like Qt Linguist has rules for this.
  • To make CMS extensible as I need to be mine, all types of web applications need to be considered. Someone can create a role-playing game that requires proposals to be built as "5 cacti." Or maybe the security software wants to say: "ClamAV detected 2 viruses." unlike "ClamAV detected 2 viruses."

After searching the Internet to find out if other Qt developers have a solution to this problem, and without finding any, I came to Stack Overflow.

I want to know:

  • What extensible and efficient programming method should be used to translate strings with possible irregular rules?
  • What do Qt programmers and translators do if they face this unevenness problem?
+6
source share
3 answers

You misunderstood how pluralization works in Qt: it is not an automatic translation.

Basically, you have a default string, for example. "% of cacti have grown." which is literal in your code. You can put everything you like in it, for example. "dingbat wibble foo% n bar".

Then you can define the translation languages ​​(including one for the same language in which you entered the source string).

A linguist is programmed with different rules, how languages ​​handle the amount of something. In English, it is simply singular or plural; but if the language has a specific form for zero or something else, then it is represented in linguistics. Then it allows you to insert any correct sentence in the target language of the translation and process the placement of %n where you decide that it should be in the translated form.

So, whoever makes the translation in a linguist, a source has been provided and must fill out, for example, the singular and plural.

Source text: %n cactus(s) have grown.

English translation (singular): %n cactus has grown.

English translation (plural): %n cacti have grown.

If the application cannot find the installed translation, it returns to the original literal. Also, the source literal is what the person translating sees so, must conclude what you had in mind. Therefore, "dingbat wibble foo% n bar" might not be a good idea when describing how many cacti have grown.

Further reading:

+6
source

Your best bet is to use the GNU gettext i18n framework. It is beautifully integrated into PHP and gives you the tools to precisely define all the fancy plural form grammar rules.

+3
source

Using Qt Linguist , you can process various grammar numbers based on the target language. Therefore, every time a %n found in the string tr , the translator will be asked to provide all the necessary translations for the target language. Read more in this article:

http://doc.qt.nokia.com/qq/qq19-plurals.html

+1
source

Source: https://habr.com/ru/post/911156/


All Articles