Hey @tobifjellner
Thanks for the detailed explanation!
Seeing that _n
provides multiple translation fields to account for multiple plural forms, it still seems to me that a translator can decide (depending on context) whether the English-equivalent singular should (or should not) be used in other plural forms or not.
From what I can tell the main issue of using _n
in this context arises in languages like Japanese, where the translator only gets 1 field, when 2 would be required.
If so, then it might be a good idea to revise the documentation supporting _n
: “Used when you want to use the appropriate form of a string based on whether a number is singular or plural.”
This description far from conveys the depth of information you are sharing here. Remember that a sentence can contain multiple singular/plural forms for nouns / pronouns, and a language that uses the same form for nouns may potentially use different forms for pronouns, e.g.:
“I bought 1 apple. It is one of the sweetest tasting apples I’ve had”.
“I bought X apples. They are some of the sweetest tasting apples I’ve had.”
In this case the first sentence might be a good candidate for _n
, but not the second one? Which means that putting them together in one _n
string would be bad practice.
Assuming that the two sentences need to be fed into different gettext functions, then developers will need to concatenate them as well ??
To account for RTL languages, the concatenation would need to happen via a gettext replacement — which is the only valid way to concatenate strings IMO.
Which brings me to your second point — concatenation. Is there another valid way to put together two sentences than to replace one in the other, or to use an in-between string such as %1$s%2$s, 'some context'
to handle the replacement in an RTL-safe manner? As long as you concatenate full sentences this should be a reasonably safe practice.
Generally speaking, as much as we all try to follow good practices when writing code, in some cases it is very difficult to follow translation guidelines to the letter, because:
1) Developers apparently must have a basic understanding of grammar and syntax in multiple languages.
2) Very often it is impossible to structure code in a translation-aware way that accounts for every possible language.
As an example — if your objective as a developer is to display a message containing some string replacements, and these strings are dependent on the state of multiple variables, then you can either choose to concatenate once, or construct your message in a dedicated block of code by writing potentially dozens/hundreds of different versions of the same string depending on your input variables.
For most developers, the intuitively “better” approach would be to break things up and concatenate once — not out of laziness, but because there’s no other feasible way.
The extent to which a project should adhere to translation guidelines is a product-related decision with serious implications from a development/cost perspective and as such, it needs to be weighed on a cost/benefit scale.
For open-source plugins specifically, it is always up to the community itself to take initiative in implementing code changes to make popular plugins easier to translate — and as a result more accessible.