Last active
August 29, 2015 14:12
-
-
Save techi602/463757be7c08212209dc to your computer and use it in GitHub Desktop.
Find unused translations for Shopio
This file contains 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 | |
/** | |
* for cygwin: | |
* set CYGWIN=nodosfilewarning | |
*/ | |
if (PHP_SAPI != 'cli') { | |
exit; | |
} | |
define('APPLICATION_PATH', str_replace('\\', '/', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR. '..' . DIRECTORY_SEPARATOR))); | |
array_map (function ($module) { | |
$translationDir = APPLICATION_PATH . '/data/www/modules/' . $module . '/translate/cs/'; | |
$files = glob($translationDir . '*.php'); | |
foreach ($files as $translateFile) { | |
$localFile = basename($translateFile); | |
if ($localFile[0] == '_') { | |
// skip prefixed files | |
continue; | |
} | |
$section = pathinfo($translateFile, PATHINFO_FILENAME); | |
$controllerNameTokens = explode('-', $section); | |
foreach ($controllerNameTokens as &$controllerNameToken) { | |
$controllerNameToken = ucfirst($controllerNameToken); | |
} | |
$controllerFile = implode('', $controllerNameTokens) . 'Controller.php'; | |
$translations = include $translateFile; | |
$translationKeys = array_keys($translations); | |
foreach ($translationKeys as $translationKey) { | |
$results = 0; | |
printf("\rSearching %s in %s...%s", $translationKey, $localFile, str_repeat(' ', 50)); | |
// check controller | |
$path = APPLICATION_PATH . '/data/www/modules/' . $module . '/controllers/' . $controllerFile; | |
if (!file_exists($path)) { | |
// skip helper translate files (i.e. connected-products) | |
continue; | |
} | |
$command = sprintf('grep -RI --include \*.php %s %s', $translationKey, $path); | |
exec($command, $output); | |
//print_r($output); | |
$results += count($output); | |
// check forms | |
$path = APPLICATION_PATH . '/data/www/modules/' . $module . '/forms/' . $section; | |
if (is_dir($path)) { | |
$command = sprintf('grep -RI --include \*.php %s %s', $translationKey, $path); | |
exec($command, $output); | |
$results += count($output); | |
} | |
// check twig templates | |
$path = APPLICATION_PATH . '/data/www/modules/' . $module . '/views/scripts/' . $section; | |
if (is_dir($path)) { | |
$command = sprintf('grep -RI %s %s', $translationKey, $path); | |
exec($command, $output); | |
$results += count($output); | |
} | |
if (empty($results)) { | |
printf("\r" . 'Keyword "%s" not found in translationFile "%s" in module "%s"' . "\n", $translationKey, $localFile, $module); | |
} | |
} | |
} | |
}, array('admin', 'default')); | |
printf("\r%s\n", str_repeat(' ', 50)); | |
exit; | |
/** | |
* for cygwin: | |
* set CYGWIN=nodosfilewarning | |
*/ | |
if (PHP_SAPI != 'cli') { | |
exit; | |
} | |
define('APPLICATION_PATH', str_replace('\\', '/', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR. '..' . DIRECTORY_SEPARATOR))); | |
$translationDir = APPLICATION_PATH . '/data/www/modules/default/translate/cs/'; | |
$files = glob($translationDir . '*.php'); | |
foreach ($files as $translateFile) { | |
$localFile = basename($translateFile); | |
$translations = include $translateFile; | |
$translationKeys = array_keys($translations); | |
foreach ($translationKeys as $translationKey) { | |
$command = sprintf('grep -RI --exclude-dir "%s" --exclude-dir ".git*" --include \*.php --include \*.twig --include \*.sql %s %s', 'translate*', $translationKey, APPLICATION_PATH . '/data'); | |
//echo $command . PHP_EOL; | |
printf("\rSearching %s in %s... ", $translationKey, $localFile); | |
exec($command, $output); | |
//print_r($output); | |
if (empty($output)) { | |
printf('Keyword "%s" not found in translationFile "%s"' . PHP_EOL, $translationKey, $localFile); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ještě to zkusím zjednodušit, že to bude hledat jen v controlleru + formulářích + šablonách pro daný controller (nikoliv v celém projektu) - takže to bude více striktní
Ikdyž někde se nám překlady používají i v modelech :)
_default a _js přeskočíme - jen pro ně by mělo hledání v celém projektu smysl