[Development] [Interest] Direct-lookup translation, even for English (was Re: get english translation)

André Somers andre at familiesomers.nl
Fri Sep 5 09:16:48 CEST 2014


Thiago Macieira schreef op 4-9-2014 20:59:
> On Thursday 04 September 2014 20:31:49 Andre Somers wrote:
>> That sounds rather short-sighted to me.
>> It means that an inconsistency is introduced for no good reason at all.
>> If you want to have something that works for English only, it would be
>> rather trivial to write a free function like this:
>>
>> QString singularOrPlural(QString singular, QString plural, int value) {
>>       if (value == 0 || qAbs(value) > 1) {
>>           return plural;
>>       }
>>       return singular;
>> }
>>
>> There you go, there's your special tr version.
> This did not extract the string for translation. It needs to be something that
> does extract for translation and does translate to another language if a
> translator was loaded.
I don't see how it properly could. Both strings would be specialized 
anyway for the singular and plural case. The singular version probably 
would not even have a placemarker for the number in it. How would that 
work in the translation? You could still use a translatable string for 
both alternatives, but I think that's completely missing the point. You 
either do localization, or you don't. This really sounds like a weird 
in-between, non-solution to me.
>
>>>> ..or alternatively we need to be clarify our documentation to explicitly
>>>> mention that this plural-form-translation feature requires a translation
>>>> to
>>>> be installed, even in English.
>>> Which is what I don't want. This basically requires everyone to always
>>> load
>>> the Qt translation, even if their apps aren't l10n'ed.
>> So? If they forget, they'll end up with "1 file(s) found" instead of "1
>> file found" or "2 files found". Big deal.
> So long as we actually write using the (s) plural. Which we sometimes don't:
>
> In designer:
> buddyeditor.cpp:    undoStack()->beginMacro(tr("Remove %n buddies", 0,
> selectedConnections.size()));
> buddyeditor.cpp:    undoStack()->beginMacro(tr("Add %n buddies", 0, count));
> qdesigner_propertycommand.cpp:
> setText(QCoreApplication::translate("Command", "Changed '%1' of %n objects",
> "", count).arg(propertyName()));
>
> Source code bugs? Probably.
Ok, so they might need to get fixed. Or not, as fixing these strings 
will break all existing real translations.

>> A quick search for %n in the Qt .ts files would reveal that. I don't
>> have them here, or I would take a peek.
>> But even so: Qt could pre-load the Qt .qm file by default from an
>> internal resource, and I guess that makes sense. There is no need for a
>> special tr() version to do that.
> Right, those are the two alternatives: preload a .qm or not require a .qm.
>
Note that these are not equal alternatives. Preloading a .qm will make 
Qt _itself_ use proper singular and plural forms. Using your special 
tr() overload would make not using a .qm file an option for users of Qt 
as well.

IMO, pre-loading the qt_en_US.qm translation file makes sense, a special 
overload does not.

André




More information about the Development mailing list