Important Dates

Latest Posts

Topic: Preparing for translation

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2513
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-10-31, 18:20

Another question:

There is a string variable subj which is either "Ship" or "Hero". Maybe those subjects have different sex in different languages or need other changes…

E.g. in English if the variable subj would be either "Ship" or "Anchor" the text has to be changed because it could be "A Ship" or "AN Anchor" depending on the content of the variable. How to handle this?

The current code:

         if opponent then
            -- TRANSLATORS: %1$s is either "Hero" or "Ship"
            title = _("%1$s created!"):bformat(subj)
            msg = msg .. p(_("%1% has created a %2$s!"):bformat(opponent.name, subj))
         else
            title = _("You have a new %1$s!"):bformat(subj)
         end

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 2027
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2024-10-31, 19:30

If there's a limited number of possibilities, try to hardcode all possible variants. Your example is problematic as it is as it mixes uppercase and lowercase. (German is a highly unusual language in that it capitalizes regular nouns; English and 99% of other languages don't do that. In your first string, subj must be uppercase, and in the second and third string, it must be lowercase. This is language-specific.)

So instead of having the three translatable strings in your code snippet above, you would omit subj (and replace it with a boolean or enum integer) and do something like this, with six translatable strings:

         if opponent then
            title = is_hero and _("Hero created!") or _("Ship created!")
            msg = msg .. p((is_hero and _("%1$s has created a hero!") or _("%1$s has created a ship!")):bformat(opponent.name))
         else
            title = is_hero and _("You have a new hero!") or _("You have a new ship!")
         end

Stylistic nitpicking: %n% should only be used if the type of the format argument is dynamic; if you already know it will be a string, prefer %s.

Edited: 2024-10-31, 19:34

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2513
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2024-10-31, 19:57

Wow, this translation preparation are a world of it's own.

Many thanks!

Stylistic nitpicking: %n% should only be used if the type of the format argument is dynamic; if you already know it will be a string, prefer %s.

I will try to add some examples and explanations to bformat. For new add-on authors it's cumbersome get his add-on to work and additionally to find the correct syntax and placeholder for formatting the translations.


Top Quote