Laravel - How to translate validation values? Not possible? - php

Here is a similar question and info what this is all about:
Laravel translate values required_if
And here's GitHub gist of feature which would solve this problem and it is merged in but still not working:
https://github.com/laravel/framework/pull/4037
Here are my validation rules
'input.deliver_to_address' => ['in:to_billing_address,to_other_address']
'input.delivery_company_name' => ['required_if:input.deliver_to_address,to_other_address'],
and here's my validation.php files:
'values' => [
'to_other_address' => 'to other address',
'input.deliver_to_address' => [
'to_other_address' => 'to other address',
],
'deliver_to_address' => [
'to_other_address' => 'to other address',
],
],
As you can see I've tried all possible combinations but still the validation rule displays:
The contact person field is required when deliver to address is to_other_address.
The question is, is it possible to translate array validation values in Laravel?
I'm using Laravel 6.2

Solved:
The issue was that I'm using input.deliver_to_address and when the Validator.php tries to replace the value with translated string, the $key will be validation.values.input.deliver_to_address.to_other_address
so the array structure needs to be like this:
'values' => [
'input' => [
'deliver_to_address' => [
'to_other_address' => 'to other address',
],
],
],
instead of
'values' => [
'input.deliver_to_address' => [
'to_other_address' => 'to other address',
],
],
because of the additional .input in the attribute name.

Related

TYPO3 BE TCA type Preview Image

i search for a Solution:
How can i add a Preview Image for a TCA type?
Example: I have 3 different types and would like to display a preview image for them. The same as the t3 backend layouts.
Just like the Backend-Layout:
Maybe there is a solution to this?
The documentation is explaining it:
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Examples.html#select-drop-down-for-records-represented-by-images
This is the example code:
[
'columns' => [
'select_single_12' => [
'label' => 'select_single_12 foreign_table selicon_field',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_styleguide_elements_select_single_12_foreign',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
],
],
],
]
And the code for the field of the connected table is this:
[
'ctrl' => [
'title' => 'Form engine elements - select foreign single_12',
'label' => 'fal_1',
'selicon_field' => 'fal_1',
// ...
],
'columns' => [
// ...
'fal_1' => [
'label' => 'fal_1 selicon_field',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'fal_1',
[
'maxitems' => 1,
],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
),
],
],
// ...
];
As you have a strange label inside your field it's not clear if you want to link to an image, to a text or even to a field that offers a combination like it's done with relations to the table sys_file by the intermediate table sys_file_ref.
So defining more precise what you need exactly might help to give you a more detailed answer. You can edit your answer to add this description.

Livewire encountered corrupt data when trying to hydrate the [data-table] component, when trying to send closure to livewire component

I tried to send some closure to the livewire component inside a nested array but it produce this error:
Livewire encountered corrupt data when trying to hydrate the [data-table] component. Ensure that the [name, id, data] of the Livewire component wasn't tampered with between requests.**
What I sent to the component :
<livewire:data-table
:model="$modelClass"
:custom="[
[
'label' => 'E-Mail',
'column'=> 'email'
],
]"
:exclude="['password', 'email_verified_at', 'remember_token', 'updated_at']"
:include="[
[
'label' => 'Role',
'column'=> 'role.name',
'format'=> fn($value, $row) => '<strong>'.ucwords($value).'</strong>',
'formatType' => 'html'
],
[
'label' => 'Search Engine',
'links' => [
[
'title' => fn($row) => $row->name.' Google',
'link' => fn($row) => 'https://google.com/search?q='.$row->name,
'type' => 'button',
]
],
],
[
'label' => 'Social Media',
'links' => [
[
'title' => 'Facebook',
'link' => 'https://facebook.com',
'type' => 'link'
],
[
'title' => 'Instagram',
'link' => 'https://instagram.com',
'type' => 'link'
]
]
],
[
'label' => 'Email Provider',
'links' => [
[
'title' => function($row){
if(str_contains($row->email, 'gmail')){
return 'Google';
}elseif(str_contains($row->email, 'yahoo')){
return 'Yahoo';
}else{
return 'Unidentified';
}
},
'class' => 'cursor-pointer',
'onclick' => 'return false',
]
]
]
]"
/>
Then i check in ComponentCheckshumManager class, my array that contains the closure become empty when go through Hashing using json_encode.
Before Hashing :
Data before hashing
After Hashing :
Data after hashing
This error happens only when refreshing the component, is there any correct way to send closure to the livewire component? Please help.
Depends on name. If it's an attribute, then issue is somewhere else, if it's a magic function, then you have a problem. Each time a template modifies original data, you will get corrupt data. Even if it's $user->full_name magic function, it will corrupt original data.

How to exclude optional parameters from input filter

I'm using laminas-inputfilter, laminas-filter and laminas-validator in my REST API.
My filter config looks like this, for example:
'input_filter_specs' => [
MyResource::class . '\\Validator' => [
'param1' => ...,
'param2' => ...,
'param3' => [
'required' => false,
'allow_empty' => false,
'filters' => [
'no_tags' => [
'name' => StripTags::class,
],
'no_newlines' => [
'name' => StripNewlines::class,
],
'trim' => [
'name' => StringTrim::class,
],
],
'validators' => [
'not_empty' => [
'name' => NotEmpty::class,
],
],
],
],
],
The filtering and validation also work perfectly so far. But what surprises me is: I make a request to the API that contains param1 and param2, I deliberately omit param3. However, if I now look at the array that my REST service receives, I find there:
Array
(
[param1] => one
[param2] => two
[param3] =>
)
This means that the optional parameter is automatically added and filled with an empty string. The behavior is a bit unfavorable for me, however, as it collides with my further processes.
Is there a possibility (e.g. via a config switch) to only validate input parameters if they are set and otherwise exclude them from the array?
You can try with validation groups feature: https://docs.laminas.dev/laminas-form/quick-start/#validation-groups.
You can set a validation groups array with only required parameters, then check if param3 is not empty and in that case add to validation group array.

Converting text to local language - laravel 5.6

I am implementing text to speech calls with laravel and Nexmo. In the application, i am able to place calls to my clients with `English language' as below. The text placed to my customers is
To add a reply, please leave a message after the beep, then press the pound key
Is there a way to convert the text from english to my native language ? So the call will be in the language i converted to ?
Please help? Beginner with this
$currentHost = 'http://abc123.ngrok.io';
Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => $cc->user->phone_number
]],
'from' => [
'type' => 'phone',
'number' => config('services.nexmo.sms_from')
],
'answer_url' => [$currentHost.'/webhook/answer/'.$entry->id],
'event_url' => [$currentHost.'/webhook/event']
]);
return response()->json([
[
'action' => 'talk',
'text' => $ticket->content
],
[
'action' => 'talk',
'text' => 'To add a reply, please leave a message after the beep, then press the pound key',
'voiceName' => 'Brian'
],
[
'action' => 'record',
'endOnKey' => '#',
'beepStart' => true
]
]);

Translate yii2 based website

I have created a website using Yii2 . And I am new also in Yii2. I have read the translation options of Yii2 here http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html . It seemed a bit complex to me and I didn't understand what really to do well.
So what about copy the project to a subdomain and just replace the words with its translations? Or should I learn Yii2 translation option and use it?
Any advice is very important me. Thanks in advance!
You can use this function for translations:
<?=Yii::t('app','Text to translate')?>
and in MyProject/messages/en/app.php
return [
'Text to translate' => 'Translated text',
'Other Text to translate' => 'Other Translated text',
];
you need to define in web.php default language
'language'=>'en'
and in web.php components array
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
//'sourceLanguage' => 'en-US',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
],
],
],
],

Categories