diff --git a/config/nested-comments.php b/config/nested-comments.php index bff56fa..169b35f 100644 --- a/config/nested-comments.php +++ b/config/nested-comments.php @@ -35,8 +35,22 @@ 'allow-multiple-reactions' => env('ALLOW_MULTIPLE_REACTIONS', false), // Allow multiple reactions from the same user 'allow-guest-reactions' => env('ALLOW_GUEST_REACTIONS', false), // Allow guest users to react 'allow-guest-comments' => env('ALLOW_GUEST_COMMENTS', false), // Allow guest users to comment - 'mentions' => [ - 'items-placeholder' => 'Search users by name or email address', - 'empty-items-message' => 'No users found', - ], + + 'format-created-date' => 'F j Y h:i:s A', + /* + |-------------------------------------------------------------------------- + | Livewire Component + |-------------------------------------------------------------------------- + | + */ + 'show-heading' => true, + + 'show-badge-counter' => true, + 'badge-counter-color' => 'info', + + 'show-refresh-button' => true, + 'style-refresh-button' => 'button', // 'button' or 'icon', + 'icon-refresh-button' => 'heroicon-m-sparkles', + 'outlined-refresh-button' => false, + 'color-refresh-button' => 'info' // 'danger', 'gray', 'info', 'success' or 'warning' ]; diff --git a/resources/lang/en/nested-comments.php b/resources/lang/en/nested-comments.php index 84a1fc3..dc9872a 100644 --- a/resources/lang/en/nested-comments.php +++ b/resources/lang/en/nested-comments.php @@ -2,5 +2,55 @@ // translations for Coolsam/NestedComments return [ - // + 'comments' => [ + 'general' => [ + 'guest' => 'Guest', + 'no_comments_provided' => 'No comments provided.', + 'no_commentable_record_set' => 'No Commentable record set.', + 'record_is_not_configured_for_reactions' => 'The current record is not configured for reactions. Please include the `HasReactions` trait to the model.', + 'no_commentable_record_found_widget' => 'No Commentable record found. Please pass a record to the widget.', + 'reply' => 'Reply', + 'no_replies' => 'No replies yet.', + 'comments' => 'Comments', + ], + 'form' => [ + 'field' => [ + 'comment' => [ + 'label' => 'Your Comment', + 'mention_items_placeholder' => 'Search users by name or email address', + 'empty_mention_items_message' => 'No users found', + + ], + ], + 'buttons' => [ + 'submit' => 'Submit', + 'cancel' => 'Cancel', + 'add_comment' => 'Add a new comment', + 'add_reply' => 'Add a reply', + 'reply' => 'Reply', + 'hide_replies' => 'Hide Replies', + 'refresh' => 'Refresh', + ] + ], + 'table' => [ + 'actions' => [ + 'view_comments' => [ + //'label' => 'View comment', + 'heading' => 'Comments', + 'close' => 'Close' + ] + ], + ], + 'actions' => [ + 'view_comment' => [ + //'label' => 'View comment', + 'heading' => 'View Comments', + 'close' => 'Close' + ] + ] + ], + 'reactions' => [ + 'add_reaction' => 'Add a reaction', + ] + ]; diff --git a/resources/lang/fr/nested-comments.php b/resources/lang/fr/nested-comments.php new file mode 100644 index 0000000..493d193 --- /dev/null +++ b/resources/lang/fr/nested-comments.php @@ -0,0 +1,55 @@ + [ + 'general' => [ + 'guest' => 'Visiteur', + 'no_comments_provided' => 'Aucun commentaire enregistré.', + 'no_commentable_record_set' => 'Aucun `Commentable record` défini.', + 'record_is_not_configured_for_reactions' => 'L\'enregistrement actuel n\'est pas configuré pour les réactions. Veuillez inclure le trait `HasReactions` au modèle.', + 'no_commentable_record_found_widget' => 'Aucun `Commentable record` trouvé. Merci de passer le model au widget', + 'reply' => 'Réponse', + 'no_replies' => 'Aucune réponse.', + 'comments' => 'Commentaires', + ], + 'form' => [ + 'field' => [ + 'comment' => [ + 'label' => '', + //'label' => 'Votre Commentaire', + 'mention_items_placeholder' => 'Rechercher les utilisateurs par nom ou email', + 'empty_mention_items_message' => 'Aucun utilisateur trouvé', + + ], + ], + 'buttons' => [ + 'submit' => 'Envoyer', + 'cancel' => 'Fermer', + 'add_comment' => 'Ajouter un nouveau commentaire', + 'add_reply' => 'Ajouter une réponse', + 'reply' => 'Répondre', + 'hide_replies' => 'Cacher les réponses', + 'refresh' => 'Rafraîchir', + ] + ], + 'table' => [ + 'actions' => [ + 'view_comments' => [ + 'heading' => 'Commentaires', + 'close' => 'Fermer' + ] + ], + ], + 'actions' => [ + 'view_comment' => [ + 'heading' => 'Voir les Commentaires', + 'close' => 'Fermer' + ] + ] + ], + 'reactions' => [ + 'add_reaction' => 'Ajouter une réaction', + ] + +]; diff --git a/resources/views/components/comment-card.blade.php b/resources/views/components/comment-card.blade.php index 141be1d..96d090b 100644 --- a/resources/views/components/comment-card.blade.php +++ b/resources/views/components/comment-card.blade.php @@ -8,6 +8,6 @@ /> @else

- {{ __('No comment provided.') }} + {{ __('nested-comments::nested-comments.comments.general.no_comments_provided') }}

-@endif \ No newline at end of file +@endif diff --git a/resources/views/components/comments.blade.php b/resources/views/components/comments.blade.php index b2c1acd..30822b4 100644 --- a/resources/views/components/comments.blade.php +++ b/resources/views/components/comments.blade.php @@ -1,5 +1,5 @@ @if(isset($record)) @else -

No Commentable record set.

-@endif \ No newline at end of file +

{{ __('nested-comments::nested-comments.comments.general.no_commentable_record_set') }}

+@endif diff --git a/resources/views/components/reactions.blade.php b/resources/views/components/reactions.blade.php index 432513c..a6d1780 100644 --- a/resources/views/components/reactions.blade.php +++ b/resources/views/components/reactions.blade.php @@ -5,6 +5,6 @@ @if(app(\Coolsam\NestedComments\NestedComments::class)->classHasTrait($record, \Coolsam\NestedComments\Concerns\HasReactions::class)) @else -

__('The current record is not configured for reactions. Please include the `HasReactions` trait to the model.')

+

{{ __('nested-comments::nested-comments.comments.general.record_is_not_configured_for_reactions') }}

@endif -@endif \ No newline at end of file +@endif diff --git a/resources/views/filament/widgets/comments-widget.blade.php b/resources/views/filament/widgets/comments-widget.blade.php index d2543ee..6dc448a 100644 --- a/resources/views/filament/widgets/comments-widget.blade.php +++ b/resources/views/filament/widgets/comments-widget.blade.php @@ -3,7 +3,7 @@ @else - No Commentable record found. Please pass a record to the widget. + {{ __('nested-comments::nested-comments.comments.general.no_commentable_record_found_widget') }} @endif diff --git a/resources/views/livewire/add-comment.blade.php b/resources/views/livewire/add-comment.blade.php index 80af469..a7e9936 100644 --- a/resources/views/livewire/add-comment.blade.php +++ b/resources/views/livewire/add-comment.blade.php @@ -3,10 +3,10 @@
{{ $this->form }} - Submit + {{ __('nested-comments::nested-comments.comments.form.buttons.submit') }} - Cancel + {{ __('nested-comments::nested-comments.comments.form.buttons.cancel') }}
@else @@ -14,7 +14,7 @@ :inline-prefix="true" prefix-icon="heroicon-o-chat-bubble-bottom-center-text">

{{ $this->comment->created_at->format('F j Y h:i:s A') }}

+ >{{ $this->comment->created_at->format(config('nested-comments.format-created-date', 'F j Y h:i:s A')) }}

@@ -34,11 +34,11 @@ class="cursor-pointer" wire:click.prevent="toggleReplies"> @if($this->comment->replies_count > 0) - {{\Illuminate\Support\Number::forHumans($this->comment->replies_count, maxPrecision: 3, abbreviate: true)}} {{ str('Reply')->plural($this->comment->replies_count) }} + {{\Illuminate\Support\Number::forHumans($this->comment->replies_count, maxPrecision: 3, abbreviate: true)}} {{ str(__('nested-comments::nested-comments.comments.general.reply'))->plural($this->comment->replies_count) }} @else - - Reply + + {{ __('nested-comments::nested-comments.comments.form.buttons.reply') }} @endif @@ -67,7 +67,7 @@ class="cursor-pointer" } " type="button" - label="Hide replies" icon="heroicon-o-minus-circle" class="absolute -left-8 -bottom-4" wire:click.prevent="toggleReplies"/> + label="{{ __('nested-comments::nested-comments.comments.form.buttons.hide_replies') }}" tooltip="{{ __('nested-comments::nested-comments.comments.form.buttons.hide_replies') }}" icon="heroicon-o-minus-circle" class="absolute -left-8 -bottom-4" wire:click.prevent="toggleReplies"/> @endif @@ -79,4 +79,4 @@ class="cursor-pointer" element.classList.add(['comment-mention']); }); -@endscript \ No newline at end of file +@endscript diff --git a/resources/views/livewire/comments.blade.php b/resources/views/livewire/comments.blade.php index 09abd1f..b9279ac 100644 --- a/resources/views/livewire/comments.blade.php +++ b/resources/views/livewire/comments.blade.php @@ -1,19 +1,35 @@ - -
-
- {{ __('Comments') }} + @if(config('nested-comments.show-heading', true)) + +
+
+ {{ __('nested-comments::nested-comments.comments.general.comments') }} +
+ @if(config('nested-comments.show-badge-counter', true)) +
+ + {{\Illuminate\Support\Number::forHumans($this->comments->count(),maxPrecision: 3, abbreviate: true)}} + +
+ @endif
-
- - {{\Illuminate\Support\Number::forHumans($this->comments->count(),maxPrecision: 3, abbreviate: true)}} - -
-
- - - Refresh - + + @endif + @if(config('nested-comments.show-refresh-button', true)) + + + @if(config('nested-comments.style-refresh-button', 'button') === 'button') + {{ __('nested-comments::nested-comments.comments.form.buttons.refresh') }} + @endif + + + @endif @foreach($this->comments as $comment) true, ]) title="{{$reaction}} {{collect($attribs)->get('reactions')}} {{str(collect($attribs)->get('name'))->plural(collect($attribs)->get('reactions'))}}" + tooltip="{{$reaction}} {{collect($attribs)->get('reactions')}} {{str(collect($attribs)->get('name'))->plural(collect($attribs)->get('reactions'))}}" :outlined="true" :color="collect($attribs)->get('meToo') ? 'primary' : 'gray'" size="xs" > @@ -14,7 +15,7 @@ @endforeach - + true, ]) - :outlined="true" :color="collect($attribs)->get('meToo') ? 'primary' : 'gray'" size="md" title="{{collect($attribs)->get('name')}}" + :outlined="true" + :color="collect($attribs)->get('meToo') ? 'primary' : 'gray'" + size="md" + title="{{collect($attribs)->get('name')}}" > {{$reaction}} @@ -37,10 +41,3 @@
-@script - -@endscript \ No newline at end of file diff --git a/src/Concerns/HasComments.php b/src/Concerns/HasComments.php index 2233269..1f64202 100644 --- a/src/Concerns/HasComments.php +++ b/src/Concerns/HasComments.php @@ -125,17 +125,17 @@ public function deleteComment(Comment $comment): ?bool $allowGuest = config('nested-comments.allow-guest-comments', false); if (! auth()->check() && ! $allowGuest) { - throw new Exception('You must be logged in to edit your comment.'); + throw new Exception('You must be logged in to delete your comment.'); } if (auth()->check() && $comment->getAttribute('user_id') !== auth()->id()) { - throw new Exception('You are not authorized to edit this comment.'); + throw new Exception('You are not authorized to delete this comment.'); } if ($allowGuest && ! auth()->check()) { $guestId = app(NestedComments::class)->getGuestId(); if ($comment->getAttribute('guest_id') !== $guestId) { - throw new Exception('You are not authorized to edit this comment.'); + throw new Exception('You are not authorized to delete this comment.'); } } @@ -149,7 +149,7 @@ final public function getUserNameUsing(Comment $comment): string final public function getUserAvatarUsing(Comment $comment): ?string { - $user = $comment->user ?? $comment->guest_name ?? 'Guest'; + $user = $comment->user ?? $comment->guest_name ?? __('nested-comments::nested-comments.comments.general.guest'); return $this->getUserAvatar($user); } diff --git a/src/Filament/Actions/CommentsAction.php b/src/Filament/Actions/CommentsAction.php index 4fb13a0..c4494b2 100644 --- a/src/Filament/Actions/CommentsAction.php +++ b/src/Filament/Actions/CommentsAction.php @@ -14,9 +14,9 @@ protected function setUp(): void parent::setUp(); $this->modalWidth('4xl') ->slideOver() - ->modalHeading(fn (): string => __('View Comments')); + ->modalHeading(fn (): string => __('nested-comments::nested-comments.comments.actions.view_comment.heading')); $this->modalSubmitAction(false); - $this->modalCancelActionLabel(__('Close')); + $this->modalCancelActionLabel(__('nested-comments::nested-comments.comments.actions.view_comment.close')); $this->icon('heroicon-o-chat-bubble-left-right'); $this->modalIcon('heroicon-o-chat-bubble-left-right'); } diff --git a/src/Filament/Infolists/CommentCardEntry.php b/src/Filament/Infolists/CommentCardEntry.php index 1d8d6bf..ef5c0f5 100644 --- a/src/Filament/Infolists/CommentCardEntry.php +++ b/src/Filament/Infolists/CommentCardEntry.php @@ -47,7 +47,7 @@ public function evaluateUserAvatar(): ?string return $this->evaluate($this->userAvatarUsingClosure ?? fn (Comment | Model $record) => app(NestedComments::class) ->getDefaultUserAvatar($record->getAttribute('user') - ?? $record->getAttribute('guest_name') ?? 'Guest')); + ?? $record->getAttribute('guest_name') ?? __('nested-comments::nested-comments.comments.general.guest'))); } public function evaluateUserName(): ?string diff --git a/src/Filament/Tables/Actions/CommentsAction.php b/src/Filament/Tables/Actions/CommentsAction.php index 0a34cab..06f4872 100644 --- a/src/Filament/Tables/Actions/CommentsAction.php +++ b/src/Filament/Tables/Actions/CommentsAction.php @@ -14,9 +14,9 @@ protected function setUp(): void parent::setUp(); $this->modalWidth('4xl') ->slideOver() - ->modalHeading(fn (): string => __('Comments')); + ->modalHeading(fn (): string => __('nested-comments::nested-comments.comments.table.actions.view_comments.heading')); $this->modalSubmitAction(false); - $this->modalCancelActionLabel(__('Close')); + $this->modalCancelActionLabel(__('nested-comments::nested-comments.comments.table.actions.view_comments.close')); $this->icon('heroicon-o-chat-bubble-left-right'); $this->modalIcon('heroicon-o-chat-bubble-left-right'); } diff --git a/src/Livewire/AddComment.php b/src/Livewire/AddComment.php index 6a4ebce..a6bc07c 100644 --- a/src/Livewire/AddComment.php +++ b/src/Livewire/AddComment.php @@ -63,11 +63,11 @@ public function form(Form $form): Form return $form ->schema([ TiptapEditor::make('body') - ->label(__('Your comment')) + ->label(__('nested-comments::nested-comments.comments.form.field.comment.label')) ->profile('minimal') ->extraInputAttributes(['style' => 'min-height: 12rem;']) - ->mentionItemsPlaceholder(config('nested-comments.mentions.items-placeholder', __('Search users by name or email address'))) - ->emptyMentionItemsMessage(config('nested-comments.mentions.empty-items-message', __('No users found'))) + ->mentionItemsPlaceholder(__('nested-comments::nested-comments.comments.form.field.comment.mention_items_placeholder')) + ->emptyMentionItemsMessage(__('nested-comments::nested-comments.comments.form.field.comment.empty_mention_items_message')) /** * @phpstan-ignore-next-line */ diff --git a/src/NestedComments.php b/src/NestedComments.php index 6fd3919..2d553a0 100644 --- a/src/NestedComments.php +++ b/src/NestedComments.php @@ -28,7 +28,7 @@ public function getGuestId(): ?string public function getUserName(Authenticatable | Model | null $user): string { - return $user?->getAttribute('name') ?? $user?->getAttribute('guest_name') ?? 'Guest'; + return $user?->getAttribute('name') ?? $user?->getAttribute('guest_name') ?? __('nested-comments::nested-comments.comments.general.guest'); } public function getGuestName(): string @@ -37,7 +37,7 @@ public function getGuestName(): string return $this->getUserName(Auth::user()); } - return session(self::GUEST_NAME_FIELD, 'Guest'); + return session(self::GUEST_NAME_FIELD, __('nested-comments::nested-comments.comments.general.guest')); } public function setGuestName(string $name): void @@ -58,7 +58,7 @@ public function setOrGetGuestId() public function setOrGetGuestName() { if (! session()->has(self::GUEST_NAME_FIELD)) { - session([self::GUEST_NAME_FIELD => 'Guest']); + session([self::GUEST_NAME_FIELD => __('nested-comments::nested-comments.comments.general.guest')]); } return session(self::GUEST_NAME_FIELD);