Skip to content

Commit

Permalink
PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
subotkevic committed Nov 7, 2018
1 parent 6535055 commit a5e6722
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
34 changes: 18 additions & 16 deletions src/Command/TranslationHelperCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,35 @@ class TranslationHelperCommand extends Command
*/
public function handle()
{
$translationKeys = $this->findProjectTranslationsKeys();
$translationKeys = $this->findProjectTranslationsKeys();
$translationFiles = $this->getProjectTranslationFiles();

foreach ($translationFiles as $file) {
$translationData = $this->getAlreadyTranslatedKeys($file);
$this->line("Language: " . str_replace('.json', '', basename($file)));
$added = [];
$added = [];

$this->line('Language: ' . str_replace('.json', '', basename($file)));

foreach ($translationKeys as $key) {
if (!isset($translationData[$key])) {
$this->warn(" - Added: {$key}");
$translationData[$key] = '';
$added[] = $key;
$added[] = $key;

$this->warn(" - Added: {$key}");
}
}

if ($added) {
$this->line("Updating translation file...");
$this->line('Updating translation file...');

$this->writeNewTranslationFile($file, $translationData);

$this->info("Translation file have been updated!");
$this->info('Translation file have been updated!');
} else {
$this->warn("Nothing new found for this language.");
$this->warn('Nothing new found for this language.');
}

$this->line("");
$this->line('');
}
}

Expand All @@ -58,11 +60,11 @@ public function handle()
*/
private function findProjectTranslationsKeys()
{
$allKeys = [];
$allKeys = [];
$viewsDirectories = config('translation-helper.scan_directories');
$fileExtensions = config('translation-helper.file_extensions');
$fileExtensions = config('translation-helper.file_extensions');

foreach($viewsDirectories as $directory) {
foreach ($viewsDirectories as $directory) {
foreach ($fileExtensions as $extension) {
$this->getTranslationKeysFromDir($allKeys, $directory, $extension);
}
Expand Down Expand Up @@ -102,11 +104,11 @@ private function getTranslationKeysFromFunction(&$keys, $functionName, $content)

preg_match_all("#{$functionName}\(\'(.*?)\'\)#", $content, $matches);

if ( ! empty($matches)) {
if (! empty($matches)) {
foreach ($matches[1] as $match) {
$match = str_replace('"', "'", str_replace("\'", "'", $match));

if ( ! empty($match)) {
if (! empty($match)) {
$keys[$match] = $match;
}
}
Expand All @@ -118,7 +120,7 @@ private function getTranslationKeysFromFunction(&$keys, $functionName, $content)
*/
private function getProjectTranslationFiles()
{
$path = config('translation-helper.output_directory');
$path = config('translation-helper.output_directory');
$files = glob("{$path}/*.json", GLOB_BRACE);

return $files;
Expand All @@ -143,7 +145,7 @@ private function getAlreadyTranslatedKeys($filePath)
*/
private function writeNewTranslationFile($filePath, $translations)
{
file_put_contents($filePath, json_encode($translations, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
file_put_contents($filePath, json_encode($translations, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

if ( ! function_exists('lang')) {
if (! function_exists('lang')) {
/**
* Translate the given message.
*
Expand All @@ -15,7 +15,7 @@ function lang($key = null, $replace = [], $locale = null)
}
}

if ( ! function_exists('glob_recursive')) {
if (! function_exists('glob_recursive')) {
/**
* Find path names matching a pattern recursively
*
Expand Down

0 comments on commit a5e6722

Please sign in to comment.