laravel / nova-issues

556 stars 34 forks source link

Multiple translations not loading #5601

Closed keizah7 closed 1 year ago

keizah7 commented 1 year ago

Description:

Translations not working if I loading multiple json files

Nova::serving(function (ServingNova $event) {
    app()->setLocale('lt');

    Nova::translations([
        lang_path('lt.json'),
        lang_path('vendor/nova/lt.json'),
    ]);
});

I can see in source code, that translations is merged into array, but it doesn't work.

public static function translations($translations)
{
    if (is_string($translations)) {
        if (! is_readable($translations)) {
            return new static();
        }

        $translations = json_decode(file_get_contents($translations), true);
    }

    static::$translations = array_merge(static::$translations, $translations);

    return new static();
}

Code snippets below works

Nova::translations(array_merge(
    json_decode(file_get_contents(lang_path('lt.json')), true),
    json_decode(file_get_contents(lang_path('vendor/nova/lt.json')), true)),
);

or

Nova::translations(lang_path('lt.json'));

I am separating vendor translations with personal, so I need pass multiple translation files.

How to pass multiple files without manually getting and merging it? I think passing an array to Nova::translations method should be default functionality

crynobone commented 1 year ago

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

crynobone commented 1 year ago

We don't support the usage you mention above. It can either be string|array<string, string>.