diff --git a/src/Polyglot.php b/src/Polyglot.php index f3ccdbf..913b7f2 100644 --- a/src/Polyglot.php +++ b/src/Polyglot.php @@ -24,21 +24,33 @@ public function __construct(Translator $translator) } /** - * Generate tranlation keys and export the trans function + * Compile translation files to array * - * @return String + * @return Array */ - public function generate() + public function compileTranslationFiles() { - $translations = []; - + // Get translation files $files = config('polyglot.files'); + $translations = []; + foreach ($files as $key => $file) { + // Load all translation keys filed under the translation file $translations[$file] = $this->translator->trans($file); } - $json = json_encode($translations); + return $translations; + } + + /** + * Generate tranlation keys and export the trans function + * + * @return String + */ + public function generate() + { + $json = json_encode($this->compileTranslationFiles()); $transFunction = file_get_contents(__DIR__ . '/dist/js/trans.min.js'); return <<