diff --git a/config/language-manager.php b/config/language-manager.php index 22effde..1ae6ba5 100644 --- a/config/language-manager.php +++ b/config/language-manager.php @@ -25,4 +25,7 @@ // Display source column // Adds a column to the language lines table to show the source, either database or file 'display_source' => false, + + // If you have Editable Columns addon, Backpack will use it in the translations table. + 'useEditableColumns' => true, ]; diff --git a/license.md b/license.md index de6ba3f..8d116f8 100644 --- a/license.md +++ b/license.md @@ -1,21 +1,61 @@ -# The MIT License (MIT) - -Copyright (c) Cristian Tabacitu - -> Permission is hereby granted, free of charge, to any person obtaining a copy -> of this software and associated documentation files (the "Software"), to deal -> in the Software without restriction, including without limitation the rights -> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -> copies of the Software, and to permit persons to whom the Software is -> furnished to do so, subject to the following conditions: -> -> The above copyright notice and this permission notice shall be included in -> all copies or substantial portions of the Software. -> -> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -> THE SOFTWARE. +## End-User License Agreement (EULA) of Private Backpack Addons + +This End-User License Agreement ("EULA") is a legal agreement between you and COMPLEMENT SOFTWARE SRL, registered in Romania, Calea Victoriei 142-148, postal code 010095, unique fiscal number RO35962660, registration number J 40/5536/2016. + +This EULA agreement governs your acquisition and use of our Private Backpack Addons software ("Software") directly from Complement Software SRL or indirectly through a Complement Software SRL authorized reseller or distributor (a "Reseller"). + +Please read this EULA agreement carefully before completing the installation process and using the Private Backpack Addons software. It provides a license to use the Private Backpack Addons and contains warranty information and liability disclaimers. + +If you register for a free trial of any Private Backpack Addons software, this EULA agreement will also govern that trial. By clicking "accept" or installing and/or using the Private Backpack Addons software, you are confirming your acceptance of the Software and agreeing to become bound by the terms of this EULA agreement. + +If you are entering into this EULA agreement on behalf of a company or other legal entity, you represent that you have the authority to bind such entity and its affiliates to these terms and conditions. If you do not have such authority or if you do not agree with the terms and conditions of this EULA agreement, do not install or use the Software, and you must not accept this EULA agreement. + +This EULA agreement shall apply only to the Software supplied by Complement Software SRL herewith regardless of whether other software is referred to or described herein. The terms also apply to any Complement Software SRL updates, supplements, Internet-based services, and support services for the Software, unless other terms accompany those items on delivery. If so, those terms apply. + +### License Grant + +Complement Software SRL hereby grants you: + +* access to download the source code for the Private Backpack Addons you have purchased, and all updates released during a period of 12 months after the purchase; +* a personal, non-transferable, non-exclusive licence to use the source code and updates of the Private Backpack Addons you have purchased, in accordance with the terms of this EULA agreement; + +For the Private Backpack Addons you have purchased, **you are permitted for both commercial and non-commercial purposes to:** + +* **Install and use the software on your local or networked device under your direct control (yourself or your company) or indirect control (a client or collaborator);** +* **Install and use the software for as many projects or devices as you please, as long as those projects are developed by or for the organization that has made the purchase;** +* Report issues and improvement ideas for the software through the channels put at your disposal, thereby granting ownership of those ideas to Complement Software SRL; +* Propose changes for the software, thereby granting complete ownership of the changes you've made to Complement Software SRL; + +As long as it not done in a way that would compete with the Software you purchased or have a negative impact on our product sales, you are also allowed to: + +* Edit, alter, modify, adapt, translate and otherwise change the whole or any part of the Software; +* Permit the whole or any part of the Software to be combined with or become incorporated in other software, decompile, disassemble or reverse engineer the Software; +* Allow third parties to use the Software on your behalf, or for the benefit of your company; + +You are not permitted to: + +* Make the source code public; +* Reproduce, copy, distribute, resell or otherwise use the Software for the purpose or with the result of creating competition to the Software you purchased, or have a negative impact on our product sales; +* Use the Software in any way which breaches any applicable local, national or international law; +* Use the Software for any purpose that Complement Software SRL considers is a breach of this EULA agreement; +* Download further updates for the Software, that were released outside the 12-month-after-purchase period, unless a new license is purchased, which will extend your update period by another 12 months; + +### Intellectual Property and Ownership + +Complement Software SRL shall at all times retain ownership of the Software as originally downloaded by you and all subsequent downloads of the Software by you. The Software (and the copyright, and other intellectual property rights of whatever nature in the Software, including any modifications made thereto) are and shall remain the property of Complement Software SRL. + +Complement Software SRL reserves the right to grant licences to use the Software to third parties. + +### Termination + +This EULA agreement is effective from the date you first use the Software and shall continue until terminated. You may terminate it at any time upon written notice to Complement Software SRL. + +It will also terminate immediately if you fail to comply with any term of this EULA agreement. Upon such termination, the licenses granted by this EULA agreement will immediately terminate and you agree to stop all access and use of the Software. The provisions that by their nature continue and survive will survive any termination of this EULA agreement. + +### Governing Law + +This EULA agreement, and any dispute arising out of or in connection with this EULA agreement, shall be governed by and construed in accordance with the laws of Romania and the European Union. + +--- + +This license was created using the [EULA Template Generator](https://www.eulatemplate.com). \ No newline at end of file diff --git a/readme.md b/readme.md index 9c7dd9a..7f65ce1 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,16 @@ # Language Manager -[![Latest Version on Packagist][ico-version]][link-packagist] [![Total Downloads][ico-downloads]][link-downloads] [![The Whole Fruit Manifesto](https://img.shields.io/badge/writing%20standard-the%20whole%20fruit-brightgreen)](https://github.com/the-whole-fruit/manifesto) -Language Manager provides a user interface for Backpack to manage translations. It allows you to: +Language Manager provides a simple user interface to help you deal with translations in your Backpack application. +At a quick glance, some of the most relevant features are: - View a list of all translations present in your application's language files (including vendor translations). -- Edit translations directly within the list. +- Edit translations directly from the interface. - Search and filter translations for easy management. -This package leverages the functionalities of `spatie/laravel-translation-loader` to Backpack for Laravel, providing a user interface to manage translations. +This package uses the battle tested [spatie/laravel-translation-loader](https://github.com/spatie/laravel-translation-loader) under the hood. ## Preview @@ -25,48 +25,43 @@ Try it right now, edit some translations in [our online demo](https://demo.backp In your Laravel + Backpack project, install this package: -1) Install the package using Composer: +**1) Install the package using Composer**: ```bash composer require backpack/language-manager ``` -2) Add menu items to `sidebar_content.blade.php`: +**2) Configure the application** -```bash -php artisan backpack:add-menu-content "" -``` +If you already had [spatie/laravel-translation-loader](https://github.com/spatie/laravel-translation-loader) installed and configured, you can skip to next step. Otherwise, follow along. -3) Optionally, publish the config file: + In you application `config/app.php` you must replace Laravel's translation service provider: -```bash -php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="config" +```diff +-Illuminate\Translation\TranslationServiceProvider::class, ++Spatie\TranslationLoader\TranslationServiceProvider::class, ``` -4) But also, if your package didn't already have [`spatie/laravel-translation-loader`](https://github.com/spatie/laravel-translation-loader) installed and set up, please [follow the installation steps in their docs](https://github.com/spatie/laravel-translation-loader#installation). We'll also copy-paste them here, for your convenience: - - - 4.1) In `config/app.php` you should replace Laravel's translation service provider +You must publish and run the migrations to create the `language_lines` table: +```bash +php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="migrations" && php artisan migrate +``` - ```diff - -Illuminate\Translation\TranslationServiceProvider::class, - +Spatie\TranslationLoader\TranslationServiceProvider::class, - ``` +**3) Optional setup options** - 4.2) You must publish and run the migrations to create the `language_lines` table: +3.1) Add a menu item to `menu_items.blade.php` for easy access: - ```bash - php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="migrations" - php artisan migrate - ``` +```bash +php artisan backpack:add-menu-content "" +``` - 4.3) Optionally you could publish the config file using this command. +3.2) Publish the config files: - ```bash - php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="config" - ``` +```bash +php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="config" && php artisan vendor:publish --provider="Backpack\LanguageManager\AddonServiceProvider" --tag="config" +``` -5) We highly recommend you to use this package allong with the [Language Switcher](https://github.com/Laravel-Backpack/language-switcher) package, so you can easily switch between languages in your panel. +**NOTE:** We highly recommend you to use this package alongside [Language Switcher](https://github.com/Laravel-Backpack/language-switcher) package, so that you can easily switch between languages in your panel. ## Usage @@ -79,7 +74,10 @@ All translations including vendor translations are displayed in the list view, i ### Editing Translations: -You can directly edit translations within the list view itself if you have the [Editable Columns](https://backpackforlaravel.com/products/editable-columns) package. +You can directly edit translations within the list itself if you have the [Editable Columns](https://backpackforlaravel.com/products/editable-columns) package. +If you don't want that behavior you can disable it in the `config/backpack/language-manager.php` file by setting `useEditableColumns => false`. +If you don't find that file, see above the optional steps to publish the config files. + Once edited, the changes are saved to the database for persistence. All translations on the database have priority over the ones in the language files. ## Security @@ -94,11 +92,10 @@ If you discover any security related issues, please email cristian.tabacitu@back ## License -This project was released under MIT License, so you can install it on top of any Backpack & Laravel project. Please see the [license file](license.md) for more information. +This project was released under EULA, so you can install it on top of any Backpack & Laravel project. Please see the [license file](https://backpackforlaravel.com/products/calendar-operation/license.md) for more information. [ico-version]: https://img.shields.io/packagist/v/backpack/language-manager.svg?style=flat-square -[ico-downloads]: https://img.shields.io/packagist/dt/backpack/language-manager.svg?style=flat-square +[ico-download]: https://img.shields.io/packagist/dt/backpack/language-manager.svg?style=flat-square -[link-packagist]: https://packagist.org/packages/backpack/language-manager -[link-downloads]: https://packagist.org/packages/backpack/language-manager +[link-author]: https://github.com/laravel-backpack [link-contributors]: ../../contributors diff --git a/src/Http/Controllers/LanguageManagerCrudController.php b/src/Http/Controllers/LanguageManagerCrudController.php index fd186f7..7813854 100644 --- a/src/Http/Controllers/LanguageManagerCrudController.php +++ b/src/Http/Controllers/LanguageManagerCrudController.php @@ -5,7 +5,6 @@ use Backpack\CRUD\app\Http\Controllers\CrudController; use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; use Backpack\LanguageManager\Models\LanguageLine; -use Backpack\LanguageManager\Models\LanguageLineOriginal; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Facades\App; use Illuminate\Support\Str; @@ -21,10 +20,7 @@ class LanguageManagerCrudController extends CrudController use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; - use \Backpack\LanguageManager\Http\Operations\MinorUpdateOperation; - - private $minorUpdateEntry = null; - private $minorUpdateRequest = null; + use \Backpack\LanguageManager\Http\Operations\CanUseEditableColumns; /** * Setup @@ -195,43 +191,4 @@ public function setupFilters(): void CRUD::addClause('where', 'database', $option === 'database'); }); } - - /** - * Override the parent method to customize the saving - */ - public function saveMinorUpdateEntry() - { - $entry = $this->minorUpdateEntry; - $request = $this->minorUpdateRequest; - $locale = App::getLocale(); - - // update - if ($entry->id_database) { - $text = $entry->text; - $text[$locale] = $request->value; - - $entry = LanguageLineOriginal::find($entry->id_database); - $entry->text = $text; - $entry->save(); - } - - // create - else { - [$group, $key] = explode('.', $request->id); - - LanguageLineOriginal::create([ - 'group' => $group, - 'key' => $key, - 'text' => [ - $locale => $request->value, - ], - ]); - } - - // fetch the entry from sushi - $entry = LanguageLine::find($request->id); - $entry->database = true; - - return $entry; - } } diff --git a/src/Http/Operations/CanUseEditableColumns.php b/src/Http/Operations/CanUseEditableColumns.php new file mode 100644 index 0000000..4ad0f84 --- /dev/null +++ b/src/Http/Operations/CanUseEditableColumns.php @@ -0,0 +1,67 @@ +minorUpdateEntry; + $request = $this->minorUpdateRequest; + $locale = App::getLocale(); + + // update + if ($entry->id_database) { + $text = $entry->text; + $text[$locale] = $request->value; + + $entry = LanguageLineOriginal::find($entry->id_database); + $entry->text = $text; + $entry->save(); + } else { + [$group, $key] = explode('.', $request->id); + + LanguageLineOriginal::create([ + 'group' => $group, + 'key' => $key, + 'text' => [ + $locale => $request->value, + ], + ]); + } + + // fetch the entry from sushi + $entry = LanguageLine::find($request->id); + $entry->database = true; + + return $entry; + } + } +} else { + trait CanUseEditableColumns + { + private function editableColumnsEnabled(): bool + { + return false; + } + } +} diff --git a/src/Http/Operations/MinorUpdateOperation.php b/src/Http/Operations/MinorUpdateOperation.php deleted file mode 100644 index 7ffbebb..0000000 --- a/src/Http/Operations/MinorUpdateOperation.php +++ /dev/null @@ -1,23 +0,0 @@ -