Reputation: 229481
Say I want to ask the user to confirm an action. The action consists of three parts. Each of the three parts can be formatted in one of two ways. In a human-language-specific way, I might do something like this (pseudocode):
res = ""
res = "Do you want to %1 at %2, %3 at time %4%5?" % (
"foo" if fooing else "bar", foobar_data,
"expiring" if expiring else "starting", the_time,
", without foobing" if no_foob else (", foobing at %1" % when_foob))
Even if I wrap all translatable strings with the translation function (e.g. tr("Do you want to %1 at %2 ...")
), this would probably only work for english since other languages are unlikely to have the same syntactic structure.
But if I write out the whole sentences then I get a combinatorial explosion:
if fooing and expiring and no_foob:
res = "Do you want to foo at %1, expiring at time %2, without foobing?"
elif fooing and expiring and not no_foob:
res = "Do you want to foo at %1, expiring at time %2, foobing at %3?"
elif fooing and not expiring and no_foob:
res = "Do you want to foo at %1, starting at time %2, without foobing?"
# etc ...
res = res % (foobar_data, the_time, when_foob) # account for sometimes not having when_foob somehow
What's the standard way to deal with this situation?
Upvotes: 0
Views: 54
Reputation: 522402
Even if I wrap all translatable strings with the translation function, this would probably only work for english since other languages are unlikely to have the same syntactic structure.
Yes and no. You can obviously switch the sentence and parameters around to fit the target language:
Wollen Sie am %2 %1, %3 %4%5?
The tricky part obviously is to get the declinations and such right; while the words themselves might not change at all in English when swapping them, they may have to be altered heavily in other languages.
For this it's important to translate all the necessary variations, and be able to annotate them with context in your translation system:
tr('foo', context='infinitive') if fooing else tr('bar', context='infinitive')
tr('expiring', context='verb before date') if expiring else tr('starting', context='verb before date')
The PO file format for instance has this notion built in:
msgctxt "verb before date"
msgid "expiring"
msgstr "wird auslaufen am"
It does take some linguistic knowledge to break up sentences correctly, be able to classify and annotate each term correctly so it can be correctly translated into all languages as necessary, and it takes a lot of Q&A to ensure it's being done correctly. You want to find the right balance between small enough snippets that translations can be reused, and breaking it down enough so it can be translated correctly.
You can also use message ids, if that becomes too complex:
res = "question.confirmActivty" % (..)
msgid "question.confirmActivty"
msgstr "Do you want to %1 at %2, %3 at time %4%5?"
Upvotes: 0
Reputation: 12215
I think it's best to avoid such complex sentences altogether. Instead, provide one simple sentence and add further details in a table-like way (tables are easier to translate).
This has the added bonus that you can hide the details per default (progressive disclosure) and keep the main message short. This increases the chance that your users read the confirmation dialog at all.
Mock-up:
Do you really want to <Foo/Bar>?
[ Cancel ] [ <Foo/Bar> ] [ Details... ]
---------------------------------------------
Time: <Expring at %1 / Starting at %1>
Foobing: <Yes/No>
Upvotes: 1