Skip to content

Conversation

N1ebieski
Copy link
Contributor

@N1ebieski N1ebieski commented Mar 9, 2025

Fixes #300, #428

This PR adds support for array translations for example:

resources/lang/en/validation.php:

'attributes' => [
    'question' => [
        'email' => 'email address',
    ],
]

Currently, the code:

__('validation.attributes.question')

shows:

Translation [validation.attributes.question] not found.Laravel Extension(translation)

but this key exists, it's only an array with nested elements.

This PR adds support for such keys for hovering and linking to the first element in the array. However, the value is not shown in the hover, because it's an array.

This code needs futher refactoring and testing.

@tharlei
Copy link

tharlei commented Mar 12, 2025

Nice PR! 🚀

It is also interesting to apply it to the locale that I passed to the __() or trans() method

Example:

__('validation.attributes.question', locale: 'pt-BR')

Check the pt-BR folder this transcription

@N1ebieski
Copy link
Contributor Author

@tharlei #330

@rmartinoscar
Copy link

Hey this works perfectly unless we have nested arrays without named key could this also be addressed ?
image

@N1ebieski
Copy link
Contributor Author

N1ebieski commented Aug 26, 2025

@rmartinoscar for me, this works:

obraz obraz

Something like this, doesn't work:

obraz

I'm afraid that feature would be impossible with the current parser.

@rmartinoscar
Copy link

Yes cause you have

return [
    'requirements' => [
        'sections' => [
            '0' => [
                'title' => 'PHP version',
            ],
            '1' => [
                'title' => 'PHP extensions',
            ],
        ]
    ]
];;

and i have which works but the extension doesn't like it

return [
    'requirements' => [
        'sections' => [
            [
                'title' => 'PHP version',
            ],
            [
                'title' => 'PHP extensions',
            ],
        ]
    ]
];;

@rmartinoscar
Copy link

rmartinoscar commented Aug 26, 2025

image image

This is also fine

@jacobmllr95
Copy link

@joetannenbaum Would love to see that merged :)
@N1ebieski Thanks for the great improvements to translations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Fail to find nested translation
4 participants