Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
also load and publish json translations (#32)
Browse files Browse the repository at this point in the history
* also load and publish json translations

* apply StyleCI recommendations
  • Loading branch information
dakira authored and overtrue committed Sep 1, 2018
1 parent e73aa56 commit 6367499
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Commands/Publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function handle()
$force = $this->option('force') ? 'f' : 'n';

$sourcePath = base_path('vendor/caouecs/laravel-lang/src');
$sourceJsonPath = base_path('vendor/caouecs/laravel-lang/json');
$targetPath = base_path('resources/lang/');

if (!is_dir($targetPath) && !mkdir($targetPath)) {
Expand All @@ -59,7 +60,10 @@ public function handle()
$inLumen = $this->laravel instanceof \Laravel\Lumen\Application;

if ('all' == $locale) {
$files = [$sourcePath.'/*'];
$files = [
$sourcePath.'/*',
$jsonSourcePath,
];
$message = 'all';
$copyEnFiles = true;
} else {
Expand All @@ -70,6 +74,7 @@ public function handle()
continue;
}
$file = $sourcePath.'/'.trim($filename);
$jsonFile = $jsonSourcePath.'/'.trim($filename).'.json';

if (!file_exists($file)) {
$this->error("lang '$filename' not found.");
Expand All @@ -79,6 +84,13 @@ public function handle()

$published[] = $filename;
$files[] = $file;

if (!file_exists($jsonFile)) {
$this->error("lang '$filename' not found.");

continue;
}
$files[] = $jsonFile;
}

if (empty($files)) {
Expand Down
5 changes: 4 additions & 1 deletion src/TranslationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ protected function registerLoader()
base_path('vendor/caouecs/laravel-lang/src/'),
];

$jsonPath = base_path('vendor/caouecs/laravel-lang/json/');

if ($this->inLumen) {
$this->app['path.lang'] = base_path('vendor/laravel/lumen-framework/resources/lang');
array_push($paths, base_path('resources/lang/'));
}

return new FileLoader($app['files'], $app['path.lang'], $paths);
return (new FileLoader($app['files'], $app['path.lang'], $paths))
->addJsonPath($jsonPath);
});
}

Expand Down

0 comments on commit 6367499

Please sign in to comment.