Skip to content

Commit

Permalink
Fix issues loading translations (#391)
Browse files Browse the repository at this point in the history
* Fix issues loading translations

* Replace `resource_path` by `lang_path`
  • Loading branch information
leandrogehlen authored Aug 24, 2023
1 parent 6efa2cf commit 83b8410
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.DS_Store
.phpunit.result.cache
/.idea
/vendor
/docker-compose.override.yml
/node_modules
package-lock.json
composer.phar
/vendor
auth.json
composer.lock
composer.phar
package-lock.json
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
/docker-compose.override.yml
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"nova"
],
"license": "MIT",
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
],
"require": {
"php": ">=7.4",
"laravel/framework": "^8.0|^9.0|^10.0",
Expand Down
27 changes: 27 additions & 0 deletions src/AdvancedNovaMediaLibraryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function boot()
$this->routes();
});

$this->loadTranslations();

Nova::serving(function (ServingNova $event) {
$this->bootTranslations();
Nova::script('media-lib-images-field', __DIR__.'/../dist/js/field.js');
});
}
Expand All @@ -34,4 +37,28 @@ protected function routes()
->prefix('nova-vendor/ebess/advanced-nova-media-library')
->group(__DIR__.'/../routes/api.php');
}

/**
* Load package translation resources.
*
* @return void
*/
protected function loadTranslations()
{
$this->loadJSONTranslationsFrom(__DIR__ . '/../resources/lang');
$this->loadJSONTranslationsFrom(lang_path('vendor/advanced-nova-media-library'));
}

/**
* Bootstraps current application locale translations to Nova.
*
* @return void
*/
protected function bootTranslations()
{
$locale = $this->app->getLocale();

Nova::translations(__DIR__ . "/../resources/lang/{$locale}.json");
Nova::translations(lang_path("vendor/advanced-nova-media-library/$locale.json"));
}
}

0 comments on commit 83b8410

Please sign in to comment.