Skip to content

Commit

Permalink
fix Add New Key to json file
Browse files Browse the repository at this point in the history
  • Loading branch information
adereksisusanto committed May 10, 2024
1 parent a619c1a commit 77576d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Actions/CopySourceKeyToTranslationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Outhebox\TranslationsUI\Models\Phrase;
use Outhebox\TranslationsUI\Models\Translation;
use Outhebox\TranslationsUI\Models\TranslationFile;

class CopySourceKeyToTranslationsAction
{
Expand All @@ -14,10 +15,10 @@ public static function execute(Phrase $sourceKey): void
'value' => null,
'uuid' => str()->uuid(),
'key' => $sourceKey->key,
'group' => $sourceKey->group,
'group' => (TranslationFile::find($sourceKey->file->id)?->is_root ? $translation->language()->first()?->code : $sourceKey->group),
'phrase_id' => $sourceKey->id,
'parameters' => $sourceKey->parameters,
'translation_file_id' => $sourceKey->file->id,
'translation_file_id' => (TranslationFile::find($sourceKey->file->id)?->is_root ? TranslationFile::firstWhere('name', $translation->language()->first()?->code)?->id : $sourceKey->file->id),
]);
});
}
Expand Down
10 changes: 9 additions & 1 deletion src/Http/Requests/SourcePhraseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Foundation\Http\FormRequest;
use Outhebox\TranslationsUI\Facades\TranslationsUI;
use Outhebox\TranslationsUI\Models\TranslationFile;

class SourcePhraseRequest extends FormRequest
{
Expand All @@ -20,8 +21,14 @@ public function rules(): array
{
$connection = TranslationsUI::getConnection();

$key = ['required', 'regex:/^[\w.]+$/u'];

if (TranslationFile::find($this->input('file'))?->extension === 'json') {
$key = ['required', 'string'];
}

return [
'key' => ['required', 'regex:/^[\w. ]+$/u'],
'key' => $key,
'file' => [
'required',
'integer',
Expand All @@ -35,6 +42,7 @@ public function messages(): array
{
return [
'*.required' => ltu_trans('validation.required'),
'*.string' => ltu_trans('validation.string'),
'*.regex' => ltu_trans('validation.regex'),
'*.integer' => ltu_trans('validation.integer'),
'*.exists' => ltu_trans('validation.exists'),
Expand Down

0 comments on commit 77576d5

Please sign in to comment.