Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Sep 18, 2023
1 parent 9cc330b commit de21ef7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 5 deletions.
3 changes: 0 additions & 3 deletions resources/views/components/add-language.blade.php

This file was deleted.

2 changes: 1 addition & 1 deletion resources/views/components/modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class="fixed inset-0 z-30 flex items-center justify-center overflow-auto bg-black bg-opacity-50"
x-show="modal === '{{ $name }}'"
>
<div class="min-w-[400px] min-h-[400px] max-w-3xl px-6 py-4 mx-auto text-left bg-white rounded shadow-lg" @click.outside="modal = false">
<div class="min-w-[600px] min-h-[400px] max-w-3xl px-6 py-4 mx-auto text-left bg-white rounded shadow-lg" @click.outside="modal = false">
{{ $slot }}
</div>
</div>
9 changes: 9 additions & 0 deletions resources/views/livewire/add-language.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<x-translation::modal name="add-language">
<h2>Add a new language</h2>

<form wire:submit="add" @submit="modal = false">
<input wire:model="language" type="text" placeholder="en_US" class="w-full px-2 py-1 bg-gray-50 rounded text-gray-700 group-hover:bg-white focus:bg-white">

<button type="submit">Add</button>
</form>
</x-translation::modal>
2 changes: 1 addition & 1 deletion resources/views/livewire/translations.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="w-full flex flex-col" x-data="{ modal: false }">
<x-translation::add-language />
<livewire:translation::add-language />

<x-translation::add-translation />

Expand Down
31 changes: 31 additions & 0 deletions src/Livewire/AddLanguage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace JoeDixon\Translation\Livewire;

use Illuminate\Contracts\View\View;
use JoeDixon\TranslationCore\TranslationManager;
use Livewire\Component;

class AddLanguage extends Component
{
public $language;

/**
* Render the component.
*/
public function render(): View
{
return view('translation::livewire.add-language');
}

/**
* Add a new language.
*/
public function add(): void
{
app(TranslationManager::class)
->addLanguage($this->language);

$this->dispatch('language-added');
}
}
7 changes: 7 additions & 0 deletions src/Livewire/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use JoeDixon\TranslationCore\TranslationManager;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Attributes\Url;
use Livewire\Component;

Expand Down Expand Up @@ -68,4 +69,10 @@ public function translateStringKey(TranslationManager $translation, string $key,
{
$translation->addStringKeyTranslation($this->language, $key, $value, $vendor);
}

#[On('language-added')]
public function updateLanguages(): void
{
$this->languages = app(TranslationManager::class)->languages();
}
}
2 changes: 2 additions & 0 deletions src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace JoeDixon\Translation;

use Illuminate\Support\ServiceProvider;
use JoeDixon\Translation\Livewire\AddLanguage;
use JoeDixon\Translation\Livewire\Translations;
use JoeDixon\TranslationCore\Configuration;
use JoeDixon\TranslationCore\TranslationProvider;
Expand Down Expand Up @@ -35,6 +36,7 @@ public function boot()
$this->registerTranslationProvider();

Livewire::component('translation::translations', Translations::class);
Livewire::component('translation::add-language', AddLanguage::class);
}

/**
Expand Down

0 comments on commit de21ef7

Please sign in to comment.