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

Commit

Permalink
Make generateMultiple and allocateLocaleArray deterministic (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jellyfrog authored Feb 12, 2020
1 parent 8f47124 commit 0e29f04
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,39 @@ public function generateMultiple($path, $format = 'es6', $multiLocales = false)
$createdFiles = '';
$dir = new DirectoryIterator($path);
$jsBody = '';
$files = [];

foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot()
&& !in_array($fileinfo->getFilename(), array_merge(['vendor'], $this->config['excludes']))
&& $fileinfo !== ''
) {
$noExt = $this->removeExtension($fileinfo->getFilename());
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(), $multiLocales);
} else {
$local = $this->allocateLocaleJSON($fileinfo->getRealPath());
if ($local === null) continue;
}
$files[] = $fileinfo->getRealPath();
}
}
asort($files);

if (isset($locales[$noExt])) {
$locales[$noExt] = array_merge($local, $locales[$noExt]);
} else {
$locales[$noExt] = $local;
}
foreach ($files as $fileName) {
$fileinfo = new \SplFileInfo($fileName);
$noExt = $this->removeExtension($fileinfo->getFilename());
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(), $multiLocales);
} 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;
}
}
}
Expand Down Expand Up @@ -209,12 +217,19 @@ private function allocateLocaleArray($path, $multiLocales = false)
$data = [];
$dir = new DirectoryIterator($path);
$lastLocale = last($this->availableLocales);
$files = [];
foreach ($dir as $fileinfo) {
// Do not mess with dotfiles at all.
if ($fileinfo->isDot()) {
continue;
}

$files[] = $fileinfo->getRealPath();
}
asort($files);

foreach ($files as $fileName) {
$fileinfo = new \SplFileInfo($fileName);
if ($fileinfo->isDir()) {
// Recursivley iterate through subdirs, until everything is allocated.

Expand Down

0 comments on commit 0e29f04

Please sign in to comment.