How to format date range for text (internationalized)

Say I have a DateInterval, for example, "P10DT1H53S", and I want to format it for a human-readable string, for example:

10 days, 1 hour and 53 seconds

Now it's pretty easy if you only plan on doing it for English. But I'm looking for a clean and internationalized way to do this using gettext.

Unfortunately, gettext only processes one plural at a time and not several (years, days, hours, etc.), so I cannot use ngettext to achieve what I want. And plurals differ greatly in language, so it’s not as easy as iterating and adding “s” where necessary. In addition, I have to build it as a whole, because I'm not sure that each language will separate days, hours, ... using commas (with one "and" instead of the last comma).

+3
source share
2 answers

You can use multiple calls for gettext instead of doing it in only one. This should circumvent the plural limit.

0
source

CLDR, Unicode. .

XML . , , POSIX.

, , PHP ( ), , , .

+1

Source: https://habr.com/ru/post/1796624/


All Articles