Hello! I am just starting with Laravel, and I have a question on how to solve this "the right way".
I have lots of words in spanish that the plural is not simply appending an "s" in the end, for example, the plural for "Especialidad" is "Especialidades", or the plural for "ObraSocial" is "ObrasSociales".
I'm seeing that there is src/Illuminate/Support/Pluralizer.php with an $irregular array. Is the correct way to add that words in this array (I don't think so..), or is there any other place from where I can put all the words that I need to use?
thanks!
Hi Ricardo,
Here how to pluralize or singularize irregular strings (based on old Laravel 4 issue #2101) for Laravel 4:
<?php
// Fails:
// echo str_plural('bureau');// → 'bureaus'
$newIrregular = ['bureau' => 'bureaux'];
$oldIrregular = \Illuminate\Support\Pluralizer::$irregular;
\Illuminate\Support\Pluralizer::$irregular = array_merge($oldIrregular, $newIrregular);
// Success:
echo str_plural('bureau');// → 'bureaux'
Cheers, Tortue Torche
And here how to pluralize or singularize irregular strings for Laravel 5:
// Fails:
// echo str_plural('bureau');// → 'bureaus'
$newIrregularRules = ['bureau' => 'bureaux'];
\Doctrine\Common\Inflector\Inflector::rules('plural', [
'irregular' => $newIrregularRules
]);
// Success:
echo str_plural('bureau');// → 'bureaux'
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community