silverstripe-admin icon indicating copy to clipboard operation
silverstripe-admin copied to clipboard

Pluralisation API for front-end

Open phalkunz opened this issue 7 years ago • 4 comments

Implement count-based pluralisation that mirrors the current i18n PHP API in JavaScript.

Note: At some point we might reuse the same language strings for both PHP and JS, so it's important that their syntax is compatible.

phalkunz avatar Sep 01 '17 03:09 phalkunz

Ugh, can we not? i18n::pluralise() in PHP is a dirty hack, and only works in (some) English nouns. I propose we make all plurals available from translation files, and have translators figure them out themselves for every language (incl english): https://github.com/silverstripe/silverstripe-admin/issues/223.

Or did I misunderstand this issue @phalkunz? Can you add some more detail please?

chillu avatar Sep 05 '17 20:09 chillu

@chillu Actually, I created this issue on behalf of @flamerohr. I did the following for a term that has singular and plural forms:

{
  "class.TERM_SINGULAR": "1 item",
  "class.TERM_PLURAL": "{count} items",
}

But @flamerohr explained to me, twice, why it wasn't a good idea and I still can't remember what it was. Sorry @flamerohr, can you help flesh this issue out?

phalkunz avatar Nov 30 '17 22:11 phalkunz

This is in the Javascript side which does not have anything like it implemented... The PHP side has pluralisation in and working _t('CLASS.KEY', 'FALLBACK', ['count' => $count])

So at the moment messages in javascript would need to be plural/quantity-agnostic, I strongly disagree with having an entry for singular and another for plural as this limits our components to work with a few languages which include english.

e.g. Polish has multiple plural levels (as seen in one of core's plural unit tests):

'0 miesięcy',
'1 miesiąc',
'2 miesiące',
'5 miesięcy',
'10 miesięcy',

flamerohr avatar Nov 30 '17 23:11 flamerohr

Right, badly described ticket leading to misunderstandings. I don't want us to recreate the english-focused pseudo-automatic pluralisation that's been part of DataObject since 2.x days. I agree with Chris' sentiments.

chillu avatar Nov 30 '17 23:11 chillu