Skip to content

Commit

Permalink
update file system to be json files remove translation-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Dec 20, 2022
1 parent f9ea6db commit b8b8a0a
Show file tree
Hide file tree
Showing 32 changed files with 255 additions and 259 deletions.
2 changes: 1 addition & 1 deletion Config/config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
"name" => "Translations",
"name" => "Translationsjson",
/*
|--------------------------------------------------------------------------
| Paths
Expand Down
7 changes: 1 addition & 6 deletions Console/InstallTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

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
{
Expand Down Expand Up @@ -44,7 +39,7 @@ public function __construct()
public function handle()
{
$this->info('Install Permissions');
Artisan::call('roles:generate language_lines');
Artisan::call('roles:generate translations');
$this->info('Your Translations is ready now');

return Command::SUCCESS;
Expand Down
Binary file removed Database/.DS_Store
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Modules\Translations\Database\Seeders;
namespace Modules\Translationsjson\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class TranslationsDatabaseSeeder extends Seeder
class TranslationsjsonDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
Expand Down
57 changes: 11 additions & 46 deletions Entities/Translation.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,24 @@
<?php

namespace Modules\Translations\Entities;
namespace Modules\Translations\Entities;

use Spatie\TranslationLoader\LanguageLine;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Translations\Services\SaveScan;
use Sushi\Sushi;
use Illuminate\Database\Eloquent\Model;



class Translation extends LanguageLine
class Translation extends Model
{
use HasFactory;
use SoftDeletes;

public $translatable = ['text'];

/** @var array */
public $guarded = ['id'];
use Sushi;

/** @var array */
protected $casts = ['text' => 'array'];
protected ?array $rows = [];

protected $table = "language_lines";

protected $fillable = [
"group",
"key",
"text"
];


public static function getTranslatableLocales(): array
public function getRows()
{
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;
return (new SaveScan())->getKeys();
}

protected function getTranslatedLocales(): array
protected function sushiShouldCache()
{
return array_keys($this->text);
return false;
}
}
25 changes: 5 additions & 20 deletions Exports/TranslationsExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Modules\Translations\Exports;

use Illuminate\Support\Facades\File;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Modules\Translations\Entities\Translation;
use Maatwebsite\Excel\Concerns\FromCollection;
Expand All @@ -13,31 +14,15 @@ class TranslationsExport implements FromCollection, WithHeadings
*/
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;
return Translation::all();
}

public function headings(): array
{

$loadLocals = [];
$getLocals = config('translations.locals');
foreach ($getLocals as $key => $value) {
array_push($loadLocals, $key);
$jsonFolder = File::files(lang_path());
foreach ($jsonFolder as $key => $value) {
$loadLocals[] = str_replace('.json', '', $value->getFilename());
}

return array_merge(["id", "key"], $loadLocals);
Expand Down
Empty file added Http/Controllers/.gitkeep
Empty file.
79 changes: 79 additions & 0 deletions Http/Controllers/TranslationsjsonController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Modules\Translationsjson\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class TranslationsjsonController extends Controller
{
/**
* Display a listing of the resource.
* @return Renderable
*/
public function index()
{
return view('translationsjson::index');
}

/**
* Show the form for creating a new resource.
* @return Renderable
*/
public function create()
{
return view('translationsjson::create');
}

/**
* Store a newly created resource in storage.
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
{
//
}

/**
* Show the specified resource.
* @param int $id
* @return Renderable
*/
public function show($id)
{
return view('translationsjson::show');
}

/**
* Show the form for editing the specified resource.
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view('translationsjson::edit');
}

/**
* Update the specified resource in storage.
* @param Request $request
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}
Empty file added Http/Middleware/.gitkeep
Empty file.
Empty file added Http/Requests/.gitkeep
Empty file.
17 changes: 6 additions & 11 deletions Imports/TranslationsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Modules\Translations\Imports;

use Illuminate\Support\Facades\File;
use Maatwebsite\Excel\Concerns\ToCollection;
use Modules\Translations\Entities\Translation;
use Illuminate\Support\Collection;
Expand All @@ -16,17 +17,11 @@ public function collection(Collection $rows)
$getLocals = config('translations.locals');

foreach ($rows as $row) {
$trans = Translation::where('key', $row[1])->where('group', '*')->first();
if ($trans) {
$text = [];
$i = 2;
foreach ($getLocals as $lang => $value) {
$text[$lang] = $row[$i];
$i++;
}

$trans->text = $text;
$trans->save();
$jsonFolder = File::files(lang_path());
foreach($jsonFolder as $key=>$getLangName){
$fileContent = json_decode(File::get(lang_path($getLangName->getFilename())));
$fileContent->{$row[1]} = $row[$key+2];
File::put(lang_path($getLangName->getFilename()), json_encode($fileContent, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
}
}
}
Expand Down
Loading

0 comments on commit b8b8a0a

Please sign in to comment.