Opened 5 years ago

Last modified 11 months ago

#15156 new New feature

Ordinal numbers in English and in other locales

Reported by: Besnik <besnik@…> Owned by:
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Some of the strings on contrib-humanize.po could be not used for Albanian locale (sq). I suppose other locales have the same issue with the way English build ordinal numbers using th, st, nd and rd (as in 4th, 15th, 2nd, etc). To make things even more complicated, there is gender to be considered here. As an example, the word used for "month" and the one used for "week" have different gender in Albanian.

Change History (15)

comment:1 Changed 5 years ago by Besnik <besnik@…>

  • Component changed from Uncategorized to Translations
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by claudep

The ordinal template tag of contrib.humanize is not fully localizable in several languages, indeed. But I think this is an unresolvable issue. There are just too many different cases to consider as the algorithm may be different for each language. I suggest to look at the code and implement it for your own specific needs (languages).

This reminds me about a similar discussion in the GNOME Nautilus File Manager (see e.g. and

comment:3 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Design decision needed

Marking this DDN. Like claudep, I'm not convinced this is even possible, but i18n isn't my specialty.

comment:4 Changed 5 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:5 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • UI/UX unset

We might improve things slightly by using pgettext_lazy instead of ugettext_lazy.

That would make it possible to distinguish the 'th' for 0 from the 'th' for 5 in this list:

suffixes = (_('th'), _('st'), _('nd'), _('rd'), _('th'), _('th'), _('th'), _('th'), _('th'), _('th'))

Would this be useful? If it isn't, then I think we should just close this as "wontfix".

Handling gender in the ordinal filter is another topic, I suggest opening another ticket for this feature if you deem it useful.

comment:6 Changed 3 years ago by jezdez

  • Triage Stage changed from Design decision needed to Accepted

I agree with aausgustin's idea of using pgettext. It's better than nothing.

comment:7 Changed 3 years ago by zerok

Given the severe differences between how different languages "count" wouldn't that in the worst case require the context to actually include the number itself?

I skimmed a little bit through and some pages about the Japanese and Chinese languages going with at worst 1-10+above should be enough except for following exceptions:

  • Swedish: Here every number that ends with a 1 or 2 has to suffixed with ":a" instead of ":e"
  • Russian
  • Catalan
  • Galician, Italian, Portuguese, and Spanish: The suffix depends on the gender of the noun to be counted

That being said, the list on Wikipedia looks very incomplete, but if the information about very widely uses languages like Spanish is correct here, the context would have to include the whole number, which looks rather impractical to me :-/

Since the gender could be indicated by the context it is not as problematic as the irregular suffix/prefix in languages like Russian and Catalan.

Last edited 3 years ago by zerok (previous) (diff)

comment:8 Changed 3 years ago by claudep

I'm not suprised at all by your findings. I maintain my original opinion: the rules are too much diverse to be able to solve this by mere translation.

comment:9 Changed 3 years ago by aaugustin

Yeah, the fix proposed here is "better than nothing, fixes it for a few languages". It's by no means a definitive solution.

Last edited 3 years ago by aaugustin (previous) (diff)

comment:10 Changed 3 years ago by zerok

  • Owner changed from nobody to zerok
  • Status changed from new to assigned

comment:11 Changed 3 years ago by claudep

Proposal: Allow defining a def ordinal(value): function in conf/locale/<lang>/ We could then generate the ordinal string by calling get_format('ordinal')(value).

comment:12 Changed 3 years ago by zerok

Yes, I was thinking along the same line. is probably the best place for this too. At first I thought that may be localflavor would be better, but since that is based around countries and not languages, sounds to me like the ideal place.

I will try to come up with an implementation in the next week or so.

Sorry for the delay on this.

comment:13 Changed 2 years ago by zerok

One issue I see there so far is how to deal with setups where USE_L10N is disabled. Should in this case a fallback implementation be just used from locales.en.formats or should this be integrated in the global_settings module? IMO the first one makes more sense since this would be the one and only callable in the whole settings module right now which would break the style there.

Something else I'd like to get in there is having the system still be based around messages in order to allow users to get their custom "context" (referencing the noun the ordinal is intended for) into the message. This way languages like Spanish that don't have a gender-neutral ordinal-indicator could detect the necessary gender from something like {{ num|ordinal:"email" }}.

I don't know if the ordinal would always reference the same noun in a sentence independent of the language but it should get around at least some of the edge cases.

@Besnik Would this help in your situation?

comment:14 Changed 2 years ago by zerok

  • Owner zerok deleted
  • Status changed from assigned to new

Sorry, but I didn't find and probably won't find the time this ticket requires. I've therefor deasigned it.

comment:15 Changed 11 months ago by timgraham

  • Component changed from Translations to Internationalization
  • Version changed from 1.2 to master
Note: See TracTickets for help on using tickets.
Back to Top