Skip to content

Commit

Permalink
Merge pull request #73 from kg-bot/analysis-ajb3nY
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
kg-bot committed Aug 21, 2021
2 parents 00f6985 + c0b9c7a commit d9b87ef
Showing 1 changed file with 47 additions and 47 deletions.
94 changes: 47 additions & 47 deletions src/Console/Commands/ExportMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

class ExportMessages extends Command
{
/** @var \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed */
protected $filepath;
/** @var \Illuminate\Config\Repository|\Illuminate\Contracts\Foundation\Application|mixed */
protected $filepath;

/** @var array */
protected $messages;
/** @var array */
protected $messages;

/**
* The name and signature of the console command.
Expand Down Expand Up @@ -49,65 +49,65 @@ public function __construct()
*/
public function handle()
{
$format = $this->argument('format');
$format = $this->argument('format');

if($format === 'javascript') {
return $this->toJavaScript();
}
if($format === 'json') {
return $this->toJson();
}
if ($format === 'javascript') {
return $this->toJavaScript();
}
if ($format === 'json') {
return $this->toJson();
}

$this->error( "Format {$format} is not currently supported, you can use callback function if you need additional modification of exported array.");
$this->error("Format {$format} is not currently supported, you can use callback function if you need additional modification of exported array.");

return 1;
return 1;
}

protected function toJavaScript() {
$filename = config('laravel-localization.js.filename', 'll_messages.js');
protected function toJavaScript()
{
$filename = config('laravel-localization.js.filename', 'll_messages.js');

$adapter = new Local($this->filepath);
$filesystem = new Filesystem($adapter);
$adapter = new Local($this->filepath);
$filesystem = new Filesystem($adapter);

$contents = 'export default '.json_encode($this->messages);
$contents = 'export default '.json_encode($this->messages);

if ($filesystem->has($filename)) {
$filesystem->delete($filename);
$filesystem->write($filename, $contents);
} else {
$filesystem->write($filename, $contents);
}
if ($filesystem->has($filename)) {
$filesystem->delete($filename);
$filesystem->write($filename, $contents);
} else {
$filesystem->write($filename, $contents);
}

$this->info('Messages exported to JavaScript file, you can find them at '.$this->filepath.DIRECTORY_SEPARATOR
.$filename);
$this->info('Messages exported to JavaScript file, you can find them at '.$this->filepath.DIRECTORY_SEPARATOR
.$filename);

return 0;
return 0;
}

protected function toJson() {

foreach ($this->messages as $language_key => $translations) {
foreach ($translations as $translation_key => $translate) {
$filepath = "$this->filepath/$language_key";
$filename = "$translation_key.json";

$adapter = new Local($filepath);
$filesystem = new Filesystem($adapter);
protected function toJson()
{
foreach ($this->messages as $language_key => $translations) {
foreach ($translations as $translation_key => $translate) {
$filepath = "$this->filepath/$language_key";
$filename = "$translation_key.json";

$contents = json_encode($translate, JSON_PRETTY_PRINT);
$adapter = new Local($filepath);
$filesystem = new Filesystem($adapter);

$contents = json_encode($translate, JSON_PRETTY_PRINT);

if ($filesystem->has($filename)) {
$filesystem->delete($filename);
$filesystem->write($filename, $contents);
} else {
$filesystem->write($filename, $contents);
}
}
}
if ($filesystem->has($filename)) {
$filesystem->delete($filename);
$filesystem->write($filename, $contents);
} else {
$filesystem->write($filename, $contents);
}
}
}

$this->info('Messages exported to JSON files, you can find them at '.$this->filepath);
$this->info('Messages exported to JSON files, you can find them at '.$this->filepath);

return 0;
return 0;
}
}

0 comments on commit d9b87ef

Please sign in to comment.