-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.x] Configurable pluralizer language and uncountables #41941
Conversation
@cesarep remember that draft PR's aren't reviewed. |
I know! |
This add a new dependency to |
b92540e
to
fefad78
Compare
That's weird when the test is run here it doesn't seem to use the portuguese ruleset Or we might as well go without a test. I was looking at the Inflector rules for portuguese anyway and, while it does really helps with probably 90% of the common words, there are still some inconsistencies that i'm reviewing doctrine/inflector#195 |
In case someone knows a way to workaround this static instance issue, we should reset the instance to the desired languages when the test begins (ideally there should be a test for each available language), and back to english once it finishes, so it doesn't mess up the rest of the tests after it. |
Removed container / config dependency. Added Pluralizer::useLanguage(string) method. |
Oh great!! How should this be setup on our apps? |
Hello!
As said previously on #41891, Pluralizer already handles all the uncountable words, so maintaining a list of those here is really redundant, the only words not listed there were already merged doctrine/inflector#194, with the exception of recommended and related for not being nouns, so i added the recommendation on the comments to request new nouns there, and keep this array for edge cases only. And while they don't release the 2.0.5 version with this merge, cattle and kin also stayed, avoiding any breaking changes.
As for the language configuration, i finally understood the errors on the last PR!
The tests on
tests/Database
use the Pluralizer as it's an essential part of Eloquent, however, their testcases (and the pluralizer test too) extendPHPUnit\Framework\TestCase
instead ofOrchestra\Testbench\TestCase
, not bootstrapping the application, so it's useless to setup agetEnvironmentSetUp($app)
function there. All the tests on features that depend on the Pluralizer and don't bootstrap the app will always throw an error saying theconfig
class doesn't exist.I used a simple
$app->has('config')
to check if the instance has this class, to get the config, otherwise it returns the default english version, acting as a fallback if the pluralizer is used outside Laravel, bypassing that error. A more elegant way to check if an Instance exists is most welcome of course.I'm being insistent on this because I really believe this feature will be very useful for a lot of non-english speaking developers making apps on their languages. Me, personally, I'm using a modified version of Laravel with this.
It might be nice to also add new Orchestra's testcases for the Pluralizer with the other languages, i could contribute with the portuguese test. Inside
tests/Integration/Support
maybe?I set the config path to
'app.pluralizer.language'
, grouping all the pluralizer related configs in one array in case someone finds a way to further extend the pluralizer with custom rules or custom words that might be set from the configs files.