Lang.js icon indicating copy to clipboard operation
Lang.js copied to clipboard

Incorrect returned value

Open astralo opened this issue 6 years ago • 7 comments

https://github.com/rmariuzzo/Lang.js/blob/31474a87dc21e4434b66b527d00944c61fc2a13d/src/lang.js#L288

if we have two lines as

    'book.btn.finish'               => 'Finish Booking',
    'book.btn'                        => 'Book Now',

and request Lang.get('book.btn.finish') then _getMessage returned 'Book Now'

astralo avatar Feb 20 '18 07:02 astralo

 if (message[subKey] && entries.length === 0) {

instead

 if (message[subKey] !== undefined) {

solves the problem

astralo avatar Feb 20 '18 07:02 astralo

Hey @astralo! We need to create a test case we your proposed changes. Thanks for letting me know.

rmariuzzo avatar Feb 21 '18 16:02 rmariuzzo

I ran into the similar issue.

Imagine the situation when you validate an input array with the nested fields in Laravel:

$request->validate([
    ...
    'location' => 'array',
    'location.city_id' => 'required',
    ...
]);

To localize the validation messages for both location and location.city_id attributes we need to add two translation strings:

// resources/lang/en/validation.php

return [
    ...
    'attributes' => [
        ...
        'location' => 'Location',
        'location.city_id' => 'City',
        ...
    ],
];

And in this case, if we want to use the validation.php file as a source for Lang.js, we will get the Location translation result for the lang.get('validation.attributes.location.city_id') call (instead of City).

RomeroMsk avatar Apr 16 '18 07:04 RomeroMsk

Any news on this?

RomeroMsk avatar Jun 01 '18 05:06 RomeroMsk

@RomeroMsk I will try to revisit it on this weekend.

rmariuzzo avatar Jun 01 '18 15:06 rmariuzzo

Bump.

RomeroMsk avatar Jul 24 '18 13:07 RomeroMsk

FYI I created a PR that solve this issue: https://github.com/rmariuzzo/Lang.js/pull/74 @astralo

In the meanwhile you can use that fork in package.json:

"lang.js": "https://github.com/alfonsobries/Lang.js#feature/proritize-dot-notations",

alfonsobries avatar Dec 26 '18 19:12 alfonsobries