Skip to content
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

[8.x] Update the Pluralizer Inflector instanciator #40336

Merged
merged 1 commit into from
Jan 11, 2022
Merged

[8.x] Update the Pluralizer Inflector instanciator #40336

merged 1 commit into from
Jan 11, 2022

Conversation

cesarep
Copy link
Contributor

@cesarep cesarep commented Jan 10, 2022

Uses the InflectorFactory::createForLanguage function to generate the instance

Should make it easier to change to other available languages rulesets such as French, Norwegian Bokmal, Portuguese, Spanish and Turkish

Uses the InflectorFactory::createForLanguage function to generate the instance
Should make it easier to change to other available languages rulesets such as French, Norwegian Bokmal, Portuguese, Spanish and Turkish
English\Rules::getPluralRuleset()
))
);
$inflector = InflectorFactory::createForLanguage('english')->build();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use their language constants.

<?php

use Doctrine\Inflector\InflectorFactory;
use Doctrine\Inflector\Language;

$inflector = InflectorFactory::createForLanguage(Language::ENLISH)->build();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main goal actually was to make it easier to change the language ruleset, just like changing the locale in the config/app.php file, adding another configuration for the pluralizer ruleset. I was thinking something like:

$inflector = InflectorFactory::createForLanguage(  $app['config']->get('app.pluralizer_ruleset', 'english')  )->build();

But I'm not sure how to fully implement it...
Other classes appear to get the config values from $this->app, however class Pluralizer does not extends any other class, so $this shoudn't have access to the app right?

@taylorotwell taylorotwell merged commit 7b165c7 into laravel:8.x Jan 11, 2022
@cesarep
Copy link
Contributor Author

cesarep commented Jan 11, 2022

I included the use Illuminate\Support\Facades\Config; on top, and
$inflector = InflectorFactory::createForLanguage(Config::get('app.pluralizer_ruleset', 'english'))->build();

and added 'pluralizer_ruleset' => 'portuguese', to the config/app.php to test on my machine, it appers to be working fine!

I just had to mannualy set the users table name on the User Model

Should i make another pull request or is there a way to reopen it? I didn't expect it to be closed so quickly 😅

For me it's a very useful feature, not having to manually set a lot of parameters and table names because of different language plurals

@driesvints
Copy link
Member

@cesarep a facade can't be mixed here. This class may be used outside Laravel.

If you aren't ready with a PR then please use draft PR's to mark them as in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants