├── .styleci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── config └── config.php ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── larabels.css └── mix-manifest.json ├── resources ├── sass │ ├── _tailwind.scss │ └── app.scss └── views │ ├── app.blade.php │ ├── components │ └── card.blade.php │ ├── home.blade.php │ ├── layouts │ └── app.blade.php │ └── partials │ ├── action_buttons.blade.php │ ├── alert_error.blade.php │ ├── alert_success.blade.php │ ├── container.blade.php │ ├── label.blade.php │ └── locale_button.blade.php ├── src ├── AuthorizesRequests.php ├── Console │ ├── InstallCommand.php │ └── PublishCommand.php ├── Domain │ ├── Container.php │ ├── GitRepository.php │ └── Label.php ├── Http │ ├── Controllers │ │ ├── CommitController.php │ │ ├── LabelsController.php │ │ └── ResetController.php │ ├── Middleware │ │ └── Authorize.php │ └── routes.php ├── Larabels.php ├── LarabelsApplicationServiceProvider.php ├── LarabelsFacade.php └── LarabelsServiceProvider.php ├── stubs └── LarabelsServiceProvider.stub ├── tailwind.config.js └── webpack.mix.js /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - single_class_element_per_statement 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/super-dev03/laravel-test/8f7e8056d192407f4b2381558ddd14db2fe94ba4/CHANGELOG.md -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Alexandru Stratulat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 |

3 | 🌍 Larabels - Laravel localization labels dashboard 🌏 4 |

5 |

6 | 7 | 8 | 9 | 10 | 11 |

12 | 13 | ## About 14 | Larabels is an editor for your Laravel localization files. 15 | 16 | The main purpose of this package is to allow non-technical 17 | people commit label updates directly to the repository in development environments. 18 | It automatically parses all languages by folders from `resources/lang` and all localization files from each language. 19 | 20 | Larabels is built to work exclusively with Git. 21 | As you've might seen in the screenshot above, we've got 3 buttons fixed to the bottom of screen: 22 | 23 | `Save` - all labels from all languages will be exported to `resources/lang`. 24 | 25 | `Reset` - all the changes exported to `resources/lang` are reverted to original state. 26 | 27 | `Commit & Push` - all the changes are commited and pushed to `origin HEAD`. 28 | 29 | Note: you (or the server) must have passwordless push access to the repository. 30 | 31 | ## Installation 32 | 33 | ```shell 34 | composer require sandulat/larabels 35 | php artisan larabels:install 36 | ``` 37 | The last command will publish Larabel's service provider, config and public front-end assets. 38 | 39 | Note: to re-publish the front-end assets when updating the package use: `php artisan larabels:publish` 40 | 41 | ## Authorization 42 | By default Larabels will be accessible by anyone in a local environment only. However it provides a customizable gate that 43 | limits access in production environments. See the `gate()` method inside the published `LarabelsServiceProvider`: 44 | 45 | ```php 46 | /** 47 | * Register the Larabels gate. 48 | * 49 | * This gate determines who can access Larabels in non-local environments. 50 | * 51 | * @return void 52 | */ 53 | protected function gate() 54 | { 55 | Gate::define('viewLarabels', function ($user) { 56 | return in_array($user->email, [ 57 | // 58 | ]); 59 | }); 60 | } 61 | ``` 62 | 63 | ## Configuration 64 | Larabels works without any additional configuration, however it provides a config (`config/larabels.php`) with these options: 65 | 66 | |Option|Default Value|Description| 67 | |------|-------------|-----------| 68 | |`enabled`|`env('LARABELS_ENABLED', true)`|This option may be used to disable Larabels direct route access. Note: Larabels views will ignore this option so you can include them in your project.| 69 | |`middleware`|`[\Sandulat\Larabels\Http\Middleware\Authorize::class]`|These middlewares will be assigned to every Larabels route. Note that in any case Larabels routes implicitly belong to the "web" middleware.| 70 | |`whitelist`|`[]`|This value determines which localization files should be included in the dashboard. Files will be loaded from `/resources/lang/{locale}`. Use file names without extension: `auth`, `pagination`, `validation`, `passwords`, etc. Leave empty to load all files.| 71 | |`path`|`/larabels`|This value determines the base route path where the dashboard will be accessible from.| 72 | 73 | ## Customization 74 | If you would like to include the Larabels editor view directly into your personal dashboard, set the environment option `LARABELS_ENABLED` to `false` to disable direct access to the Larabels route. Now add `@include('larabels::app')` wherever you'd like. 75 | 76 | Larabels is splitted into partials so you can easily cutomize the look. Inside the path `resources/views` create the folder `vendor/larabels`. 77 | 78 | Now you can override the default Larabels views: 79 | - `components/card.blade.php` 80 | - `partials/action_buttons.blade.php` 81 | - `partials/container.blade.php` 82 | - `partials/label.blade.php` 83 | - `partials/locale_button.blade.php` 84 | 85 | ## Credits 86 | 87 | Created by [Stratulat Alexandru](https://twitter.com/sandulat). 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sandulat/larabels", 3 | "description": "Laravel localization labels dashboard", 4 | "keywords": [ 5 | "sandulat", 6 | "larabels", 7 | "laravel", 8 | "labels", 9 | "localization" 10 | ], 11 | "homepage": "https://github.com/sandulat/larabels", 12 | "license": "MIT", 13 | "type": "library", 14 | "authors": [ 15 | { 16 | "name": "Alexandru Stratulat", 17 | "email": "alexanderstratulat97@gmail.com", 18 | "role": "Developer" 19 | } 20 | ], 21 | "require": { 22 | "php": "^7.1", 23 | "czproject/git-php": "^3.17", 24 | "illuminate/support": "5.8.*", 25 | "laravel/framework": "~5.8.0|~5.9.0", 26 | "zendframework/zend-code": "^3.3" 27 | }, 28 | "require-dev": { 29 | "orchestra/testbench": "3.8.*", 30 | "phpunit/phpunit": "^7.0" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Sandulat\\Larabels\\": "src" 35 | } 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Sandulat\\Larabels\\Tests\\": "tests" 40 | } 41 | }, 42 | "scripts": { 43 | "test": "vendor/bin/phpunit", 44 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 45 | }, 46 | "config": { 47 | "sort-packages": true 48 | }, 49 | "extra": { 50 | "laravel": { 51 | "providers": [ 52 | "Sandulat\\Larabels\\LarabelsServiceProvider" 53 | ], 54 | "aliases": { 55 | "Larabels": "Sandulat\\Larabels\\LarabelsFacade" 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /config/config.php: -------------------------------------------------------------------------------- 1 | env('LARABELS_ENABLED', true), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Larabels Route Middleware 23 | |-------------------------------------------------------------------------- 24 | | 25 | | These middlewares will be assigned to every Larabels route. Note that 26 | | in any case Larabels routes implicitly belong to the "web" middleware. 27 | | 28 | */ 29 | 30 | 'middleware' => [ 31 | Authorize::class, 32 | ], 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Localization Files Whitelist 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This value determines which localization files should be included in the 40 | | dashboard. Files will be loaded from "/resources/lang/{locale}". Use 41 | | file names without extension: "auth", "pagination", "validation", 42 | | "passwords", etc. Leave empty to load all files. 43 | | 44 | */ 45 | 46 | 'whitelist' => [], 47 | 48 | /* 49 | |-------------------------------------------------------------------------- 50 | | Dashboard path 51 | |-------------------------------------------------------------------------- 52 | | 53 | | This value determines the base route path where the dashboard will be 54 | | accessible from. 55 | | 56 | */ 57 | 58 | 'path' => '/larabels', 59 | 60 | ]; 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "npm run development -- --watch", 7 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 8 | "prod": "npm run production", 9 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 10 | }, 11 | "devDependencies": { 12 | "cross-env": "^5.2.0", 13 | "laravel-mix": "^4.0.15", 14 | "laravel-mix-purgecss": "^4.1.0", 15 | "sass": "^1.20.1", 16 | "sass-loader": "^7.1.0", 17 | "tailwindcss": "^1.0.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/super-dev03/laravel-test/8f7e8056d192407f4b2381558ddd14db2fe94ba4/public/favicon.ico -------------------------------------------------------------------------------- /public/larabels.css: -------------------------------------------------------------------------------- 1 | /*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}a{background-color:transparent}strong{font-weight:bolder}sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;top:-.5em}button,input{font-family:inherit;font-size:100%;line-height:1.15;margin:0;overflow:visible}button{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}legend{color:inherit;display:table;max-width:100%;white-space:normal}[type=checkbox],[type=radio],legend{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}[hidden]{display:none}html{box-sizing:border-box;font-family:sans-serif}*,:after,:before{box-sizing:inherit}button{background:transparent;padding:0}button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}ul{list-style:none;margin:0;padding:0}html{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;line-height:1.5}*,:after,:before{border:0 solid #e2e8f0}input::-webkit-input-placeholder{color:inherit;opacity:.5}input::-moz-placeholder{color:inherit;opacity:.5}input:-ms-input-placeholder{color:inherit;opacity:.5}input::-ms-input-placeholder{color:inherit;opacity:.5}input::placeholder{color:inherit;opacity:.5}[role=button],button{cursor:pointer}a{color:inherit;text-decoration:inherit}button,input{padding:0;line-height:inherit;color:inherit}canvas{display:block;vertical-align:middle}.larabels-container{width:100%}@media (min-width:640px){.larabels-container{max-width:640px}}@media (min-width:768px){.larabels-container{max-width:768px}}@media (min-width:1024px){.larabels-container{max-width:1024px}}@media (min-width:1280px){.larabels-container{max-width:1280px}}.larabels-bg-white{background-color:#fff}.larabels-bg-gray-100{background-color:#f7fafc}.larabels-bg-gray-300{background-color:#e2e8f0}.larabels-bg-gray-500{background-color:#a0aec0}.larabels-bg-gray-700{background-color:#4a5568}.larabels-bg-green-200{background-color:#c6f6d5}.larabels-bg-indigo-200{background-color:#c3dafe}.larabels-bg-indigo-700{background-color:#4c51bf}.larabels-bg-pink-200{background-color:#fed7e2}.larabels-border-gray-400{border-color:#cbd5e0}.larabels-border-gray-500{border-color:#a0aec0}.larabels-border-gray-700{border-color:#4a5568}.larabels-border-green-400{border-color:#68d391}.larabels-border-indigo-400{border-color:#7f9cf5}.larabels-border-pink-400{border-color:#f687b3}.larabels-rounded{border-radius:.25rem}.larabels-border{border-width:1px}.larabels-border-b{border-bottom-width:1px}.larabels-inline-block{display:inline-block}.larabels-flex{display:-webkit-box;display:flex}.larabels-hidden{display:none}.larabels-flex-col{-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column}.larabels-flex-wrap{flex-wrap:wrap}.larabels-items-center{-webkit-box-align:center;align-items:center}.larabels-justify-between{-webkit-box-pack:justify;justify-content:space-between}.larabels-flex-grow{-webkit-box-flex:1;flex-grow:1}.larabels-font-sans{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.larabels-font-medium{font-weight:500}.larabels-h-full{height:100%}.larabels-my-8{margin-top:2rem;margin-bottom:2rem}.larabels-mx-auto{margin-left:auto;margin-right:auto}.larabels--mx-3{margin-left:-.75rem;margin-right:-.75rem}.larabels-mb-0{margin-bottom:0}.larabels-mr-1{margin-right:.25rem}.larabels-mt-2{margin-top:.5rem}.larabels-mb-2{margin-bottom:.5rem}.larabels-ml-2{margin-left:.5rem}.larabels-mt-3{margin-top:.75rem}.larabels-mr-3{margin-right:.75rem}.larabels-mb-4{margin-bottom:1rem}.larabels-mb-6{margin-bottom:1.5rem}.larabels-ml-8{margin-left:2rem}.larabels-overflow-hidden{overflow:hidden}.larabels-overflow-x-auto{overflow-x:auto}.larabels-p-1{padding:.25rem}.larabels-p-4{padding:1rem}.larabels-py-1{padding-top:.25rem;padding-bottom:.25rem}.larabels-px-1{padding-left:.25rem;padding-right:.25rem}.larabels-px-2{padding-left:.5rem;padding-right:.5rem}.larabels-px-3{padding-left:.75rem;padding-right:.75rem}.larabels-py-4{padding-top:1rem;padding-bottom:1rem}.larabels-py-5{padding-top:1.25rem;padding-bottom:1.25rem}.larabels-px-5{padding-left:1.25rem;padding-right:1.25rem}.larabels-pb-10{padding-bottom:2.5rem}.larabels-relative{position:relative}.larabels-left-0{left:0}.larabels-shadow{box-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px 0 rgba(0,0,0,.06)}.larabels-text-center{text-align:center}.larabels-text-white{color:#fff}.larabels-text-gray-700{color:#4a5568}.larabels-text-gray-800{color:#2d3748}.larabels-text-green-900{color:#22543d}.larabels-text-indigo-700{color:#4c51bf}.larabels-text-indigo-900{color:#3c366b}.larabels-text-pink-900{color:#702459}.larabels-text-xs{font-size:.75rem}.larabels-text-sm{font-size:.875rem}.larabels-uppercase{text-transform:uppercase}.larabels-capitalize{text-transform:capitalize}.larabels-tracking-wider{letter-spacing:.05em}.larabels-tracking-widest{letter-spacing:.1em}.larabels-w-auto{width:auto}.larabels-w-full{width:100%}.larabels-btn{border-radius:.25rem;border-width:1px;font-size:.875rem;padding:.5rem;text-transform:uppercase;font-weight:500}@media (min-width:768px){.larabels-btn{padding-left:2.5rem;padding-right:2.5rem}}@media (min-width:768px){.md\:larabels-flex-row{-webkit-box-orient:horizontal;-webkit-box-direction:normal;flex-direction:row}.md\:larabels-px-0{padding-left:0;padding-right:0}} -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/larabels.css": "/larabels.css?id=c01488e2f5df1e15a847" 3 | } 4 | -------------------------------------------------------------------------------- /resources/sass/_tailwind.scss: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /resources/sass/app.scss: -------------------------------------------------------------------------------- 1 | @import 'tailwind'; 2 | 3 | .larabels-btn { 4 | @apply larabels-rounded larabels-border larabels-text-sm larabels-px-2 larabels-py-2 larabels-uppercase larabels-font-medium; 5 | 6 | @screen md { 7 | @apply larabels-px-10; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /resources/views/app.blade.php: -------------------------------------------------------------------------------- 1 | @inject('larabels', 'Sandulat\Larabels\Larabels') 2 | 3 | 4 |

5 |
6 | @csrf 7 | @method('put') 8 | @foreach($larabels->labels()->keys() as $locale) 9 | @include('larabels::partials.locale_button') 10 | @endforeach 11 | @foreach($larabels->labels() as $locale => $files) 12 |
13 | @foreach($files as $file => $items) 14 |
15 | @component('larabels::components.card', ['title' => $file]) 16 |
    17 | @foreach ($items as $item) 18 | @if ($item instanceof \Sandulat\Larabels\Domain\Label) 19 | @include('larabels::partials.label', ['label' => $item]) 20 | @elseif($item instanceof \Sandulat\Larabels\Domain\Container) 21 | @include('larabels::partials.container', ['container' => $item]) 22 | @endif 23 | @endforeach 24 |
25 | @endcomponent 26 |
27 | @endforeach 28 |
29 | @endforeach 30 |
31 | @include('larabels::partials.action_buttons') 32 |
33 | -------------------------------------------------------------------------------- /resources/views/components/card.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
5 | {{ $title }} 6 |
7 | 8 |
9 | {{ $slot }} 10 |
11 |
12 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('larabels::layouts.app') 2 | 3 | @section('content') 4 | @include('larabels::app') 5 | @endsection 6 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {{ config('app.name', 'Larabels') }} - Labels Dashboard 7 | 8 | 9 | 10 | 14 |
15 | @if (session()->has('success')) 16 | @include('larabels::partials.alert_success', ['message' => session()->get('success')]) 17 | @endif 18 | @if (session()->has('error')) 19 | @include('larabels::partials.alert_error', ['message' => session()->get('error')]) 20 | @endif 21 | @yield('content') 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /resources/views/partials/action_buttons.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 6 | @if ($larabels->labelsHaveChanges()) 7 |
8 | @csrf 9 | 12 |
13 |
14 | @csrf 15 | 18 |
19 | @endif 20 |
21 |
22 | -------------------------------------------------------------------------------- /resources/views/partials/alert_error.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{ $message }} 4 |
5 |
6 | -------------------------------------------------------------------------------- /resources/views/partials/alert_success.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{ $message }} 4 |
5 |
6 | -------------------------------------------------------------------------------- /resources/views/partials/container.blade.php: -------------------------------------------------------------------------------- 1 |
  • 2 | {{ $container->key() }} 3 | @if(! empty($container->labels())) 4 | 9 | @endif 10 | @if(! empty($container->containers())) 11 | 16 | @endif 17 |
  • 18 | -------------------------------------------------------------------------------- /resources/views/partials/label.blade.php: -------------------------------------------------------------------------------- 1 |
  • 2 | {{ $label->key() }} 3 | 4 |
  • 5 | -------------------------------------------------------------------------------- /resources/views/partials/locale_button.blade.php: -------------------------------------------------------------------------------- 1 | 18 | -------------------------------------------------------------------------------- /src/AuthorizesRequests.php: -------------------------------------------------------------------------------- 1 | environment('local'); 45 | })($request); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Console/InstallCommand.php: -------------------------------------------------------------------------------- 1 | comment('Publishing Larabels Service Provider...'); 40 | $this->callSilent('vendor:publish', ['--tag' => 'larabels-provider']); 41 | 42 | $this->comment('Publishing Larabels Assets...'); 43 | $this->callSilent('vendor:publish', ['--tag' => 'larabels-assets']); 44 | 45 | $this->comment('Publishing Larabels Configuration...'); 46 | $this->callSilent('vendor:publish', ['--tag' => 'larabels-config']); 47 | 48 | $this->registerLarabelsServiceProvider(); 49 | 50 | $this->info('Larabels scaffolding installed successfully.'); 51 | } 52 | 53 | /** 54 | * Register the Larabels service provider in the application configuration file. 55 | * 56 | * @return void 57 | */ 58 | protected function registerLarabelsServiceProvider(): void 59 | { 60 | $namespace = str_replace_last('\\', '', $this->getAppNamespace()); 61 | 62 | $appConfig = file_get_contents(config_path('app.php')); 63 | 64 | if (Str::contains($appConfig, $namespace.'\\Providers\\LarabelsServiceProvider::class')) { 65 | return; 66 | } 67 | 68 | $lineEndingCount = [ 69 | "\r\n" => substr_count($appConfig, "\r\n"), 70 | "\r" => substr_count($appConfig, "\r"), 71 | "\n" => substr_count($appConfig, "\n"), 72 | ]; 73 | 74 | $eol = array_keys($lineEndingCount, max($lineEndingCount))[0]; 75 | 76 | file_put_contents(config_path('app.php'), str_replace( 77 | "{$namespace}\\Providers\EventServiceProvider::class,".$eol, 78 | "{$namespace}\\Providers\EventServiceProvider::class,".$eol." {$namespace}\Providers\LarabelsServiceProvider::class,".$eol, 79 | $appConfig 80 | )); 81 | 82 | file_put_contents(app_path('Providers/LarabelsServiceProvider.php'), str_replace( 83 | "namespace App\Providers;", 84 | "namespace {$namespace}\Providers;", 85 | file_get_contents(app_path('Providers/LarabelsServiceProvider.php')) 86 | )); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Console/PublishCommand.php: -------------------------------------------------------------------------------- 1 | call('vendor:publish', [ 36 | '--tag' => 'larabels-config', 37 | '--force' => $this->option('force'), 38 | ]); 39 | 40 | $this->call('vendor:publish', [ 41 | '--tag' => 'larabels-assets', 42 | '--force' => true, 43 | ]); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Domain/Container.php: -------------------------------------------------------------------------------- 1 | key = $key; 49 | 50 | $this->slug = $parentSlug ? $parentSlug.'.'.$key : $key; 51 | 52 | $this->parseData($data); 53 | } 54 | 55 | /** 56 | * Prases labels & containers. 57 | * 58 | * @param array $data 59 | * @return void 60 | */ 61 | public function parseData(array $data): void 62 | { 63 | $collection = new Collection($data); 64 | 65 | $this->labels = $collection->filter(static function ($item) { 66 | return is_string($item); 67 | })->map(function ($item, $key) { 68 | return new Label($item, $key, $this->slug); 69 | }); 70 | 71 | $this->containers = $collection->filter(static function ($item) { 72 | return is_array($item); 73 | })->map(function ($item, $key) { 74 | return new self($item, $key, $this->slug); 75 | }); 76 | } 77 | 78 | /** 79 | * Returns labels collection. 80 | * 81 | * @return \Illuminate\Support\Collection 82 | */ 83 | public function labels(): Collection 84 | { 85 | return $this->labels; 86 | } 87 | 88 | /** 89 | * Returns containers collection. 90 | * 91 | * @return \Illuminate\Support\Collection 92 | */ 93 | public function containers(): Collection 94 | { 95 | return $this->containers; 96 | } 97 | 98 | /** 99 | * Returns container key. 100 | * 101 | * @return string 102 | */ 103 | public function key(): string 104 | { 105 | return $this->key; 106 | } 107 | 108 | /** 109 | * Returns container slug. 110 | * 111 | * @return string 112 | */ 113 | public function slug(): string 114 | { 115 | return $this->slug; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Domain/GitRepository.php: -------------------------------------------------------------------------------- 1 | begin() 21 | ->run('git update-index -q --refresh') 22 | ->end(); 23 | 24 | $output = collect($this->extractFromCommand('git status --porcelain')); 25 | 26 | return $output->some(static function ($item) use ($path) { 27 | return Str::contains($item, $path); 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Domain/Label.php: -------------------------------------------------------------------------------- 1 | text = $label; 40 | 41 | $this->key = $key; 42 | 43 | $this->slug = $parentSlug ? $parentSlug.'.'.$key : $key; 44 | } 45 | 46 | /** 47 | * Returns label key. 48 | * 49 | * @return string 50 | */ 51 | public function key(): string 52 | { 53 | return $this->key; 54 | } 55 | 56 | /** 57 | * Returns label text. 58 | * 59 | * @return string 60 | */ 61 | public function text(): string 62 | { 63 | return $this->text; 64 | } 65 | 66 | /** 67 | * Returns label slug. 68 | * 69 | * @return string 70 | */ 71 | public function slug(): string 72 | { 73 | return $this->slug; 74 | } 75 | 76 | /** 77 | * Returns label slug formatted for frontend input. 78 | * 79 | * @return string 80 | */ 81 | public function slugForInput(): string 82 | { 83 | return collect(explode('.', $this->slug))->map(static function ($item, $key) { 84 | if ($key > 0) { 85 | return '['.$item.']'; 86 | } 87 | 88 | return $item; 89 | })->implode(''); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Http/Controllers/CommitController.php: -------------------------------------------------------------------------------- 1 | commit(); 24 | } catch (GitException $e) { 25 | return back()->with('error', $e->getMessage()); 26 | } 27 | 28 | return back()->with('success', __('Successfully committed and pushed.')); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Http/Controllers/LabelsController.php: -------------------------------------------------------------------------------- 1 | except(['_method', '_token']))->each( 36 | static function ($files, $locale) use ($larabels) { 37 | $larabels->exportLabels($locale, $files); 38 | } 39 | ); 40 | 41 | return back()->with('success', __('Successfully updated.')); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Http/Controllers/ResetController.php: -------------------------------------------------------------------------------- 1 | checkoutLabels(); 22 | 23 | return back()->with('success', __('Successfully reseted.')); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Http/Middleware/Authorize.php: -------------------------------------------------------------------------------- 1 | name('index'); 6 | Route::put('/', 'LabelsController@update')->name('update'); 7 | Route::post('/reset', 'ResetController')->name('reset'); 8 | Route::post('/commit', 'CommitController')->name('commit'); 9 | -------------------------------------------------------------------------------- /src/Larabels.php: -------------------------------------------------------------------------------- 1 | mapWithKeys( 53 | static function ($path) { 54 | $locale = static::lastDirectoryName($path); 55 | 56 | return [ 57 | $locale => static::files($path)->mapWithKeys( 58 | static function (SplFileInfo $file) use ($path, $locale) { 59 | return [ 60 | $file->getFilenameWithoutExtension() => static::fileLabels($file, $path, $locale), 61 | ]; 62 | } 63 | ), 64 | ]; 65 | } 66 | ); 67 | } 68 | 69 | /** 70 | * Returns all the directories from locales path. 71 | * 72 | * @return \Illuminate\Support\Collection 73 | */ 74 | private static function directories(): Collection 75 | { 76 | return collect((new Filesystem)->directories(static::$localesPath)); 77 | } 78 | 79 | /** 80 | * Returns all the files from the given path. 81 | * 82 | * @param string $path 83 | * @return \Illuminate\Support\Collection 84 | */ 85 | private static function files(string $path): Collection 86 | { 87 | $files = collect((new Filesystem)->files($path)); 88 | 89 | $whitelist = config('larabels.whitelist'); 90 | 91 | if (! empty($whitelist)) { 92 | return $files->filter( 93 | static function (SplFileInfo $file) use ($whitelist) { 94 | return in_array($file->getFilenameWithoutExtension(), $whitelist); 95 | } 96 | ); 97 | } 98 | 99 | return $files; 100 | } 101 | 102 | /** 103 | * Returns all the files from the given path. 104 | * 105 | * @param \Symfony\Component\Finder\SplFileInfo $file 106 | * @param string $path 107 | * @param string $locale 108 | * @return \Illuminate\Support\Collection 109 | */ 110 | private static function fileLabels(SplFileInfo $file, string $path, string $locale): Collection 111 | { 112 | $items = include $path.'/'.$file->getFilename(); 113 | 114 | return (new Collection($items))->map( 115 | static function ($item, $key) use ($file, $locale) { 116 | $fileName = $locale.'.'.$file->getFilenameWithoutExtension(); 117 | 118 | if (is_string($item)) { 119 | return new Label($item, $key, $fileName); 120 | } 121 | 122 | return new Container($item, $key, $fileName); 123 | } 124 | ); 125 | } 126 | 127 | /** 128 | * Returns the last directory name from a path. 129 | * 130 | * @param string $path 131 | * @return string 132 | */ 133 | private static function lastDirectoryName(string $path): string 134 | { 135 | $directories = explode('/', $path); 136 | 137 | return end($directories); 138 | } 139 | 140 | /** 141 | * Exports locale labels. 142 | * 143 | * @param string $locale 144 | * @param array $files 145 | * @return void 146 | */ 147 | public function exportLabels(string $locale, array $files): void 148 | { 149 | collect($files)->each(static function ($labels, $file) use ($locale) { 150 | $exportPath = static::$localesPath.'/'.$locale.'/'.$file.'.php'; 151 | 152 | $exportFile = FileGenerator::fromArray([ 153 | 'body' => 'return '.(new ValueGenerator($labels))->generate().';'.PHP_EOL, 154 | ]); 155 | 156 | (new Filesystem)->put($exportPath, $exportFile->generate()); 157 | }); 158 | } 159 | 160 | /** 161 | * Check if labels where changed. 162 | * 163 | * @param string $locale 164 | * @param array $files 165 | * @return void 166 | */ 167 | public function labelsHaveChanges(): bool 168 | { 169 | return static::$repository->pathHasChanges('resources/lang'); 170 | } 171 | 172 | /** 173 | * Checkout labels. 174 | * 175 | * @return \Sandulat\Larabels\Domain\GitRepository 176 | */ 177 | public function checkoutLabels(): GitRepository 178 | { 179 | return tap(static::$repository, static function (GitRepository $repository) { 180 | $repository->execute(['checkout', 'resources/lang']); 181 | 182 | $repository->execute(['reset', 'resources/lang']); 183 | }); 184 | } 185 | 186 | /** 187 | * Commit the changes. 188 | * 189 | * @return \Sandulat\Larabels\Domain\GitRepository 190 | */ 191 | public function commit(): GitRepository 192 | { 193 | if (! $this->labelsHaveChanges()) { 194 | return static::$repository; 195 | } 196 | 197 | return tap(static::$repository, static function (GitRepository $repository) { 198 | $repository->addFile('resources/lang'); 199 | 200 | $repository->commit(__('Updated labels.')); 201 | 202 | $repository->push('origin', ['HEAD']); 203 | }); 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/LarabelsApplicationServiceProvider.php: -------------------------------------------------------------------------------- 1 | authorization(); 18 | } 19 | 20 | /** 21 | * Configure the Larabels authorization services. 22 | * 23 | * @return void 24 | */ 25 | protected function authorization() 26 | { 27 | $this->gate(); 28 | 29 | Larabels::auth(function ($request) { 30 | return app()->environment('local') || 31 | Gate::check('viewLarabels', [$request->user()]); 32 | }); 33 | } 34 | 35 | /** 36 | * Register the Larabels gate. 37 | * 38 | * This gate determines who can access Larabels in non-local environments. 39 | * 40 | * @return void 41 | */ 42 | protected function gate() 43 | { 44 | Gate::define('viewLarabels', function ($user) { 45 | return in_array($user->email, [ 46 | // 47 | ]); 48 | }); 49 | } 50 | 51 | /** 52 | * Register any application services. 53 | * 54 | * @return void 55 | */ 56 | public function register() 57 | { 58 | // 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/LarabelsFacade.php: -------------------------------------------------------------------------------- 1 | registerRoutes(); 18 | 19 | $this->registerViews(); 20 | 21 | if ($this->app->runningInConsole()) { 22 | $this->publishes([ 23 | __DIR__.'/../config/config.php' => config_path('larabels.php'), 24 | ], 'larabels-config'); 25 | 26 | $this->publishes([ 27 | __DIR__.'/../public' => public_path('vendor/larabels'), 28 | ], 'larabels-assets'); 29 | 30 | $this->publishes([ 31 | __DIR__.'/../stubs/LarabelsServiceProvider.stub' => app_path('Providers/LarabelsServiceProvider.php'), 32 | ], 'larabels-provider'); 33 | } 34 | } 35 | 36 | /** 37 | * Register the application services. 38 | */ 39 | public function register(): void 40 | { 41 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'larabels'); 42 | 43 | $this->commands([ 44 | Console\InstallCommand::class, 45 | Console\PublishCommand::class, 46 | ]); 47 | 48 | $this->app->singleton('larabels', function () { 49 | return new Larabels; 50 | }); 51 | } 52 | 53 | /** 54 | * Register the package routes. 55 | * 56 | * @return void 57 | */ 58 | private function registerRoutes(): void 59 | { 60 | Route::group($this->routeConfiguration(), function () { 61 | $this->loadRoutesFrom(__DIR__.'/Http/routes.php'); 62 | }); 63 | } 64 | 65 | /** 66 | * Get the main route group configuration array. 67 | * 68 | * @return array 69 | */ 70 | private function routeConfiguration(): array 71 | { 72 | return [ 73 | 'namespace' => 'Sandulat\Larabels\Http\Controllers', 74 | 'prefix' => config('larabels.path'), 75 | 'middleware' => array_merge(['web'], config('larabels.middleware')), 76 | ]; 77 | } 78 | 79 | /** 80 | * Register the package views. 81 | * 82 | * @return array 83 | */ 84 | private function registerViews(): void 85 | { 86 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'larabels'); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /stubs/LarabelsServiceProvider.stub: -------------------------------------------------------------------------------- 1 | email, [ 21 | // 22 | ]); 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | theme: {}, 3 | variants: {}, 4 | plugins: [], 5 | prefix: 'larabels-', 6 | }; 7 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const mix = require('laravel-mix'); 3 | const webpack = require('webpack'); 4 | const tailwindcss = require('tailwindcss'); 5 | require('laravel-mix-purgecss'); 6 | 7 | /* 8 | |-------------------------------------------------------------------------- 9 | | Mix Asset Management 10 | |-------------------------------------------------------------------------- 11 | | 12 | | Mix provides a clean, fluent API for defining some Webpack build steps 13 | | for your Laravel application. By default, we are compiling the Sass 14 | | file for the application as well as bundling up all the JS files. 15 | | 16 | */ 17 | 18 | mix.options({ 19 | uglify: { 20 | uglifyOptions: { 21 | compress: { 22 | drop_console: true, 23 | }, 24 | }, 25 | }, 26 | }) 27 | .setPublicPath('public') 28 | .sass('resources/sass/app.scss', 'public/larabels.css') 29 | .options({ 30 | processCssUrls: false, 31 | postCss: [tailwindcss('./tailwind.config.js')], 32 | }) 33 | .version() 34 | .purgeCss(); 35 | --------------------------------------------------------------------------------