Skip to content

Commit

Permalink
accept multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomarinho committed Apr 17, 2017
1 parent e908e34 commit 9c78214
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/MultiLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,16 @@

trait MultiLanguage
{
private $appName;
private $languageKeys;
private $languages;
private $languageDirectories;

public function init()
{
$this->setAppName();
$this->setLanguageDirectories();
$this->listLanguages();
}

private function setAppName()
{
$this->appName = strtolower(config('app.name')).'.';
}

private function getAppName()
{
return $this->appName;
}

private function setLanguageDirectories()
{
$this->languageDirectories = File::directories(resource_path().'/lang');
Expand All @@ -56,10 +44,15 @@ public function generateFile()
$finder->in($this->languageDirectories);

foreach ($finder as $file) {
$path = pathinfo($file);
$arrFile = include $file;

$arr = [];
foreach ($this->languageKeys as $value) {
$arr[$value] = $arrFile[$value] ?? $this->getAppName().$value;
$exp = explode('.', $value);
if ($exp[0] == $path['filename']) {
$value = str_replace($path['filename'].'.', '', $value );
$arr[$value] = $arrFile[$value] ?? $path['filename'].'.'.$value;
}
}

$this->putFile($file, $arr);
Expand All @@ -75,8 +68,9 @@ public function putFile($file, $arr)
$template .= "\n";
$template .= str_replace($search, $replace, $this->banner());
$template .= "\n\r";
$template .= 'return '.var_export($arr, true).';';

if (!empty($arr)) {
$template .= 'return '.var_export($arr, true).';';
}
File::put($file, $template);
$this->line('Put file '.$file);
}
Expand Down Expand Up @@ -120,7 +114,7 @@ public function find()
foreach ($finder as $file) {
if (preg_match_all("/$pattern/siU", $file->getContents(), $matches)) {
foreach ($matches[2] as $key) {
$keys[] = str_replace($this->getAppName(), '', $key);
$keys[] = $key;
}
}

Expand Down

0 comments on commit 9c78214

Please sign in to comment.