Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
MohmmedAshraf committed Apr 20, 2024
1 parent fb41286 commit 381aee9
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 34 deletions.
4 changes: 2 additions & 2 deletions resources/views/components/phrase/similar/similar-phrases.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defineProps<{
</script>

<template>
<div v-if="similarPhrases.data.length > 0" class="flex flex-col divide-y">
<SimilarPhrasesItem v-for="phrase in similarPhrases.data" :key="phrase.uuid" :phrase="phrase" />
<div v-if="similarPhrases.length > 0" class="flex flex-col divide-y">
<SimilarPhrasesItem v-for="phrase in similarPhrases" :key="phrase.uuid" :phrase="phrase" />
</div>

<div v-else class="relative flex size-full min-h-[250px]">
Expand Down
4 changes: 2 additions & 2 deletions resources/views/pages/source/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const props = defineProps<{
translation: Translation
source: SourceTranslation
similarPhrases: SourcePhrase
files: { data: Record<string, TranslationFile> }
files: Record<string, TranslationFile>
}>()
const form = useForm({
Expand All @@ -28,7 +28,7 @@ const submit = () => {
}
const translationFiles = computed(() => {
return props.files.data.map((fileType: TranslationFile) => {
return props.files.map((fileType: TranslationFile) => {
return {
value: fileType.id,
label: fileType.nameWithExtension,
Expand Down
20 changes: 8 additions & 12 deletions resources/views/pages/translations/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ import { SourceTranslation, Translation } from "../../../scripts/types"
import useConfirmationDialog from "../../../scripts/composables/use-confirmation-dialog"
const props = defineProps<{
translations?: {
data: Record<string, Translation>
links: Record<string, string>
meta: Record<string, string>
}
sourceTranslation?: SourceTranslation
translations?: Record<string, Translation>
sourceTranslation?: Record<string, SourceTranslation>
}>()
const searchQuery = ref("")
Expand All @@ -35,8 +31,8 @@ const deleteTranslations = async (id: number) => {
}
const filteredTranslations = computed(() => {
return Object.keys(props.translations.data).map((key) => {
return props.translations.data[key];
return Object.keys(props.translations).map((key) => {
return props.translations[key];
}).filter((translation: Translation | undefined) => {
return (
translation &&
Expand All @@ -48,15 +44,15 @@ const filteredTranslations = computed(() => {
function toggleSelection() {
if (selectedIds.value.length === props.translations.data.length) {
if (selectedIds.value.length === props.translations.length) {
selectedIds.value = []
} else {
selectedIds.value = props.translations.data.map((language: Translation) => language.id)
selectedIds.value = props.translations.map((language: Translation) => language.id)
}
}
const isAllSelected = computed(() => selectedIds.value.length === Object.keys(props.translations.data).length)
const isAllSelected = computed(() => selectedIds.value.length === Object.keys(props.translations).length)
</script>

<template>
Expand All @@ -74,7 +70,7 @@ const isAllSelected = computed(() => selectedIds.value.length === Object.keys(pr
<div class="relative z-10 flex w-full divide-x shadow">
<div class="flex w-14 shrink-0 items-center justify-center">
<div class="flex shrink-0 items-center">
<InputCheckbox :disabled="!translations.data.length" :checked="isAllSelected" @input="toggleSelection" />
<InputCheckbox :disabled="!translations.length" :checked="isAllSelected" @input="toggleSelection" />
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/Actions/SyncPhrasesAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function execute(Translation $source, $key, $value, $locale, $file
'group' => $translationFile->name,
'translation_file_id' => $translationFile->id,
], [
'value' => (empty($value)?null:$value),
'value' => (empty($value) ? null : $value),
'parameters' => getPhraseParameters($value),
'phrase_id' => $translation->source ? null : $source->phrases()->where('key', $key)->first()?->id,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/PublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PublishCommand extends Command

public function handle(): int
{
$force = (bool)$this->option('force');
$force = (bool) $this->option('force');

if (! $force && File::exists(public_path('vendor/translations-ui'))) {
$this->line('Your application already have the Translations UI assets');
Expand Down
4 changes: 2 additions & 2 deletions src/Exceptions/TranslationsUIExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Outhebox\TranslationsUI\Exceptions;

use App\Exceptions\Handler;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as BaseHandler;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
Expand All @@ -11,7 +12,6 @@
use Inertia\Inertia;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Throwable;
use Illuminate\Auth\AuthenticationException;

if (class_exists('App\Exceptions\Handler')) {
class ExtendedHandler extends Handler
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function renderInertiaException($request, $e): Response|JsonResponse|\
])->toResponse($request)->setStatusCode($statusCode);
}

if ($statusCode === 500 && !$e instanceof AuthenticationException && ! App::hasDebugModeEnabled()) {
if ($statusCode === 500 && ! $e instanceof AuthenticationException && ! App::hasDebugModeEnabled()) {
return Inertia::render('error', [
'code' => '500',
'title' => 'Internal server error',
Expand Down
8 changes: 7 additions & 1 deletion src/Http/Controllers/PhraseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ public function update(Translation $translation, Phrase $phrase, Request $reques
return redirect()->route('ltu.phrases.edit', [
'translation' => $translation,
'phrase' => $nextPhrase,
])->with('notification', [
'type' => 'success',
'body' => 'Phrase has been updated successfully',
]);
}

return redirect()->route('ltu.phrases.index', $translation);
return redirect()->route('ltu.phrases.index', $translation)->with('notification', [
'type' => 'success',
'body' => 'Phrase has been updated successfully',
]);
}
}
15 changes: 12 additions & 3 deletions src/Http/Controllers/SourcePhraseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public function store(Request $request): RedirectResponse
content: $request->input('content'),
);

return redirect()->route('ltu.source_translation');
return redirect()->route('ltu.source_translation')->with('notification', [
'type' => 'success',
'body' => 'Phrase has been added successfully',
]);
}

public function edit(Phrase $phrase): Response|RedirectResponse
Expand Down Expand Up @@ -104,8 +107,14 @@ public function update(Phrase $phrase, Request $request): RedirectResponse
->first();

return $nextPhrase
? redirect()->route('ltu.source_translation.edit', ['translation' => $phrase->translation, 'phrase' => $nextPhrase])
: redirect()->route('ltu.source_translation');
? redirect()->route('ltu.source_translation.edit', ['translation' => $phrase->translation, 'phrase' => $nextPhrase])->with('notification', [
'type' => 'success',
'body' => 'Phrase has been updated successfully',
])
: redirect()->route('ltu.source_translation')->with('notification', [
'type' => 'success',
'body' => 'Phrase has been updated successfully',
]);
}

public function destroy(Phrase $phrase): RedirectResponse
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Resources/ContributorResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/** @mixin Contributor */
class ContributorResource extends JsonResource
{
public static $wrap = null;

public function toArray($request): array
{
return [
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Resources/LanguageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
/** @mixin Language */
class LanguageResource extends JsonResource
{
public static $wrap = null;

public function toArray($request): array
{
return [
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Resources/PhraseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/** @mixin Phrase */
class PhraseResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request): array
{
return [
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Resources/TranslationFileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/** @mixin TranslationFile */
class TranslationFileResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request): array
{
return [
Expand Down
2 changes: 0 additions & 2 deletions src/Http/Resources/TranslationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
class TranslationResource extends JsonResource
{
public static $wrap = null;

public function toArray($request): array
{
return [
Expand Down
2 changes: 2 additions & 0 deletions src/TranslationsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function getTranslations(string $locale): array
if ($file->getRelativePath() === '') {
return $locale.DIRECTORY_SEPARATOR.$file->getFilename();
}

return $locale.DIRECTORY_SEPARATOR.$file->getRelativePath().DIRECTORY_SEPARATOR.$file->getFilename();
})
->when($this->filesystem->exists(lang_path($rootFileName)), function ($collection) use ($rootFileName) {
Expand Down Expand Up @@ -107,6 +108,7 @@ public function getTranslations(string $locale): array
$translations[$file] = [];
}
});

return $translations;
}

Expand Down
12 changes: 12 additions & 0 deletions src/TranslationsUIServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
use Outhebox\TranslationsUI\Console\Commands\ImportTranslationsCommand;
use Outhebox\TranslationsUI\Console\Commands\PublishCommand;
use Outhebox\TranslationsUI\Exceptions\TranslationsUIExceptionHandler;
use Outhebox\TranslationsUI\Http\Resources\ContributorResource;
use Outhebox\TranslationsUI\Http\Resources\InviteResource;
use Outhebox\TranslationsUI\Http\Resources\LanguageResource;
use Outhebox\TranslationsUI\Http\Resources\PhraseResource;
use Outhebox\TranslationsUI\Http\Resources\TranslationFileResource;
use Outhebox\TranslationsUI\Models\Contributor;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
Expand Down Expand Up @@ -70,6 +75,13 @@ public function packageBooted(): void
$this->registerAuthDriver();

$this->registerExceptionHandler();

PhraseResource::withoutWrapping();
InviteResource::withoutWrapping();
LanguageResource::withoutWrapping();
ContributorResource::withoutWrapping();
TranslationFileResource::withoutWrapping();
TranslationFileResource::withoutWrapping();
}

private function registerAuthDriver(): void
Expand Down

0 comments on commit 381aee9

Please sign in to comment.