Question

I'm using the PECL intl module to localize dates and numbers in a PHP project. In all other languages I'm using (40), localizing ordinal numbers works fine. In Swedish, however, I get strange output. It appears to be the template constants used to generate the ordinals.

$fnf = new NumberFormatter('sv_FI', NumberFormatter::ORDINAL);
echo $fnf->format(1);

and

$snf = new NumberFormatter('sv_SE', NumberFormatter::ORDINAL);
echo $snf->format(1);

Both return 1:e%digits-ordinal-neutre:0: 1:a vs. something like 1st or 1er.

My only guess, other than a bug, is that I'm missing some additional argument such as the gender of an associated verb.

Was it helpful?

Solution

If you output the rule based number formatters rules $fnf->getPattern():

%digits-ordinal-masculine:
    0: =#,##0==%%dord-mascabbrev=;
    -x: −>%digits-ordinal-masculine>;
%%dord-mascabbrev:
    0: :e%digits-ordinal-neutre:0: =%digits-ordinal-feminine=;
%digits-ordinal-reale:
    0: =%digits-ordinal-feminine=;
%digits-ordinal-feminine:
    0: =#,##0==%%dord-femabbrev=;
    -x: −>%digits-ordinal-feminine>;
%%dord-femabbrev:
    0: :e;
    1: :a;
    2: :a;
    3: :e;
    20: >%%dord-femabbrev>;
    100: >%%dord-femabbrev>;
%digits-ordinal:
    0: =%digits-ordinal-masculine=;

You can see that the private rule set dord-mascabbrev only has one rule giving that value:

:e%digits-ordinal-neutre:0: 1:a

Which you will have then output after your 1, like you describe in your question.

This is not a bug in PECL INTL, but the underlying rule is malformatted which is part of the ICU Libraries (that rule there). About three years ago the sv number formatter rules were fixed for missing semicolons, it looks like that one line slipped through.

These rules are taken into ICU from the CLDR (Common Locale Data Repository) at the Unicode Consortium. I opened a bug report there, because unless this is fixed in CLDR, and then put into ICU, it can't work with the PHP INTL extension.

The alternative might be to manually patch the ICU libraries (version 4.8) and then build the PECL package against your patched libraries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top