-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d4da406
Showing
43 changed files
with
1,283 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
return [ | ||
"name" => "Translations", | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Paths | ||
|-------------------------------------------------------------------------- | ||
| | ||
| add path that will be show to the scaner to catch lanuages tags | ||
| | ||
*/ | ||
"paths" => [ | ||
app_path(), | ||
resource_path('views'), | ||
base_path('Modules') | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Locals | ||
|-------------------------------------------------------------------------- | ||
| | ||
| add the locals that will be show on the languages selector | ||
| | ||
*/ | ||
"locals" => [ | ||
"en" => "English", | ||
"ar" => "Arabic" | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Show Switcher | ||
|-------------------------------------------------------------------------- | ||
| | ||
| show switcher item on the navigation menu | ||
| | ||
*/ | ||
"show-switcher" => true, | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Switcher | ||
|-------------------------------------------------------------------------- | ||
| | ||
| the lanuages of the switcher navigation item must be 2 | ||
| | ||
*/ | ||
"switcher" => [ | ||
"ar", | ||
"en", | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Switcher Item Option | ||
|-------------------------------------------------------------------------- | ||
| | ||
| custome switcher menu item | ||
| | ||
*/ | ||
|
||
"languages-switcher-menu" => [ | ||
"group" => "Translations", | ||
"icon" => "heroicon-o-translate", | ||
"sort" => 10, | ||
"url" => 'admin/translations/change' | ||
], | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Modal | ||
|-------------------------------------------------------------------------- | ||
| | ||
| use simple modal resource for the translation resource | ||
| | ||
*/ | ||
"modal" => true, | ||
|
||
"auto" => true, | ||
|
||
"google_key" => env('GOOGLE_API', null) | ||
|
||
]; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Console; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Modules\Base\Helpers\Resources\VILT; | ||
use Modules\Menu\Entities\Menus; | ||
use Modules\Menu\Entities\MenusGroups; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
class InstallTranslation extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'translations:install'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Install translations permissions to main admin role'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$this->info('Install Permissions'); | ||
Artisan::call('roles:generate language_lines'); | ||
$this->info('Your Translations is ready now'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
/** | ||
* Get the console command arguments. | ||
* | ||
* @return array | ||
*/ | ||
protected function getArguments() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ ]; | ||
} | ||
} |
Empty file.
51 changes: 51 additions & 0 deletions
51
Database/Migrations/2022_01_25_010712_create_language_lines_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateLanguageLinesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('language_lines', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('group'); | ||
$table->index('group'); | ||
$table->text('key'); | ||
$table->jsonb('text'); | ||
$table->jsonb('metadata')->nullable(); | ||
$table->string('namespace')->default('*'); | ||
$table->index('namespace'); | ||
$table->softDeletes(); | ||
$table->timestamps(); | ||
}); | ||
|
||
if (!Schema::hasColumn('users', 'lang')) { | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->string('lang')->default('en'); | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('language_lines'); | ||
|
||
if (Schema::hasColumn('users', 'lang')) { | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('lang'); | ||
}); | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class TranslationsDatabaseSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
Model::unguard(); | ||
|
||
// $this->call("OthersTableSeeder"); | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Entities; | ||
|
||
use Spatie\TranslationLoader\LanguageLine; | ||
use Illuminate\Database\Eloquent\SoftDeletes; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
|
||
|
||
|
||
class Translation extends LanguageLine | ||
{ | ||
use HasFactory; | ||
use SoftDeletes; | ||
|
||
public $translatable = ['text']; | ||
|
||
/** @var array */ | ||
public $guarded = ['id']; | ||
|
||
/** @var array */ | ||
protected $casts = ['text' => 'array']; | ||
|
||
protected $table = "language_lines"; | ||
|
||
protected $fillable = [ | ||
"group", | ||
"key", | ||
"text" | ||
]; | ||
|
||
|
||
public static function getTranslatableLocales(): array | ||
{ | ||
return config('filament-translations.locals'); | ||
} | ||
|
||
public function getTranslation(string $locale, string $group = null): string | ||
{ | ||
if ($group === '*' && !isset($this->text[$locale])) { | ||
$fallback = config('app.fallback_locale'); | ||
|
||
return $this->text[$fallback] ?? $this->key; | ||
} | ||
return $this->text[$locale] ?? ''; | ||
} | ||
|
||
public function setTranslation(string $locale, string $value): self | ||
{ | ||
$this->text = array_merge($this->text ?? [], [$locale => $value]); | ||
|
||
return $this; | ||
} | ||
|
||
protected function getTranslatedLocales(): array | ||
{ | ||
return array_keys($this->text); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Exports; | ||
|
||
use Maatwebsite\Excel\Concerns\WithHeadings; | ||
use Modules\Translations\Entities\Translation; | ||
use Maatwebsite\Excel\Concerns\FromCollection; | ||
|
||
class TranslationsExport implements FromCollection, WithHeadings | ||
{ | ||
/** | ||
* @return \Illuminate\Support\Collection | ||
*/ | ||
public function collection() | ||
{ | ||
$transaltions = Translation::all(); | ||
|
||
foreach ($transaltions as $item) { | ||
foreach ($item->text as $key => $lang) { | ||
$item->{$key} = $lang; | ||
} | ||
unset($item->group); | ||
unset($item->metadata); | ||
unset($item->namespace); | ||
unset($item->text); | ||
unset($item->created_at); | ||
unset($item->updated_at); | ||
unset($item->deleted_at); | ||
} | ||
|
||
return $transaltions; | ||
} | ||
|
||
public function headings(): array | ||
{ | ||
|
||
$loadLocals = []; | ||
$getLocals = config('translations.locals'); | ||
foreach ($getLocals as $key => $value) { | ||
array_push($loadLocals, $key); | ||
} | ||
|
||
return array_merge(["id", "key"], $loadLocals); | ||
} | ||
} |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Http\Middleware; | ||
|
||
use Closure; | ||
|
||
class Language | ||
{ | ||
public function handle($request, Closure $next) | ||
{ | ||
if (in_array($request->header('Language'), ['ar', 'en'])) { | ||
app()->setLocale($request->header('Language')); | ||
} else { | ||
app()->setLocale('ar'); | ||
} | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Modules\Translations\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Cookie; | ||
|
||
|
||
class LanguageMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next | ||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse | ||
*/ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
if ($request->user()) { | ||
if (Cookie::get('lang')) { | ||
app()->setLocale(Cookie::get('lang')); | ||
} else { | ||
app()->setLocale('en'); | ||
} | ||
} | ||
return $next($request); | ||
} | ||
} |
Empty file.
Oops, something went wrong.