CrestApps / laravel-code-generator

An efficient Laravel code generator, saving time by automating the creation of resources such as views, controllers, routes, migrations, languages, and form-requests. Highly flexible and customizable, it includes a cross-browser compatible template and client-side validation for application modernization.
https://laravel-code-generator.crestapps.com
MIT License
738 stars 158 forks source link

language files creating doesn't work #17

Closed qcol closed 7 years ago

qcol commented 7 years ago

Hi Today I found this Laravel generator and I'm very impressed... It can do much better than a lot older InfyOm or scaffold-interface. Respect - good job!

So far, one option does not work for me - generating language files. When create resources with options like this: --lang-file-name=products --translation-for=en,pl

No files are created in lang folder and direct english labels are used in Views. I expected, that lang file (lang/products.php) will be created and __('label_name') will be used in Views files. Am i doing something wrong?

MikeAlhayek commented 7 years ago

I am glad you like this package! Thank you. Heads-up Version 2.1.0 which is coming up real soon will be yet more robust for people that use it for multiple languages apps. if you want to test drive it, download dev-master which is 98% ready and stable. If you go this route, make sure to re-issue the publish command.

Back to your question/issue. the issue is actually in the documentation with is misleading. I'll make sure that gets updates soon.

The commands --lang-file-name=products --translation-for=en,pl works when you want to create resources for existing database's table. These commands will generate .json files with your fields, and use these fields to generate the resources all in one command. However, if you do not have existing database and want to design a new one, you'll need to create the fields file first.

If you are using v2.0 or dev-master there is a command to helps you generate the fields-file very quick. (i.e php artisan fields-file:create products.json --names=field1,field2,field3...... --translation-for=en,pl) once the fields-file is creates, and your done customizing it, you can create the resources using the following command (php artisan create:resources Product --fields-file=products.json`

Please let me know if you run into any issues. Also, I would appreciate hearing more about your experience as you are developing a new app with multiple languages.

Thank you

qcol commented 7 years ago

Thank You for quick reply. Maybe I don't understand doc correctly, but in resource section --lang-file-name option says that it puts language file. In my case this does not work. I have created json file from database table before (by php artisan create:fields-file products command). Then, I used create:resource command with --lang-file-name=products --translation-for=en,pl commands. Isn't it correct?

Tried to use php artisan create:language products - command does not produce any results.

Upgraded to dev-master - no change.

By the way: section "How to create a fields' file from existing database" in docs is linked to
https://www.crestapps.com/laravel-code-generator/docs/2.0#how-to-create-field-file.

MikeAlhayek commented 7 years ago

Again, I apologize that the docs are little misleading (that will be fixed soon). If you already create the fields-file from existing database, then your fields field already setup with translatable labels. I assume that you creates the fields-file with --translation-for=en,pl. So you can just run the php artisan create:resources Product .... command without the --lang-file-name=products --translation-for=en,pl and translations should get created.

If you want me to evaluate your fields file to ensure it was created correctly, please post the content of your products.json file here. However, if you want to re-create everything using one command run the following command php artisan create:resources Product --translation-for=en,pl --table-exists --force

The above command will do the following 1) Creates a file named products.json with all the fields from your products table. (if your table is not names products you can use the --table-name= option to specify a different name. 2) It'll use the products.json file to create the following a) controller b) model c) language files d) views

Note, the above command uses --force it WILL override all your exists file including your products.json file. It will override any customization that you already did to your existing products.json file.

PS: I like to always create my resources with --with-form-request to keep my controllers clean. But of course that is personal preference.

Also, when you are creating resources from existing database, the new section common_definitions in the config file is extremely useful to instruct the generator on how to generate your fields by default (which will save you tons of time!)

Let me know if I can be of any additional help.

qcol commented 7 years ago

Wow, after php artisan create:resources Product --translation-for=en,pl --table-exists --force it works now! Maybe I should read docs again line by line :) Thank You! I keep my fingers crossed for further development of this great tool.

MikeAlhayek commented 7 years ago

Glad it worked for you.

We are striving to deliver website with almost 0 effort in creating resources, so if a new idea comes to mind, please do not hesitate to share :)

Here is one more helpful too in in v2.1.0 which will allow you create resources for your entire database from one command.

Create a new file called resources_map.json in that file add the following json (list all the tables)

[
    {
        "model-name": "Product",
        "fields-file": "products.json",
        "table-name": "productsBlahTable"
    },
    {
        "model-name": "ProductGroup",
        "fields-file": "product_groups.json" // "table-name" is not needed assuming the table is named product_groups
    }
]

Once your done mapping for your tables, run the following command php artisan create:resources mapping-file=resources_map.json --translation-for=en,pl --table-exists --force

Good luck!

qcol commented 7 years ago

Looks great!

For now only one suggestion... It would be nice to use translations not only for form labels but for other generated items too (placeholders, headers) .

MikeAlhayek commented 7 years ago

That is the remaining 2% that I mentioned above....which is by they way almost ready :)

MikeAlhayek commented 7 years ago

v2.1.0 is finally out! Feel free to upgrade to it and try it out. It is yet the most robust version out. Full improved documentation can be found at https://crestapps.com/laravel-code-generator/docs/2.1