|
|
@@ -183,26 +183,44 @@ class BxDolStudioLanguagesUtils extends BxDolLanguages implements iBxDolSingleto
|
|
|
if(empty($aLanguage) || !is_array($aLanguage))
|
|
|
return false;
|
|
|
|
|
|
+ $aModulesToProcess = array();
|
|
|
+ $oModuleQuery = BxDolModuleQuery::getInstance();
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Get modules to be processed from language module.
|
|
|
+ */
|
|
|
$sPath = BX_DIRECTORY_PATH_MODULES . $aLanguageModule['path'] . 'data/langs/';
|
|
|
- if(!($rHandler = opendir($sPath)))
|
|
|
- return false;
|
|
|
+ if(($rHandler = opendir($sPath)) !== false) {
|
|
|
+ while(($sFileName = readdir($rHandler)) !== false) {
|
|
|
+ if($sFileName == '.' || $sFileName == '..')
|
|
|
+ continue;
|
|
|
|
|
|
- $oModuleQuery = BxDolModuleQuery::getInstance();
|
|
|
+ $aModule = $oModuleQuery->getModuleByName($sFileName);
|
|
|
+ if(empty($aModule) || !is_array($aModule))
|
|
|
+ continue;
|
|
|
|
|
|
- $bResult = false;
|
|
|
- while(($sFileName = readdir($rHandler)) !== false) {
|
|
|
- if($sFileName == '.' || $sFileName == '..')
|
|
|
- continue;
|
|
|
-
|
|
|
- $aModule = $oModuleQuery->getModuleByName($sFileName);
|
|
|
- if(empty($aModule) || !is_array($aModule))
|
|
|
- continue;
|
|
|
+ $aModulesToProcess[$aModule['name']] = $aModule;
|
|
|
+ }
|
|
|
|
|
|
- $bResult |= $this->_restoreLanguageByModule($aLanguage, $sPath, $aModule);
|
|
|
+ closedir($rHandler);
|
|
|
}
|
|
|
- closedir($rHandler);
|
|
|
|
|
|
- $bResult |= $this->_restoreLanguageByModule($aLanguage, $sPath, $aLanguageModule);
|
|
|
+ /*
|
|
|
+ * Get modules to be processed from a list of already installed modules.
|
|
|
+ */
|
|
|
+ $aModulesInstalled = $oModuleQuery->getModulesBy(array('type' => 'all_key_name'));
|
|
|
+ if(!empty($aModulesInstalled) && is_array($aModulesInstalled))
|
|
|
+ $aModulesToProcess = array_merge($aModulesToProcess, $aModulesInstalled);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Add language module itself.
|
|
|
+ */
|
|
|
+ $aModulesToProcess[$aLanguageModule['name']] = $aLanguageModule;
|
|
|
+
|
|
|
+ $bResult = false;
|
|
|
+ foreach($aModulesToProcess as $aModuleToProcess)
|
|
|
+ $bResult |= $this->_restoreLanguageByModule($aLanguage, $sPath, $aModuleToProcess);
|
|
|
+
|
|
|
return $bResult && ($bRecompile ? $this->compileLanguage($aLanguage['id']) : true);
|
|
|
}
|
|
|
|
|
|
@@ -214,7 +232,7 @@ class BxDolStudioLanguagesUtils extends BxDolLanguages implements iBxDolSingleto
|
|
|
$this->oDb->getLanguagesBy(array('type' => $sType, 'value' => $mixedLang), $aLanguages[0], false);
|
|
|
}
|
|
|
else
|
|
|
- $this->oDb->getLanguagesBy(array('type' => 'all'), $aLanguages, false);
|
|
|
+ $this->oDb->getLanguagesBy(array('type' => 'all'), $aLanguages, false);
|
|
|
|
|
|
$bResult = true;
|
|
|
foreach($aLanguages as $aLanguage) {
|
|
|
@@ -244,6 +262,46 @@ class BxDolStudioLanguagesUtils extends BxDolLanguages implements iBxDolSingleto
|
|
|
return $bResult;
|
|
|
}
|
|
|
|
|
|
+ function fixLanguage($mixedLang = 0, $bRecompile = true)
|
|
|
+ {
|
|
|
+ $aLanguages = array();
|
|
|
+ if(!empty($mixedLang)) {
|
|
|
+ $sType = is_string($mixedLang) && !is_numeric($mixedLang) ? 'by_name' : 'by_id';
|
|
|
+ $this->oDb->getLanguagesBy(array('type' => $sType, 'value' => $mixedLang), $aLanguages[0], false);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ $this->oDb->getLanguagesBy(array('type' => 'all'), $aLanguages, false);
|
|
|
+
|
|
|
+ foreach($aLanguages as $aLanguage) {
|
|
|
+ if(empty($aLanguage) || !is_array($aLanguage))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ $iLanguageId = (int)$aLanguage['id'];
|
|
|
+
|
|
|
+ $aKeys = array();
|
|
|
+ $this->oDb->getKeysBy(array('type' => 'autogenerated', 'language_id' => $iLanguageId, 'empty' => true), $aKeys);
|
|
|
+ if(empty($aKeys) || !is_array($aKeys))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ foreach($aKeys as $aKey) {
|
|
|
+ $sKey = preg_replace("/_[0-9]{8,10}$/i", '', $aKey['key']);
|
|
|
+ if(empty($sKey))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ $sString = '';
|
|
|
+ $aString = array();
|
|
|
+ $this->oDb->getStringsBy(array('type' => 'by_key_language_id', 'key' => $sKey, 'language_id' => $iLanguageId), $aString, false);
|
|
|
+ if(!empty($aString) && is_array($aString) && isset($aString['string']))
|
|
|
+ $sString = $aString['string'];
|
|
|
+
|
|
|
+ $this->addLanguageString($aKey['key'], $sString, $iLanguageId, 0, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($bRecompile)
|
|
|
+ $this->compileLanguage($iLanguageId, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function removeLanguageById($mixedLang = 0, $bRecompile = true)
|
|
|
{
|
|
|
$aLanguages = array();
|
|
|
@@ -440,7 +498,7 @@ class BxDolStudioLanguagesUtils extends BxDolLanguages implements iBxDolSingleto
|
|
|
if(empty($aModule) || !is_array($aModule) || !$aModule['name'] || !$aModule['lang_category'])
|
|
|
return true;
|
|
|
|
|
|
- $sPath = $sPath . $aModule['name'] . '/' . $aLanguage['name'] . '.xml';
|
|
|
+ $sPath = $sPath . $aModule['name'] . '/' . $aLanguage['name'] . '.xml';
|
|
|
if(!file_exists($sPath) && isset($aModule['path'])) {
|
|
|
$sPath = BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'install/langs/' . $aLanguage['name'] . '.xml';
|
|
|
if(!file_exists($sPath))
|