Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanilla-thunder/b6f2d3ed717a09e91514 to your computer and use it in GitHub Desktop.
Save vanilla-thunder/b6f2d3ed717a09e91514 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
$iLangId = 2; // Türkisch
$iFallbackLangId = 1; // Fallback language for oTrace Packages (usually 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();
$aMaybeMissingIdents = 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;
}
}
}
}
}
// search for lang strings in modules
$aModuleTpls = getDirContents( getShopBasePath() . "/modules" );
foreach ( $aModuleTpls as $sFile )
{
$sExtension = pathinfo( $sFile, PATHINFO_EXTENSION );
if( $sExtension == 'tpl' )
{
preg_match_all( "/(?=\[\{oxmultilang ident=\"([A-Z_-]*)\"\}\])|(?=\"([A-Z_-]*)\"\|oxmultilangassign)/", file_get_contents( $sFile ), $aModuleLangIdents );
if( !empty( $aModuleLangIdents[ 1 ][ 0 ] ) || !empty( $aModuleLangIdents[ 2 ][ 0 ] ) )
{
$aModuleLangIdents = array_merge( $aModuleLangIdents[ 1 ], $aModuleLangIdents[ 2 ] );
foreach ( $aModuleLangIdents 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 )
{
$translation = $oLang->translateString( $sLangIdent, $iLangId );
if( $translation === $sLangIdent )
{
$aMissingLangIdents[ $sLangIdent ] = $aFiles;
}
else if( $translation === $oLang->translateString( $sLangIdent, $iFallbackLangId ) );
{
$aMaybeMissingLangIdents[ $sLangIdent ] = $aFiles;
}
}
}
echo '<pre>';
if( !count( $aMissingLangIdents ) && !count( $aMaybeMissingLangIdents ) ) echo 'Congratulations! All lang idents are translated.';
else echo '<html><head><title>language ident debugger</title><style type="text/css"> table { margin: 15px; border-collapse: collapse; } tr:hover { background: #eee; } td { padding: 3px;}</style></head><body>';
if( count($aMissingLangIdents ) ) {
// output missing lang strings
echo '<h1>Missing Lang Idents: '.count( $aMissingLangIdents ).'<h1><table border="1"><colgroup><col width="350"/><col width="*"/></colgroup><tr><td><h3>Ident<h3></td><td><h3>Files where the lang ident occurs</h3></td></tr>';
foreach ($aMissingLangIdents as $sLangIdent => $aFiles)
{
echo "<tr><td valign='top'>$sLangIdent</td><td>" . str_replace( getShopBasePath(), "", implode( "<br/>", $aFiles ) )."</td></tr>";
}
echo "</table>";
}
if( count($aMaybeMissingLangIdents) )
{
// output maybe missing lang strings
echo '<h1>Lang idents equal to fallback language: '.count( $aMaybeMissingLangIdents ).'<h1><table border="1"><colgroup><col width="350"/><col width="*"/></colgroup><tr><td><h3>Ident<h3></td><td><h3>Files where the lang ident occurs</h3></td></tr>';
foreach ( $aMaybeMissingLangIdents as $sLangIdent => $aFiles )
{
echo "<tr><td valign='top'>$sLangIdent</td><td>" . str_replace( getShopBasePath(), "", implode( "<br/>", $aFiles ) )."</td></tr>";
}
echo "</table>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment