mysociety / alaveteli

Provide a Freedom of Information request system for your jurisdiction
https://alaveteli.org
Other
389 stars 195 forks source link

Allow front page text to handle plural forms #3942

Open crowbot opened 7 years ago

crowbot commented 7 years ago

The text

Search over<br/>" \
        "<strong>{{number_of_requests}} requests</strong> " \
        "<span>and</span><br/>" \
        "<strong>{{number_of_authorities}} authorities</strong>"

doesn't use n_() and so can't handle variants in plural forms - reuser says "We need one, few and many version for the number of requests and number of authorities."

lizconlan commented 7 years ago

Note n_() can only handle 1 count value at a time so without splitting the string into 2 parts, we'd have to choose between being able to generate plural form translations for requests or authorities.

View definition of FastGettext.n_ ```rb #translate pluralized # some languages have up to 4 plural forms... # n_(singular, plural, plural form 2, ..., count) # n_('apple','apples',3) def n_(*keys, &block) count = keys.pop translations = FastGettext.cached_plural_find(*keys) selected = FastGettext.pluralisation_rule.call(count) selected = (selected ? 1 : 0) unless selected.is_a? Numeric #convert booleans to numbers result = translations[selected] if result result elsif keys[selected] _(keys[selected]) else block ? block.call : keys.last end end ```


Although having looked at this in a bit more detail, I am struggling to work out under what circumstances the front page would need this, particularly given that IPV currently has over 6,000 public requests and nearly 12,000 authorities.

What am I missing?

garethrees commented 7 years ago

What am I missing?

I think that there need to be three options, rather than two:

We need one, few and many version for the number of requests and number of authorities."

I guess this means adding an abnormal pluralisation rule to FastGettext.

lizconlan commented 7 years ago

I guess this means adding an abnormal pluralisation rule to FastGettext

It's already in the pofile so we don't need to add anything to the Ruby code:

"Language-Team: Czech (http://www.transifex.com/mysociety/alaveteli/language/cs/)\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"

So to solve this for Czech, I just need to add an extra option to the call to n_ (Although it looks as though Polish has 4 plural forms and Arabic has 6...)

lizconlan commented 7 years ago

Although I still can't work out how to deal with this format:

Search over<br/>" \
        "<strong>{{number_of_requests}} requests</strong> " \
        "<span>and</span><br/>" \
        "<strong>{{number_of_authorities}} authorities</strong>"

as it has multiple plurals in a single string

garethrees commented 7 years ago

Ah with you. Seems like you can't.

I guess you'd have to have a few different strings to handle the different cases

if number_of_requests.size == 1 && number_of_authorities.size == 1
  # …
elsif number_of_requests.size > 1 && number_of_authorities.size == 1
  # …
#etc
end

Not sure its worth the effort for one string, but @crowbot probably has a better idea of the specific issue the partner is concerned about.

lizconlan commented 7 years ago

It looks like their extra rule is for > 4 which is going to apply most of the time on that page

lizconlan commented 7 years ago

ToDo: