From 4ebc57ef6c3493078834c86e784478da0b7343c8 Mon Sep 17 00:00:00 2001 From: Harings Rob Date: Tue, 7 Apr 2020 21:18:07 +0200 Subject: [PATCH 1/2] Use full data array for generating locales. --- src/Generator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index 8055cb2..d71df30 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -160,7 +160,7 @@ public function generateMultiple($path, $format = 'es6', $multiLocales = false) foreach ($this->filesToCreate as $fileName => $data) { $fileToCreate = $jsPath . $fileName . '.js'; $createdFiles .= $fileToCreate . PHP_EOL; - $jsonLocales = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; + $jsonLocales = json_encode($locales[$fileName], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('Could not generate JSON, error code '.json_last_error()); } @@ -208,7 +208,6 @@ private function allocateLocaleArray($path, $multiLocales = false) { $data = []; $dir = new DirectoryIterator($path); - $lastLocale = last($this->availableLocales); foreach ($dir as $fileinfo) { // Do not mess with dotfiles at all. if ($fileinfo->isDot()) { @@ -222,6 +221,7 @@ private function allocateLocaleArray($path, $multiLocales = false) } else { $noExt = $this->removeExtension($fileinfo->getFilename()); $fileName = $path . DIRECTORY_SEPARATOR . $fileinfo->getFilename(); + $lastLocale = basename(dirname($fileName)); // Ignore non *.php files (ex.: .gitignore, vim swap files etc.) if (pathinfo($fileName, PATHINFO_EXTENSION) !== 'php') { From 3b8e8db0c008ed604ac51ca348a07980e911f440 Mon Sep 17 00:00:00 2001 From: Harings Rob Date: Tue, 7 Apr 2020 21:20:24 +0200 Subject: [PATCH 2/2] Ensure nesting. --- src/Generator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator.php b/src/Generator.php index d71df30..16c193d 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -160,7 +160,7 @@ public function generateMultiple($path, $format = 'es6', $multiLocales = false) foreach ($this->filesToCreate as $fileName => $data) { $fileToCreate = $jsPath . $fileName . '.js'; $createdFiles .= $fileToCreate . PHP_EOL; - $jsonLocales = json_encode($locales[$fileName], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; + $jsonLocales = json_encode([$fileName => $locales[$fileName]], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception('Could not generate JSON, error code '.json_last_error()); }