Refactor that function like this. No need for “freelancer”.
private function getPluralizationRule(float $number, string $locale): int
{
$number = abs($number);
$locale = ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3)
? substr($locale, 0, strrpos($locale, '_'))
: $locale;
if (in_array($locale, [
'af', 'bn', 'bg', 'ca', 'da', 'de', 'el', 'en', 'en_US_POSIX', 'eo', 'es', 'et', 'eu',
'fa', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'he', 'hu', 'is', 'it', 'ku', 'lb',
'ml', 'mn', 'mr', 'nah', 'nb', 'ne', 'nl', 'nn', 'no', 'oc', 'om', 'or', 'pa', 'pap',
'ps', 'pt', 'so', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'zu'
])) {
return (1 == $number) ? 0 : 1;
}
if (in_array($locale, ['am', 'bh', 'fil', 'fr', 'gun', 'hi', 'hy', 'ln', 'mg', 'nso', 'pt_BR', 'ti', 'wa'])) {
return ($number < 2) ? 0 : 1;
}
if (in_array($locale, ['be', 'bs', 'hr', 'ru', 'sh', 'sr', 'uk'])) {
return ((1 == $number % 10) && (11 != $number % 100)) ? 0 :
((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
}
if (in_array($locale, ['cs', 'sk'])) {
return (1 == $number) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
}
if ($locale === 'ga') {
return (1 == $number) ? 0 : ((2 == $number) ? 1 : 2);
}
if ($locale === 'lt') {
return ((1 == $number % 10) && (11 != $number % 100)) ? 0 :
((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
}
if ($locale === 'sl') {
return (1 == $number % 100) ? 0 :
((2 == $number % 100) ? 1 : (((3 == $number % 100) || (4 == $number % 100)) ? 2 : 3));
}
if ($locale === 'mk') {
return (1 == $number % 10) ? 0 : 1;
}
if ($locale === 'mt') {
return (1 == $number) ? 0 :
(((0 == $number) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 :
((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3));
}
if ($locale === 'lv') {
return (0 == $number) ? 0 : (((1 == $number % 10) && (11 != $number % 100)) ? 1 : 2);
}
if ($locale === 'pl') {
return (1 == $number) ? 0 :
((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2);
}
if ($locale === 'cy') {
return (1 == $number) ? 0 : ((2 == $number) ? 1 : (((8 == $number) || (11 == $number)) ? 2 : 3));
}
if ($locale === 'ro') {
return (1 == $number) ? 0 :
(((0 == $number) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
}
if ($locale === 'ar') {
return (0 == $number) ? 0 :
((1 == $number) ? 1 : ((2 == $number) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5))));
}
return 0;
}