Opened 11 years ago
Last modified 2 years ago
#22225 reviewing enhancement
WordPress does not localize ordinal suffixes in dates
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 3.4.2 |
Component: | I18N | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
In wp-includes/functions.php function date_i18n(), elements like month, month abbreviation, weekday etc.. are localized but not the ordinal suffixes (e.g. st, nd, rt, th)
effect: when using the ordinal suffixes for dates
e.g.
<?php the_time('F jS, Y'); ?>
on translated/localized page page, the month name is translated (F) but the ordinal suffix no.
Not browser/OS/environment dependent.
Attachments (3)
Change History (20)
#4
@
8 years ago
- Keywords needs-patch removed
I had to extend some functionality in WP_locale too. There were no unit tests for this class so I tested all of the things needed together.
#6
follow-up:
↓ 7
@
8 years ago
@realloc nice approach of using wp-locale, but I think there is some confusion about 'S'. It is the day of the month rather than the month number. So for instance, the output of
<?php date_i18n( 'S', 1424001600 ) //Feb 15th, 2015
Should not be expecting 'nd' in the unit test, it should be 'th'.
I think it needs a function that is hardcoded into wp-locale to handle each locale. Maybe something based off of this wikipedia article? For some languages we should entirely remove the 'S'. I ended up here due to Russian and Hebrew localization of 'F jS' where I think I understand the best solution to be removing the 'S' entirely. cc @kovshenin
Also looks like in PHP 5.3.0+ there is support for formatting an ordinal. So maybe should use that with a reasonable fall back for old versions of PHP?
#7
in reply to:
↑ 6
@
8 years ago
Replying to gibrown:
@realloc nice approach of using wp-locale, but I think there is some confusion about 'S'. It is the day of the month rather than the month number. So for instance, the output of
Thanks a lot! After reading http://php.net/manual/en/function.date.php again I have to admit that your are completely right. 'S' is indeed not meant for months but for days.
Also looks like in PHP 5.3.0+ there is support for formatting an ordinal. So maybe should use that with a reasonable fall back for old versions of PHP?
It seems that the class NumberFormatter needs PHP 5 >= 5.3.0 and PECL intl >= 1.0.0 ... I'm sure that discussions about these things will be very interesting in the near future.
Anyway, I worked on a new solution today. ;) I think that WordPress should at least provide the functionality for the English ordinal numbers but should also come with a filter so that a developer could extend it easily. In German the rules are very different for example: they append the suffix 'te' to numbers from 0 to 19 and 'ste' from 20 and above.
#8
follow-up:
↓ 9
@
8 years ago
Feels like it would be good to have test cases in different languages for this to prove out that it works across multiple languages. Looking at the code it is not obvious to me that it would work for how you describe German for instance.
#9
in reply to:
↑ 8
@
8 years ago
Replying to gibrown:
Feels like it would be good to have test cases in different languages for this to prove out that it works across multiple languages.
I just added 2 filter examples to illustrate the idea. Any multilingual plugin could so implement the necessary functionality.
This ticket was mentioned in Slack in #core-i18n by ocean90. View the logs.
8 years ago
#12
@
8 years ago
- Milestone changed from Awaiting Review to 4.6
- Owner changed from SergeyBiryukov to ocean90
#13
@
8 years ago
- Keywords dev-feedback needs-testing removed
- Milestone changed from 4.6 to Future Release
- Owner ocean90 deleted
I don't like the filter approach because it doesn't provide out of the box support for any other locale. As you've already noticed Russian doesn't have a specific identifier for ordinals and an empty translations is not supported.
I'd like to see an approach which follows the Plural-Forms
entry in a .po file. It's "Plural-Forms: nplurals=2; plural=n != 1;\n"
for German or "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
for Russian.
You'll see similar rules in the Unicode CLDR database: http://www.unicode.org/cldr/charts/29/supplemental/language_plural_rules.html.
An example for English could be "Ordinal-Forms: nplurals=4; plural=(n % 10 = 1 && n % 100 != 11) ? 'st' : (n % 10 = 3 && n % 100 != 13) ? 'nd' : (n % 10 = 3 && n % 100 != 13) ? 'rd' : 'th';"
.
That's something which we can be stored into the translation file and parsed by a WP_Locale::get_ordinal_suffix()
method.
This ticket was mentioned in Slack in #core by johnbillion. View the logs.
7 years ago
#15
@
7 years ago
What if we simply drop back the whole solution to something that already works for everyone?, by simply using gettext an already normal translations tools?.
We could add 31 strings to translate, with proper context to make sure that they're understood and correctly translated.
_x( 'st', 'Ordinal suffix for day 1 in month, "-" for empty', 'my-text-domain'
_x( 'nd', 'Ordinal suffix for day 2 in month, "-" for empty', 'my-text-domain'
_x( 'rd', 'Ordinal suffix for day 3 in month, "-" for empty', 'my-text-domain'
_x( 'th', 'Ordinal suffix for day 4 in month, "-" for empty', 'my-text-domain'
_x( 'th', 'Ordinal suffix for day 5 in month, "-" for empty', 'my-text-domain'
_x( 'st', 'Ordinal suffix for day 31 in month, "-" for empty', 'my-text-domain'
...
And then wrap it up in a simple function?
#16
@
3 years ago
I ran into this today. It seems like this ticket has stalled out many years ago so I just wanted to add here that this is something that people still run into today. I've disabled the ordinal suffix on our site for now as I have no good alternative.
Related: #11226