多🌹444收拾收拾计算机视觉手机手机手机手机4大尺寸惆怅长岑长 ??????????????????????????С??????????????P??????????????????????????????????????????????????????^?????????? ????j?????????? ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!LICENSE000064400000002065152666150540005566 0ustar00MIT License Copyright (c) 2023 Mahmud Elseyyidömer 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. README.md000064400000004712152666150540006041 0ustar00# Laravel Json Localization Manager This is a package to manage json strings for Laravel 5.4 and higher Localization Translation Strings As Keys With MySQL. [Using Translation Strings As Keys][6ea2d96e] [6ea2d96e]: https://laravel.com/docs/5.4/localization#using-translation-strings-as-keys "Using Translation Strings As Keys" ## Composer require ``` bash $ composer require elseyyid/laravel-json-mysql-locations-manager ``` ## Add Provider into config/app.php ``` php Elseyyid\LaravelJsonLocationsManager\Providers\LaravelJsonLocationsManagerServiceProvider::class, ``` ### For Only local environment Add the following to the AppServiceProvider in the register function: #### app/Providers/AppServiceProvider.php ``` php if ($this->app->environment() == 'local' || $this->app->environment() == 'testing') { /* * Load third party local providers */ $this->app->register(\Elseyyid\LaravelJsonLocationsManager\Providers\LaravelJsonLocationsManagerServiceProvider::class); } ``` ## Package install Run in console this command ``` bash $ php artisan elseyyid:location:install ``` This command install database and will ask if you want to import the existing locations in the application. There are 2 questions, the first to import the strings in arrays and the second to import the existing strings into json files. This will pupulate the database with all strings. You don't need to run artisan migrate, this package uses an independent database (sqlite). ### Other Console Command You can publish all languages Json files in console running ``` bash $ php artisan elseyyid:location:publish ``` Of course you also can do that in browser views. ## Manage Locations Now you can access to /translations/home in your browser and manage all langs strings. - Search Language Strings - Add new Language - Add new Strings - Edit Strings - Publish / Update json Files ## Publish the views and config file ``` bash $ php artisan vendor:publish --provider='Elseyyid\LaravelJsonLocationsManager\Providers\LaravelJsonLocationsManagerServiceProvider' ``` ### In the config file you can call your custom layout, the content section and the scripts section (this is important for the edit views) and routes prefix and middlewares. ## Routes middlewares in config file you can add your middlewares, by default is only 'web' middleware ### Feel free to send improvements Created by [elseyyid][760a7857] [760a7857]: https://github.com/OmarElseyyid "https://github.com/OmarElseyyid" src/Controllers/HomeController.php000064400000011045152666150540013321 0ustar00files = $filesystem; } public function index() { if (Schema::hasTable('strings')) { $fields = \DB::getSchemaBuilder()->getColumnListing('strings'); } else { Artisan::call('elseyyid:location:install'); $fields = \DB::getSchemaBuilder()->getColumnListing('strings'); } $exceptions = ['en','code','created_at','updated_at']; $filtered = collect($fields)->filter(function ($value, $key) use($exceptions){ if (!in_array($value,$exceptions) ) { return $value; } }); return view('langs::home')->with('langs', $filtered); } public function lang($lang) { $list = Strings::select(['code','en',$lang])->get(); return view('langs::list')->with('lang', $lang)->with('list', $list); } public function update(Request $request,$code) { $column_name = $request->get('name'); $column_value = $request->get('value'); if($request->has('name') && $request->has('value')) { $test = Strings::select() ->where('code', '=', $code) ->update([$column_name => $column_value]); return response()->json([ 'code'=>200], 200); } return response()->json([ 'error'=> 400, 'message'=> 'Not enought params' ], 400); } public function generateJson($lang) { $list = Strings::pluck($lang,'en'); $json = json_encode_prettify($list); $this->files->put(base_path('lang/'.$lang.'.json'),$json); return redirect()->back()->with(config('elseyyid-location.message_success_variable'), 'Publicado'); } public function newLang(NewLangFormRequest $request) { $fields = \DB::getSchemaBuilder()->getColumnListing('strings'); if (! in_array( $request->newLang, $fields )) { Schema::table('strings', function (Blueprint $table) use($request){ $table->text($request->newLang)->nullable(); }); } return redirect()->route('elseyyid.translations.lang',$request->newLang)->with(config('elseyyid-location.message_success_variable'), 'Language '.$request->newLang. ' Created!'); } public function newString(NewStringFormRequest $request) { $string = Strings::where('en',$request->newString)->first(); if (!isset($string->code)) { Strings::create(['en' => $request->newString]); } return redirect()->back()->with(config('elseyyid-location.message_success_variable'), 'String '.$request->newString. ' Created!'); } public function search(SearchFormRequest $request) { $search_value = $request->search; $fields = collect(\DB::getSchemaBuilder()->getColumnListing('strings')); $columns = $fields->flip()->except(['code','created_at','updated_at'])->keys(); $query = Strings::select('*'); $query->where('en', 'LIKE', '%' . $search_value . '%'); foreach($columns as $column) { $query->orWhere($column, 'LIKE', '%' . $search_value . '%'); } $result = $query->get(); return view('langs::search_result')->with('result', $result)->with('search_value', $search_value); } public function string($code) { $string = Strings::find($code); return view('langs::lang')->with('string', $string); } public function publishAll() { $fields = collect(\DB::getSchemaBuilder()->getColumnListing('strings')); $columns = $fields->flip()->except(['code','en','created_at','updated_at'])->keys(); foreach ($columns as $lang) { $list = Strings::pluck($lang,'en'); $json = json_encode_prettify($list); $this->files->put(base_path('lang/'.$lang.'.json'),$json); } return redirect()->back()->with(config('elseyyid-location.message_success_variable'), __('All Json Files Published!')); } } src/Services/Helper.php000064400000000440152666150540011056 0ustar00 'required', ]; } } src/Requests/NewLangFormRequest.php000064400000001036152666150540013421 0ustar00 'required', ]; } } src/Requests/SearchFormRequest.php000064400000001034152666150540013271 0ustar00 'required', ]; } } src/Models/Strings.php000064400000000420152666150540010726 0ustar00{{__('Languages installed')}} @foreach ($langs as $lang)
{{__('Lang')}} {{ucfirst($lang)}}
@endforeach @endsection src/views/list.blade.php000064400000005166152666150540011244 0ustar00@extends(config('elseyyid-location.layout')) @section(config('elseyyid-location.content_section')) @include('langs::includes.tools')

Language {{ucfirst($lang)}}

Generate Json File
@foreach($list as $key => $value) @foreach ($value->toArray() as $key => $element) @if ($key !== 'code') @endif @endforeach @endforeach
{{$element}}Show
@endsection @section(config('elseyyid-location.scripts_section')) @endsection src/views/lang.blade.php000064400000003404152666150540011203 0ustar00@extends(config('elseyyid-location.layout')) @section(config('elseyyid-location.content_section')) @include('langs::includes.tools')

String {{$string->en}} ({{$string->code}})

@foreach (collect($string)->except(['code','created_at','updated_at'])->toArray() as $key => $element) {{$key}}
{{$element}}

@endforeach @endsection @section(config('elseyyid-location.scripts_section')) @endsection src/views/search_result.blade.php000064400000001766152666150540013136 0ustar00@extends(config('elseyyid-location.layout')) @section(config('elseyyid-location.content_section')) @include('langs::includes.tools')

{{__('Search Result for')}} '{{$search_value }}'

@if (count($result) > 0)
@foreach ($result as $element)
{{$element->en}}

@endforeach
@else

No results for {{ $search_value }}

@endif @endsection src/views/includes/nav.blade.php000064400000001606152666150540012656 0ustar00 src/views/includes/messages.blade.php000064400000003425152666150540013702 0ustar00@if ($errors->any())
@foreach ($errors->all() as $error) {!! $error !!}
@endforeach
@elseif (session()->get('flash_success'))
@if(is_array(json_decode(session()->get('flash_success'), true))) {!! implode('', session()->get('flash_success')->all(':message
')) !!} @else {!! session()->get('flash_success') !!} @endif
@elseif (session()->get('flash_warning'))
@if(is_array(json_decode(session()->get('flash_warning'), true))) {!! implode('', session()->get('flash_warning')->all(':message
')) !!} @else {!! session()->get('flash_warning') !!} @endif
@elseif (session()->get('flash_info'))
@if(is_array(json_decode(session()->get('flash_info'), true))) {!! implode('', session()->get('flash_info')->all(':message
')) !!} @else {!! session()->get('flash_info') !!} @endif
@elseif (session()->get('flash_danger'))
@if(is_array(json_decode(session()->get('flash_danger'), true))) {!! implode('', session()->get('flash_danger')->all(':message
')) !!} @else {!! session()->get('flash_danger') !!} @endif
@elseif (session()->get('flash_message'))
@if(is_array(json_decode(session()->get('flash_message'), true))) {!! implode('', session()->get('flash_message')->all(':message
')) !!} @else {!! session()->get('flash_message') !!} @endif
@endifsrc/views/includes/tools.blade.php000064400000004540152666150540013232 0ustar00
{{__('Publish All Json Files')}} {{__('All Locations')}}
src/views/layouts/app.blade.php000064400000003135152666150540012543 0ustar00 Locations Manager @include('langs::includes.nav')
@include('langs::includes.messages') @yield('content')
@yield('scripts') src/Providers/LaravelJsonLocationsManagerServiceProvider.php000064400000003400152666150540020453 0ustar00loadViewsFrom(__DIR__ . '/../views', 'langs'); /*Load routes*/ $this->loadRoutesFrom(__DIR__.'/../routes/web.php'); $this->publishes([ __DIR__ . '/../config/elseyyid-location.php' => base_path('config/elseyyid-location.php'), ], 'elseyyid-location'); $this->publishes([ __DIR__ . '/../views' => base_path('/resources/views/vendor/langs')], 'views'); } /** * Register the service provider. * * @return void */ public function register() { //Load helpers Helper::loadModuleHelpers(__DIR__); $this->mergeConfigFrom(__DIR__.'/../config/database.php','lang-manager'); $this->mergeConfigFrom(__DIR__.'/../config/elseyyid-location.php', 'elseyyid-location'); $this->commands($this->commands); } /** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ InstallCommand::class, PublishAllCommand::class, ]; } src/Commands/InstallCommand.php000064400000020061152666150540012523 0ustar00files = $filesystem; } /** * Execute the console command. * * @return mixed */ public function handle() { if (!Schema::hasTable('strings')) { $this->createSchema(); } else { $this->createSchema("fresh"); } $this->line(''); $this->info('Database Created!'); $this->importJsonStrings(); $this->info('Json strings imported!'); $this->line('Package installed!'); $this->info(''); } public function importArraysStrings() { $files = $this->files->directories(base_path('lang')); $all = []; $langs = []; $codes = []; foreach ($files as $key => $value) { $lang = Arr::last(explode('/',$value)); if ($lang !== 'vendor' ) { array_push($langs,$lang); $a = $this->files->allFiles($value); $array = []; foreach ($a as $k => $v) { $m = explode('.php',Arr::last(explode('/',$v)))[0]; array_push($array,Arr::dot([$m => include($v)])); } list($keys, $values) = Arr::divide(Arr::collapse($array)); array_push($codes,$keys); array_push($all,[$lang => Arr::collapse($array)]); } } $languages = Arr::collapse($all); $codigos = collect(Arr::collapse($codes))->unique(); $this->isInTable($langs); $collect = collect(); foreach ($codigos as $key => $codigo) { $fila = []; foreach ($languages as $key => $arr) { if (Arr::has($arr, $codigo)) { array_push($fila,[$key => Arr::get($arr, $codigo)]); } } $collect->push(Arr::collapse($fila)); } $this->fill($collect); } public function importJsonStrings() { $json_files = $this->files->files(base_path('lang')); $all = []; $langs = []; $codes = []; foreach ($json_files as $key => $json_file) { if (str_contains($json_file, '.json')) { $lang = Arr::first(explode('.json', basename($json_file))); array_push($langs,$lang); $array = json_decode($this->files->get($json_file)); $keys = collect($array)->keys(); array_push($codes,$keys); array_push($all,[$lang => $array ]); } } $languages = Arr::collapse($all); $codigos = collect(Arr::collapse($codes))->unique(); $this->isInTable($langs); $collect = collect(); foreach ($codigos as $key => $codigo) { $fila = []; array_push($fila,['en' => $codigo]); foreach ($languages as $key => $arr) { if( $key == 'en' ){ continue; } $arr = (array) $arr; if (Arr::has($arr, $codigo)) { array_push($fila, [$key => $arr[$codigo]]); } } $collect->push(Arr::collapse($fila)); } $this->fill($collect); } public function fill($collect) { foreach ($collect as $key => $value) { if (!Arr::has($value,'en')) { $array = collect($value); $array->prepend(Arr::first($value),'en'); $string = Strings::where('en',$array['en'])->first(); if (!isset($string->code)) { Strings::create($array->toArray()); } } else { $string = Strings::where('en',$value['en'])->first(); if (!isset($string->code)) { Strings::create($value); } } } } public function createSchema($mode = null) { if ($mode === 'fresh') { $this->backupTable(); Schema::dropIfExists('strings'); } Schema::create('strings', function (Blueprint $table) { $table->increments('code')->unsigned(); $table->text('en')->nullable()->collation('utf8_bin'); $table->text('ar')->nullable()->collation('utf8_bin'); $table->text('da')->nullable()->collation('utf8_bin'); $table->text('de')->nullable()->collation('utf8_bin'); $table->text('el')->nullable()->collation('utf8_bin'); $table->text('es')->nullable()->collation('utf8_bin'); $table->text('fr')->nullable()->collation('utf8_bin'); $table->text('id')->nullable()->collation('utf8_bin'); $table->text('it')->nullable()->collation('utf8_bin'); $table->text('nl')->nullable()->collation('utf8_bin'); $table->text('pt_BR')->nullable()->collation('utf8_bin'); $table->text('sv')->nullable()->collation('utf8_bin'); $table->text('th')->nullable()->collation('utf8_bin'); $table->timestamps(); }); } public function backupTable() { $backupFileName = 'backup_strings_' . now()->format('Y_m_d_His') . '.sql'; $backupPath = storage_path('backups/'); if (!is_dir($backupPath)) { mkdir($backupPath, 0755, true); } $command = "mysqldump --user=" . config('database.connections.mysql.username') . " --password=" . config('database.connections.mysql.password') . " --host=" . config('database.connections.mysql.host') . " " . config('database.connections.mysql.database') . " > " . $backupPath . $backupFileName . " 2> /dev/null"; try { exec($command); } catch (\Throwable $th) { Process::run($command); } $this->info("Backup created: {$backupPath}{$backupFileName}"); $this->info(''); $files = $this->getBackupFiles(); $maximumFiles = 3; if (count($files) > $maximumFiles) { $sliced = array_slice($files, 0, count($files) - $maximumFiles); collect($sliced)->each(function ($file) { if ($file != '.') { unlink($file); } }); } } public static function getBackupFiles(): array { $backupFolder = storage_path('backups'); if (!file_exists($backupFolder)) { mkdir($backupFolder, 0775, true); return []; } $files = array_filter( scandir($backupFolder), function ($item) { return !is_dir($item); } ); $files = array_values($files); return array_map(function ($file) use ($backupFolder) { return $backupFolder . '/' . $file; }, $files); } public function isInTable($langs) { $fields = \DB::getSchemaBuilder()->getColumnListing('strings'); foreach ($langs as $key => $value) { if (! in_array( $value, $fields )) { Schema::table('strings', function (Blueprint $table) use($value){ $table->text($value)->nullable()->collation('utf8_bin'); }); } } } } src/Commands/PublishAllCommand.php000064400000002636152666150540013164 0ustar00files = $filesystem; } /** * Execute the console command. * * @return mixed */ public function handle() { $fields = collect(\DB::getSchemaBuilder()->getColumnListing('strings')); $columns = $fields->flip()->except(['code','en','created_at','updated_at'])->keys(); foreach ($columns as $lang) { $list = Strings::pluck($lang,'en'); $json = json_encode_prettify($list); $this->files->put(base_path('lang/'.$lang.'.json'),$json); $this->info($lang.'.json Published!'); } $this->info('All Json Files Published!'); } } src/routes/web.php000064400000002526152666150540010161 0ustar00 config('elseyyid-location.prefix'), 'middleware' => config('elseyyid-location.middlewares') ,'as' => 'elseyyid.translations.'], function(){ Route::get('home', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@index')->name('home'); Route::get('lang/{lang}', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@lang')->name('lang'); Route::get('lang/generateJson/{lang}', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@generateJson')->name('lang.generateJson'); Route::get('newLang', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@newLang')->name('lang.newLang'); Route::get('newString', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@newString')->name('lang.newString'); Route::get('search', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@search')->name('lang.search'); Route::get('string/{code}', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@string')->name('lang.string'); Route::get('publish-all', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@publishAll')->name('lang.publishAll'); }); Route::post('translations/lang/update/{id}', '\Elseyyid\LaravelJsonLocationsManager\Controllers\HomeController@update')->name('elseyyid.translations.lang.update'); src/config/elseyyid-location.php000064400000000607152666150540012763 0ustar00 'Localization Manager', /** * Views */ 'layout' => 'langs::layouts.app', 'content_section' => 'content', 'scripts_section' => 'scripts', 'message_success_variable' => 'flash_success', /** * Routes */ 'prefix' => 'translations', 'middlewares' => ['web'], ]; src/config/database.php000064400000001505152666150540011070 0ustar00 [ 'mysql' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], ], ] ]; composer.json000064400000001367152666150540007307 0ustar00{ "name": "elseyyid/laravel-json-mysql-locations-manager", "type": "package", "description": "Laravel Json Locations Manager. Import all app language strings from lang folder", "keywords": ["laravel","laravel 5.4", "laravel 8", "laravel 9", "laravel 10", "laravel 11", "Laravel Json Locations Manager MySQL", "Laravel Json Locations Manager", "Laravel Localization Using Translation Strings As Keys"], "minimum-stability": "stable", "license": "MIT", "require": { "php": ">=5.3.0" }, "authors": [ { "name": "Omar Elseyyid", "email": "mhmoud.omar3@gmail.com" } ], "autoload":{ "psr-4": { "Elseyyid\\LaravelJsonLocationsManager\\": "src/" } }, "config": { "preferred-install": "dist" } } .gitignore000064400000000266152666150540006552 0ustar00vendor/ node_modules/ .idea/ composer.lock .DS_Store # Laravel 4 specific bootstrap/compiled.php app/storage/ # Laravel 5 & Lumen specific bootstrap/cache/ .env.*.php .env.php .env