Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool translations aren't forwarded to the front-end #982

Closed
blackfyre opened this issue Nov 15, 2018 · 10 comments
Closed

Tool translations aren't forwarded to the front-end #982

blackfyre opened this issue Nov 15, 2018 · 10 comments
Labels
request Feature Request

Comments

@blackfyre
Copy link

  • Laravel Version: 5.7.13
  • Nova Version: 1.1.7
  • PHP Version: 7.2.11

Description:

As per Laravel 5.7 docs, I've added the translations to my tool, and in the blade templates / Tinker / ... it works fine. I've expected this to be added to the Nova.config.translations object automatically to be used with __(), but that's not the case, only the Nova translations are added there.

The Nova::provideToScript([]) doesn't help in extending already present translations with the new ones.

@maslauskas
Copy link

maslauskas commented Nov 15, 2018

solved this adding the following method to component file:

    /**
     * Get the translation keys from file.
     *
     * @return array
     */
    private function getTranslations()
    {
        $translationFile = __DIR__ . '/../resources/lang/'.app()->getLocale().'.json';

        if (! is_readable($translationFile)) {
            return [];
        }

        return json_decode(file_get_contents($translationFile), true);
    }

and then in component's boot method:

        Nova::provideToScript([
            'translations' => $this->getTranslations(),
        ]);

However, it overrides a bunch of other translations, which is not that great. Would love Nova to automatically include component translations in frontend.

@blackfyre
Copy link
Author

blackfyre commented Nov 15, 2018

@maslauskas I've already tried very similar things...

            Nova::provideToScript([
                'translations' => [
                    'proposal-items::' => __('proposal-editor::kpi')
                ],
            ]);
Nova::$jsonVariables['translations']['proposal-items::'] =  __('proposal-editor::kpi');

But nothing seems to work...

@maslauskas
Copy link

maslauskas commented Nov 15, 2018

Got it to work with this in component's boot method:

        /** @var Translator $translator */
        $translator = app('translator');
        $translator->load('*', '*', app()->getLocale());
        $lines = $translator->getFromJson('*');

        Nova::provideToScript([
            'translations' => $lines
        ]);

Basically just loading all translations again and providing them to frontend...

Seems to me that at the time of passing json translations to frontend, component translations are not loaded yet, so maybe it's a simple issue of moving scripts around.

@blackfyre
Copy link
Author

@maslauskas Still no dice... When I dump out the results of your snippet ($lines), I only get this:

 -------- ------------------------------------------------------------
  date     Thu, 15 Nov 2018 16:09:07 +0100
  source   ToolServiceProvider.php on line 36
  file     nova-components\my-resource-tool\src\ToolServiceProvider.php
 -------- ------------------------------------------------------------

"*"

@maslauskas
Copy link

Very strange. For me this little hack works as expected. Hopefully they add something to Nova that would load all component translations to frontend soon.

@blackfyre
Copy link
Author

@maslauskas Still, this should be a core feature and not something that requires workarounds...

@blackfyre
Copy link
Author

This is still an issue with Nova 1.2.1

@bonzai bonzai added the request Feature Request label Dec 18, 2018
@d3jn
Copy link

d3jn commented Dec 25, 2018

Nova provides translations to front using the following method:

/**
 * Get the translation keys from file.
 *
 * @return array
 */
private static function getTranslations()
{
    $translationFile = resource_path('lang/vendor/nova/'.app()->getLocale().'.json');

    if (! is_readable($translationFile)) {
        return [];
    }

    return json_decode(file_get_contents($translationFile), true);
}

Meaning you need to place your translations inside published resources/lang/vendor/nova directory.

@davidhemphill
Copy link
Contributor

Hey there! In order to keep this repository focused on bug reports, we auto-close feature requests and requests for help. Feel free to post your feature requests so others can discuss and add reactions. We'll keep an eye on them for later planning.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
request Feature Request
Projects
None yet
Development

No branches or pull requests

5 participants