Skip to content

Commit

Permalink
add translations
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Sep 19, 2023
1 parent de21ef7 commit 424934a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
3 changes: 0 additions & 3 deletions resources/views/components/add-translation.blade.php

This file was deleted.

21 changes: 21 additions & 0 deletions resources/views/livewire/add-translation.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<x-translation::modal name="add-translation">
<h2>Add a new language</h2>

<form wire:submit="add" @submit="modal = false" class="flex flex-col gap-y-4">
<select wire:model="type" class="w-full px-2 py-1 bg-gray-50 rounded text-gray-700 group-hover:bg-white focus:bg-white">
<option value="short">Short</option>

<option value="string">String</option>
</select>

<input wire:model="group" type="text" name="group" placeholder="validation" class="w-full px-2 py-1 bg-gray-50 rounded text-gray-700 group-hover:bg-white focus:bg-white" x-show="$wire.type == 'short'">

<input wire:model="key" type="text" name="key" placeholder="required" class="w-full px-2 py-1 bg-gray-50 rounded text-gray-700 group-hover:bg-white focus:bg-white">

<input wire:model="value" type="text" name="value" placeholder="The :attribute is required" class="w-full px-2 py-1 bg-gray-50 rounded text-gray-700 group-hover:bg-white focus:bg-white">

<input wire:model="vendor" type="text" name="vendor" placeholder="my-package" 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,7 +1,7 @@
<div class="w-full flex flex-col" x-data="{ modal: false }">
<livewire:translation::add-language />

<x-translation::add-translation />
<livewire:translation::add-translation :language="$language" />

<div class="flex items-center justify-between gap-x-5 p-4 bg-indigo-600">
<div class="flex items-center gap-x-5">
Expand Down
62 changes: 62 additions & 0 deletions src/Livewire/AddTranslation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace JoeDixon\Translation\Livewire;

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

class AddTranslation extends Component
{
public $language;

public $type = 'short';

public $key;

public $value;

public $group;

public $vendor;

public function mount($language)
{
$this->language = $language;
}

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

/**
* Add a new language.
*/
public function add(): void
{
$translation = app(TranslationManager::class);

if ($this->type == 'short') {
$translation->addShortKeyTranslation(
$this->language,
$this->group,
$this->key,
$this->value,
$this->vendor
);
} else {
$translation->addStringKeyTranslation(
$this->language,
$this->key,
$this->value,
$this->vendor
);
}

$this->dispatch('translation-added');
}
}
2 changes: 2 additions & 0 deletions src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\ServiceProvider;
use JoeDixon\Translation\Livewire\AddLanguage;
use JoeDixon\Translation\Livewire\AddTranslation;
use JoeDixon\Translation\Livewire\Translations;
use JoeDixon\TranslationCore\Configuration;
use JoeDixon\TranslationCore\TranslationProvider;
Expand Down Expand Up @@ -37,6 +38,7 @@ public function boot()

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

/**
Expand Down

0 comments on commit 424934a

Please sign in to comment.