Last active
October 11, 2023 11:17
-
-
Save aaronr0207/e67f5f347ac8070cf68348d2b7f64ce7 to your computer and use it in GitHub Desktop.
Busca y vuelca en un archivo txt las traducciones que se encuentran en los archivos de traducción y no se usan en un proyecto de laravel
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 = __DIR__; // directorio base para buscar | |
| $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)); | |
| $translationKeys = []; // claves de traducción utilizadas en el código | |
| foreach ($files as $file) { | |
| if ($file->getExtension() !== 'php' || strpos($file->getPathname(), 'vendor') !== false) { | |
| continue; | |
| } | |
| $content = file_get_contents($file->getPathname()); | |
| // buscar claves de traducción que incluyen el nombre del archivo | |
| preg_match_all('/__\(\'([a-zA-Z0-9_.]+)\'\)/', $content, $matches); | |
| preg_match_all('/__\("([a-zA-Z0-9_.]+)"\)/', $content, $matchesDoubleQuotes); | |
| $matches = array_merge($matches[1], $matchesDoubleQuotes[1]); | |
| foreach ($matches as $match) { | |
| $translationKeys[$match] = $file->getPathname(); | |
| } | |
| } | |
| $unusedTranslations = []; | |
| $translationFiles = glob($dir . '/resources/lang/es/*.php'); // cambiar 'es' a tu idioma principal | |
| foreach ($translationFiles as $file) { | |
| $translations = array_keys(include $file); | |
| foreach ($translations as $translation) { | |
| if (!isset($translationKeys[$translation]) && !isset($translationKeys[basename($file, '.php') . '.' . $translation])) { | |
| $unusedTranslations[] = $file .': '.$translation ; | |
| } | |
| } | |
| } | |
| file_put_contents('traducciones_sin_usar.txt', implode("\n", $unusedTranslations)); | |
| echo "Se han volcado las traducciones sin usar en el archivo: traducciones_sin_usar.txt\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment