13

Background

I work on an app that has many translations inside it.

I have the next English plural strings:

<plurals name="something">
    <item quantity="one">added photo</item>
    <item quantity="other">added %d photos</item>
</plurals>

and the French translation:

<plurals name="something">
    <item quantity="one">a ajouté une photo</item>
    <item quantity="other">a ajouté %d photos</item>
</plurals>

The problem

For both the French and Russian, I get the next warning:

The quantity 'one' matches more than one specific number in this locale, but the message did not include a formatting argument (such as %d). This is usually an internationalization error. See full issue explanation for more.

when choosing to show details , it says: enter image description here

Thins is, I don't get what should be done to fix it, and if there is even a problem...

The question

What exactly should I do with those strings? What should I tell the translators?

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • That means that numbers that end in one should use the singular form. Android will use singular form for French but it's incorrect to say "added photo" for 101 photos for example. So I guess you are using the plural strings incorrectly. Or use `"added %d photo"` instead. Android will use "Added 1 photo" in English and in French it will use `a ajouté 101 photo` which is the way correct to say it – Pedro Oliveira Oct 02 '14 at 11:27
  • This is an old question but the comment from @PedroOliveira needs correcting : `a ajouté 101 photo` is definitely _not_ French; we say `a ajouté 101 photos` (notice the *s* — http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#fr-comp if you're unsure) . So Android is **wrong** : in the French locale, the quantity `one` matches only a single specific number : 1, and the linter _should not_ indicate a problem here. – tchap Dec 23 '15 at 21:55
  • @tchap Old question indeed but since then, Android Studio got more precise about the problem and tells `The quantity 'one' matches more than one specific number in this locale (0,1) [...]` ; which is **correct**, in French you can say `a ajouté 0 photo` and `a ajouté 1 photo`. Anyway I'm just here to comment that although Android Studio is complaining, it doesn't prevented me from compiling ans running my app. – Unda Feb 17 '16 at 14:02
  • 1
    @Unda **no** it is not correct, the quantity "one" matches 1 only ! 0 is matched with quantity "zero" (see https://developer.android.com/guide/topics/resources/string-resource.html#Plurals). I understand it works anyway since it's just a warning, but Android Studio should not complain :) – tchap Feb 17 '16 at 14:26
  • @tchap I understant that "one" matches 1 ans "zero" matches 0, I can only agree with you on this one. I'm just saying that in French, there's no difference between 1 and 0 in terms of plurals (at least none that I can think of ...), so IMO Android Studio is right to handle them the same way. But, is it "right" to handle them both under the "one" quantity (as Android Studio seems to do, from the error message), I don't think so ... But that's the way it is ... – Unda Feb 17 '16 at 15:00
  • 1
    Is at the end somebody right? each one says another thing. – David Mar 27 '17 at 13:43
  • @David, at least, "no items" is better than "0 items". Moreover, for several languages `zero` item is not the same as `other`. So, 0, 1, 2, 5 are different. Android should distinguish not only `one` and `other`. – CoolMind Apr 25 '19 at 10:07

2 Answers2

5

I'm going to write an answer since this is quite an difficult explanation.

In various languages, nouns use the singular form if they end with 1. Refer to: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html

Explaining in English there are languages where it's correct to say "added 1 photo" as well as "added 101 photo". Notice the "photo". So this means that you should always add "%d" on one strings as well. Android will choose the best scenario to use. Which means that in English it will choose "other" for numbers > 1 and on other languages it will choose "one" for numbers ended in one.

Resuming, add %d to your one string and should be fine. Also make sure your translators respect the plural rules for their language.

Pedro Oliveira
  • 20,442
  • 8
  • 55
  • 82
  • I've now spoken to someone I know, that knows Russian, and he said it's ok to say it this way, so I still don't get what's wrong. – android developer Oct 02 '14 at 13:52
  • Check that website. As you can see on Russian the cardinal "one" is used for all numbers that end in 1. – Pedro Oliveira Oct 02 '14 at 13:55
  • but he said it's ok to say it this way. – android developer Oct 02 '14 at 14:00
  • 2
    Just because it's okay that say that doesn't mean it's the proper way. The same goes for other languages. I suggest you read http://cldr.unicode.org/index/cldr-spec/plural-rules too – Pedro Oliveira Oct 02 '14 at 14:02
  • 1
    "the cardinal "one" is used for all numbers that end in 1" - except 11 – Anton Malyshev Aug 12 '15 at 08:05
  • @androiddeveloper, I think that whether it is "ok" or "not ok" to use some form is irrelevant - you just need to understand how the system currently works. This answer is good. If you want to omit the quantity digit for a single item, you can always define additional string and perform a manual check before asking for "pluralized" string resource: `if (someQuantity == 1) {...}` – Vasiliy Oct 31 '16 at 15:28
5

In French singular form is used when count is 0 or 1. In English singular form is used only when count is 1. 0 uses a plural form.

This is why you need to insert a placeholder (%d) in your French singular pattern.

Jaska
  • 1,007
  • 10
  • 9
  • I see. Thank you – android developer Nov 14 '17 at 23:24
  • 2
    I know it is an old issue, but why I need to add the placeholder into the string? I don't need to have them there, for other locales and they are not used in code. I don't want to change other locales and code for just one (or more) languages. If I understand it correctly, why I cannot just add zero item quantity into Franch locale? Is there some logical reason for adding the placeholder into the string or is it just an Android Studio limitation? – kycera Jun 07 '21 at 14:52
  • Because if you don't have a place holder in the French pattern you cannot make difference between 0 and 1. The original sample had no placeholder so in both 0 and 1 cases "a ajouté une photo" was shown – Jaska Jun 08 '21 at 15:23