Skip to content

Instantly share code, notes, and snippets.

@Crease29
Last active February 19, 2016 10:15
Show Gist options
  • Save Crease29/ff59975221c4f6783f31 to your computer and use it in GitHub Desktop.
Save Crease29/ff59975221c4f6783f31 to your computer and use it in GitHub Desktop.
<?php
// ===================================================
// = place this file in the root of your OXID eShop! =
// ===================================================
require_once 'bootstrap.php';
// CONFIG
$sTheme = 'azure';
$iLangId = 0; // German
// $iLangId = 1; // English
// CONFIG END
/**
* Returns files of given $dir recursively.
*
* @param $dir
* @param array $results
*
* @see http://stackoverflow.com/a/24784144
*
* @return array
*/
function getDirContents( $dir, &$results = array() )
{
$files = scandir( $dir );
foreach ( $files as $key => $value )
{
$path = realpath( $dir . DIRECTORY_SEPARATOR . $value );
if ( !is_dir( $path ) )
{
$results[] = $path;
}
else
{
if ( $value != "." && $value != ".." )
{
getDirContents( $path, $results );
$results[] = $path;
}
}
}
return $results;
}
// delete lang cache from tmp
$aLangCaches = glob( getShopBasePath() . '/tmp/oxpec_langcache_*.txt' );
if( count( $aLangCaches ) )
{
foreach ( $aLangCaches as $sLangCache )
{
unlink( $sLangCache );
}
}
$aFiles = getDirContents( getShopBasePath() . "/application/views/$sTheme/tpl" );
if( count( $aFiles ) )
{
$aAllLangIdents = array();
$aMissingLangIdents = array();
$i = 0;
// search for lang strings
foreach ( $aFiles as $sFile )
{
$sExtension = pathinfo( $sFile, PATHINFO_EXTENSION );
if( $sExtension == 'tpl' )
{
preg_match_all( "/(?=\[\{oxmultilang ident=\"([A-Z_-]*)\"\}\])|(?=\"([A-Z_-]*)\"\|oxmultilangassign)/", file_get_contents( $sFile ), $aLangIdents );
if( !empty( $aLangIdents[ 1 ][ 0 ] ) || !empty( $aLangIdents[ 2 ][ 0 ] ) )
{
$aLangIdents = array_merge( $aLangIdents[ 1 ], $aLangIdents[ 2 ] );
foreach ( $aLangIdents as $sLangIdent )
{
if( !empty( $sLangIdent ) )
{
if( !isset( $aAllLangIdents[ $sLangIdent ] ) )
{
$aAllLangIdents[ $sLangIdent ] = array();
}
$aAllLangIdents[ $sLangIdent ][] = $sFile;
}
}
}
}
}
if( count( $aAllLangIdents ) )
{
$oLang = oxRegistry::getLang();
$oLang->setBaseLanguage( $iLangId );
$oLang->setTplLanguage( $iLangId );
// check found lang strings
foreach ( $aAllLangIdents as $sLangIdent => $aFiles )
{
if( $oLang->translateString( $sLangIdent, $iLangId ) === $sLangIdent )
{
$aMissingLangIdents[ $sLangIdent ] = $aFiles;
}
}
}
echo '<pre>';
if( count( $aMissingLangIdents ) )
{
// output missing lang strings
echo str_pad( 'Lang ident', 64, ' ' ) . "\tFiles where the lang ident occurs\n\n";
foreach ( $aMissingLangIdents as $sLangIdent => $aFiles )
{
echo str_pad( $sLangIdent, 64, ' ' ) . "\t" . str_replace( getShopBasePath(), '', implode( ', ', $aFiles ) ) . "\n";
}
}
else
{
echo 'Congratulations! All lang idents are translated.';
}
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment