InfyOmLabs / laravel-generator

API and Admin Panel CRUD Generator for Laravel.
https://www.infyom.com/open-source
MIT License
3.79k stars 814 forks source link

Change Pluralisation rules #479

Closed Silvio12 closed 5 years ago

Silvio12 commented 7 years ago

Hi,

is it possible to change the pluralisation rules for this package? In english you have for example athlete=>athletes but in other languages you need other rules. Is it possible to define some irregular words or to change the language for the pluralisation rule?

mitulgolakiya commented 7 years ago

@Silvio12 Can you post some more details with some examples?

Maybe it can be possible via publishing templates. But I need to confirm. so if you can post some examples, then I can let you know exactly, if it is possible or not.

sistemaswebbrasil commented 7 years ago

I also have problem with pluralization, I decided to change the file /var/www/html/infyom/vendor/infyomlabs/laravel-generator/src/Common/GeneratorConfig.php in function prepareModelNames
$this->mPlural = Str::plural($this->mName); to this->mPlural = $this->mName;I would like to pass a parameter to say which is the plural of my ex template: --plural. But I can not understand how to add a new parameter.

Sorry, my English came from Google Translate.

juliocg86 commented 6 years ago

Hi! I have the same problem with pluralization. I resolved it on this way:

In infyomlabs/laravel-generator/src/Common/GeneratorConfig.php, edit the array $availableOptions, adding 'plural' at the end.

/* Command Options */
public static $availableOptions = [
    'fieldsFile',
    'jsonFromGUI',
    'tableName',
    'fromTable',
    'save',
    'primary',
    'prefix',
    'paginate',
    'skip',
    'datatables',
    'views',
    'relations',
    'plural'
];

next, edit the first line of the function prepareModelNames

    if ($this->getOption('plural')) {
       $this->mPlural = $this->getOption('plural');
    } else {
       $this->mPlural = Str::plural($this->mName);
    }

In infyomlabs/laravel-generator/src/Commands/BaseCommand.php -> getOptions add 'plural' to the array, on this way:

public function getOptions()
{
    return [
        ['fieldsFile', null, InputOption::VALUE_REQUIRED, 'Fields input as json file'],
        ['jsonFromGUI', null, InputOption::VALUE_REQUIRED, 'Direct Json string while using GUI interface'],
        ['tableName', null, InputOption::VALUE_REQUIRED, 'Table Name'],
        ['plural', null, InputOption::VALUE_REQUIRED, 'Model Plural'],
        ['fromTable', null, InputOption::VALUE_NONE, 'Generate from existing table'],
        ['save', null, InputOption::VALUE_NONE, 'Save model schema to file'],
        ['primary', null, InputOption::VALUE_REQUIRED, 'Custom primary key'],
        ['prefix', null, InputOption::VALUE_REQUIRED, 'Prefix for all files'],
        ['paginate', null, InputOption::VALUE_REQUIRED, 'Pagination for index.blade.php'],
        ['skip', null, InputOption::VALUE_REQUIRED, 'Skip Specific Items to Generate (migration,model,controllers,api_controller,scaffold_controller,repository,requests,api_requests,scaffold_requests,routes,api_routes,scaffold_routes,views,tests,menu,dump-autoload)'],
        ['datatables', null, InputOption::VALUE_REQUIRED, 'Override datatables settings'],
        ['views', null, InputOption::VALUE_REQUIRED, 'Specify only the views you want generated: index,create,edit,show'],
        ['relations', null, InputOption::VALUE_NONE, 'Specify if you want to pass relationships for fields'],
    ];
}

That's all! Now, if you want to use a custom plural for a model, you can use --plural=pluralmodelname