TGnuGettextInstance.ngettext broken if SearchAllDomains is set to True
Brought to you by:
dybdahl
When SearchAllDomains was introduced the patch code suggested to change TGnuGettextInstance.ngettext like this:
domain := curmsgdomain; domainIndex := -1; repeat Result := dngettext(domain, singular, plural, Number); Inc(domainIndex); if domainIndex < domainlist.Count then domain := domainlist[domainIndex]; until not SearchAllDomains or ((Result <> singular) and (Result <> plural)) or (domainIndex >= domainlist.Count);
Upon inclusion, it has been rewritten to use a while loop like this:
Result := dngettext(curmsgdomain, singular, plural, Number); if SearchAllDomains then begin domainIndex := 0; while (Result <> singular) and (Result <> plural) and (domainIndex < domainlist.count) do begin domain := domainlist[domainIndex]; Result := dngettext(domain, singular, plural, Number); Inc(domainIndex); end; end;
In doing so, the condition for the loop should have been completely inverted but the tests on Result were left as is.
This results in the fact that a valid translation found by the initial call is immediately overwritten by the call to dngettext in the loop.
The loop condition should read like this:
while ((Result = singular) or (Result = plural)) and (domainIndex < domainlist.count) do begin
Note how the tests on result have been inverted while still being grouped together.
With this, I now have the proper translation being returned.