Created
June 12, 2023 00:34
-
-
Save Rene-Roscher/ac04627ae6357a05848ebb36ae3e98ca to your computer and use it in GitHub Desktop.
Laravel / Lang Fetch (For a structured lang folder / json)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $dir = 'resources/lang'; | |
| $exportFileName = 'export-en'; | |
| $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | |
| $files = array(); | |
| foreach ($iterator as $file) { | |
| if ($file->isFile() && in_array($file->getExtension(), ['json', 'php'])) { | |
| if ($file->getFilename() !== $exportFileName . '.json') { | |
| $files[] = $file->getPathname(); | |
| } | |
| } | |
| } | |
| $localeData = []; | |
| foreach ($files as $file) { | |
| if (pathinfo($file, PATHINFO_EXTENSION) === 'json') { | |
| $json = file_get_contents($file); | |
| $array = json_decode($json, true); | |
| foreach ($array as $key => $value) { | |
| if (is_string($value)) { | |
| $localeData[$key] = $value; | |
| } | |
| } | |
| } elseif (pathinfo($file, PATHINFO_EXTENSION) === 'php') { | |
| $array = include $file; | |
| foreach ($array as $key => $value) { | |
| if (is_string($value)) { | |
| $localeData[$key] = $value; | |
| } | |
| } | |
| } | |
| } | |
| $localeFile = sprintf('%s/%s.json', $dir, $exportFileName); | |
| file_put_contents($localeFile, json_encode($localeData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); | |
| echo "Mapping completed. Locale file '{$localeFile}' created."; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment