Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Nova card localization

I'm trying to add localization support for a card built for the Laravel Nova dashboard.

I already created a folder in /resources/lang containing the JSON language files in a format like en.json. The files get published (copied) with the publish command but the loadJsonTranslationsFrom() does not seem to do anything:

class CardServiceProvider extends ServiceProvider
{
  public function boot()
  {
    $this->publishes(
      [__DIR__ . '/../resources/lang' => resource_path('lang/vendor/my-custom-card')],
      'my-custom-card-lang'
    );

    $this->loadJsonTranslationsFrom(resource_path('lang/vendor/my-custom-card'));
  }
}

This is how the markup in Card.vue looks like:

{{__('Title')}}

How can I test if the JSON files are loaded correctly? What am I missing?

The question is how do I support localization for cards in Laravel Nova?

like image 730
Sven Avatar asked Sep 21 '18 12:09

Sven


1 Answers

Card localization has been solved in Laravel Nova 2.

To localize strings use the __ helper within your Vue components and load the according translation files within your NovaServiceProvider:

Nova::serving(function (ServingNova $event) {
    Nova::script('{{ component }}', __DIR__.'/../dist/js/card.js');
    Nova::style('{{ component }}', __DIR__.'/../dist/css/card.css');
    Nova::translations(__DIR__.'/../resources/lang/en/card.json');
});

An exemplary implementation can be found on GitHub.

Further information is now available in the documentation.

like image 185
Sven Avatar answered Sep 27 '22 22:09

Sven