Laravel-Lang / publisher

Publisher provides functionality for working with application localization
https://laravel-lang.com/packages-publisher.html
MIT License
212 stars 25 forks source link

`lang:update` breaks dot notation in the "attributes" (validation.php) and converts it into an array #289

Closed poldixd closed 2 years ago

poldixd commented 2 years ago

Description:

After using php artisan lang:update the package breakes the dot notation in the validation.php in the attributes array and converts it into an array.

Here is my attributes array:

<?php

return [
    'attributes' => [
        'timeplan.monday.0.0' => 'Monday (from)',
        'timeplan.monday.0.1' => 'Monday (to)',
        'timeplan.monday.1.0' => 'Monday (from)',
        'timeplan.monday.1.1' => 'Monday (to)',
        'timeplan.monday.2.0' => 'Monday (from)',
        'timeplan.monday.2.1' => 'Monday (to)',
        'timeplan.monday.3.0' => 'Monday (from)',
        'timeplan.monday.3.1' => 'Monday (to)',
        'timeplan.monday.4.0' => 'Monday (from)',
        'timeplan.monday.4.1' => 'Monday (to)',
    ]
];

After using php artisan lang:update the attributes array becomes this:

<?php

return [
    'attributes' => [
        'timeplan' => [
            'monday'    => [
                '0' => [
                    '0' => 'Monday (from)',
                    '1' => 'Monday (to)',
                ],
                '1' => [
                    '0' => 'Monday (from)',
                    '1' => 'Monday (to)',
                ],
                '2' => [
                    '0' => 'Monday (from)',
                    '1' => 'Monday (to)',
                ],
                '3' => [
                    '0' => 'Monday (from)',
                    '1' => 'Monday (to)',
                ],
                '4' => [
                    '0' => 'Monday (from)',
                    '1' => 'Monday (to)',
                ],
            ],
        ]
    ]
];

Now laravel gives me an error because the field is an array and not a string.

  mb_strtoupper(): Argument #1 ($string) must be of type string, array given

  at vendor/laravel/framework/src/Illuminate/Support/Str.php:902
    898▕      * @return string
    899▕      */
    900▕     public static function upper($value)
    901▕     {
  ➜ 902▕         return mb_strtoupper($value, 'UTF-8');
    903▕     }
    904▕ 
    905▕     /**
    906▕      * Convert the given string to title case.

      +9 vendor frames 
  10  app/Http/Livewire/User/UpdateTimeplanForm.php:98
      Livewire\Component::validate()

      +31 vendor frames 
  42  tests/Feature/User/UpdateTimeplanForm.php:143
      Livewire\Testing\TestableLivewire::call("update")

Steps To Reproduce:

Add the attributes array like in the discription to the validation.php and run php artisan lang:update

andrey-helldar commented 2 years ago

Using nested elements in field names is an interesting solution.

This feature has been released in version 14.3.0.

Thank you for issue.

poldixd commented 2 years ago

:-) Thank you very much for fixing.

icaliman commented 2 years ago

Using nested elements in field names is an interesting solution.

This feature has been released in version 14.3.0.

Thank you for issue.

@andrey-helldar Translation does not work after updating to the latest version and updating transtaions using php artisan lang:update.

Here is a example:

image

After updating transtations the validation.php file looks like:

<?php

return [
    'attributes' => [
        'frontend.email' => 'E-mail',
        'frontend.password' => 'Password',
        //...
    ]
];