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

Commit

Permalink
Added the ability to exclude generic files or generic folders. (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
waydelyle authored and martinlindhe committed May 1, 2019
1 parent a0f95ad commit 056293f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
74 changes: 41 additions & 33 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function __construct($config = [])
if (!isset($config['i18nLib'])) {
$config['i18nLib'] = self::VUE_I18N;
}
if (!isset($config['excludes'])) {
$config['excludes'] = [];
}
$this->config = $config;
}

Expand All @@ -49,7 +52,9 @@ public function generateFromPath($path, $format = 'es6', $withVendor = false, $l
$jsBody = '';
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()) {
if(!$withVendor && in_array($fileinfo->getFilename(), ['vendor'])) {
if(!$withVendor
&& in_array($fileinfo->getFilename(), array_merge(['vendor'], $this->config['excludes']))
) {
continue;
}

Expand All @@ -62,21 +67,23 @@ public function generateFromPath($path, $format = 'es6', $withVendor = false, $l
$fileinfo = new \SplFileInfo($fileName);

$noExt = $this->removeExtension($fileinfo->getFilename());
if (class_exists('App')) {
App::setLocale($noExt);
}
if ($noExt !== '') {
if (class_exists('App')) {
App::setLocale($noExt);
}

if ($fileinfo->isDir()) {
$local = $this->allocateLocaleArray($fileinfo->getRealPath());
} else {
$local = $this->allocateLocaleJSON($fileinfo->getRealPath());
if ($local === null) continue;
}
if ($fileinfo->isDir()) {
$local = $this->allocateLocaleArray($fileinfo->getRealPath());
} else {
$local = $this->allocateLocaleJSON($fileinfo->getRealPath());
if ($local === null) continue;
}

if (isset($locales[$noExt])) {
$locales[$noExt] = array_merge($local, $locales[$noExt]);
} else {
$locales[$noExt] = $local;
if (isset($locales[$noExt])) {
$locales[$noExt] = array_merge($local, $locales[$noExt]);
} else {
$locales[$noExt] = $local;
}
}
}

Expand Down Expand Up @@ -120,29 +127,30 @@ public function generateMultiple($path, $format = 'es6')
$jsBody = '';
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()
&& !in_array($fileinfo->getFilename(), ['vendor'])
&& !in_array($fileinfo->getFilename(), array_merge(['vendor'], $this->config['excludes']))
&& $fileinfo !== ''
) {
$noExt = $this->removeExtension($fileinfo->getFilename());
if (class_exists('App')) {
App::setLocale($noExt);
}
if (!in_array($noExt, $this->availableLocales)) {
$this->availableLocales[] = $noExt;
}
if ($fileinfo->isDir()) {
$local = $this->allocateLocaleArray($fileinfo->getRealPath());
} else {
$local = $this->allocateLocaleJSON($fileinfo->getRealPath());
if ($local === null) continue;
}
if ($noExt !== '') {
if (class_exists('App')) {
App::setLocale($noExt);
}
if (!in_array($noExt, $this->availableLocales)) {
$this->availableLocales[] = $noExt;
}
if ($fileinfo->isDir()) {
$local = $this->allocateLocaleArray($fileinfo->getRealPath());
} else {
$local = $this->allocateLocaleJSON($fileinfo->getRealPath());
if ($local === null) continue;
}

if (isset($locales[$noExt])) {
$locales[$noExt] = array_merge($local, $locales[$noExt]);
} else {
$locales[$noExt] = $local;
if (isset($locales[$noExt])) {
$locales[$noExt] = array_merge($local, $locales[$noExt]);
} else {
$locales[$noExt] = $local;
}
}


}
}
foreach ($this->filesToCreate as $fileName => $data) {
Expand Down
6 changes: 4 additions & 2 deletions src/config/vue-i18n-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@

/*
|--------------------------------------------------------------------------
| Excluded files
| Excluded files & folders
|--------------------------------------------------------------------------
|
| Exclude translation files you don't need.
| Exclude translation files, generic files or folders you don't need.
|
*/
'excludes' => [
/*
'validation',
'example.file',
'example-folder',
*/
],

Expand Down

0 comments on commit 056293f

Please sign in to comment.