Skip to content

Instantly share code, notes, and snippets.

@techi602
Last active August 29, 2015 14:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save techi602/463757be7c08212209dc to your computer and use it in GitHub Desktop.
Find unused translations for Shopio
<?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);
}
}
}
@techi602
Copy link
Author

techi602 commented Jan 5, 2015

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

@mhujer
Copy link

mhujer commented Jan 6, 2015

Skoro jsi ho mohl dát private...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment