Twig icon indicating copy to clipboard operation
Twig copied to clipboard

[Intl] format to feminine ordinal numbers

Open JorickPepin opened this issue 2 years ago • 1 comments

As mentioned in this issue, the addition of the Intl extension should have enabled the display of feminine ordinal numbers through the format_ordinal_number filter (e.g. 1re instead of 1er in French), but is this really the case? If so, how could this be achieved? Thanks in advance.

JorickPepin avatar Dec 07 '23 16:12 JorickPepin

In the current implementation, i think you'd code it quicker by yourself in a dedicated extension... than with the IntlExtension.

As you can see in the createNumberFormatter() method, the only way to set textAttributes would be to inject a $prototype ... but even then, you'd only can set "feminine" or "masculine" once.

Or you can try to find another way to add this behaviour line 511 (if the $textAttrs in not usable as right now)


        foreach ($textAttrs as $name => $value) {
            $this->numberFormatters[$hash]->setTextAttribute(self::NUMBER_TEXT_ATTRIBUTES[$name], $value);
        }

        foreach ($symbols as $name => $value) {
            $this->numberFormatters[$hash]->setSymbol(self::NUMBER_SYMBOLS[$name], $value);
        }

+        $this->numberFormatters[$hash]->setTextAttribute(self::NUMBER_TEXT_ATTRIBUTES['default_ruleset'], '%digits-ordinal-feminine');

        return $this->numberFormatters[$hash];
    }
}

smnandre avatar Jan 13 '24 23:01 smnandre