GithubHelp home page GithubHelp logo

gabsource / oc-scaffold-translation-plugin Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 7.0 72 KB

OctoberCMS plugin that overrides default scaffold commands to generate translation aware source files

License: MIT License

PHP 100.00%

oc-scaffold-translation-plugin's Introduction

Scaffold Translation Plugin

Purpose

This OctoberCMS plugin adds scaffold commands to generate translation aware source files.

Following php artisan commands are enhanced :

  • create:plugin:translated
  • create:controllers:translated
  • create:component:translated

Note: running those commands will rewrite and reformat existing plugin language files (ie. the returned PHP array).

Usage

php artisan create:plugin:translated Acme.Demo
php artisan create:controller:translated Acme.Demo Turtles
php artisan create:component:translated Acme.Demo TurtleList

Those commands will create the plugin, with a controller and a component. The new Acme.Demo plugin lang/en/lang.php will look like this :

<?php

return [
    'plugin' => [
        'name' => 'Demo',
        'description' => 'No description provided yet...',
    ],
    'turtle' => [
        'new' => 'New Turtle',
        'label' => 'Turtle',
        'create_title' => 'Create Turtle',
        'update_title' => 'Edit Turtle',
        'preview_title' => 'Preview Turtle',
        'list_title' => 'Manage Turtles',
    ],
    'turtles' => [
        'delete_selected_confirm' => 'Delete the selected turtles?',
        'menu_label' => 'Turtles',
        'return_to_list' => 'Return to Turtles',
        'delete_confirm' => 'Do you really want to delete this turtle?',
        'delete_selected_success' => 'Successfully deleted the selected turtles.',
        'delete_selected_empty' => 'There are no selected :name to delete.',
    ],
    'components' => [
        'turtlelist' => [
            'name' => 'TurtleList Component',
            'description' => 'No description provided yet...',
        ],
    ],
];

These keys are used in controller, component and plugin classes, views or YAML files.

Language files for en, config('app.locale') and config('app.fallback_locale') are generated.

The default values can be translated in other languages using the lang/xx/lang.php files of this plugin. If no default value is found, the key is used.

New commands available

Generate a widget stub

php artisan create:widget:translated Acme.Plugin FooWidget

Similar to create:formwidget, no translation here.

Find missing translation keys

php artisan plugin:translate Acme.Plugin

This new command will scan classes, components, models, controllers, widgets, formwidgets folders and Plugin.php files. It will detect missing translation key and add them to the lang/xx/lang.php files.

Warning: running those commands will rewrite and reformat existing language file returned array.

Manual installation

To manually install the plugin, get the sources archive from Github, uncompress the files in plugins/bnb/scaffoldtranslation folder and run this command at the root of OctoberCMS installation :

php artisan plugin:refresh BnB.ScaffoldTranslation

oc-scaffold-translation-plugin's People

Contributors

dougogodinho avatar gabsource avatar mr118 avatar tomaszstrojny avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

oc-scaffold-translation-plugin's Issues

Controller onDelete behavior

Hello,

Thank you for your awesome plugin. I've got a question though, can bring PR if you are willing.

Basically, you scaffold controller with delete button and onDelete method like this:

public function index_onDelete()
{
    if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
        foreach ($checkedIds as ${{lower_singular_model}}Id) {
            if (!${{lower_singular_model}} = {{model}}::find(${{lower_singular_model}}Id)) continue;
                ${{lower_singular_model}}->delete();
        }
    }
    (...)
}

and it does what should rarely be done: makes singular queries in loop, also loads whole model with find and does some non required checks. That makes it super slow, for 120 records at once I've got like 5 seconds deletion time.

My suggestion would be to use:

if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
  {{model}}::whereIn('id', $checkedIds)->delete();  
}

so results would be like

if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
  Model::whereIn('id', $checkedIds)->delete();
}

Rationale:

  • You do not really need to confirm that model exists and load it with find when you just want to delete it.
  • You do not need to spam database with queries when you want one operation to go and have array of ids.
  • There is HUGE speed difference:

Loop method for 120 records: 5116 ms (red on screenshot)
Wherein method for 120 records: 121ms (green on screenshot)

db

Let me know if you would be willing to accept PR for this?

Polish language support

Hi.
I use your plugin a lot so I've created an included a polish translation file. Hope you'll find this usefull.

pl.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.