Attached Files |
language_pack_import_breaker.lang [^] (2,705 bytes) 2012-05-05 10:02
missing_phrase_breaks_multiple_language_import_513.patch [^] (8,136 bytes) 2012-05-05 10:03
[Show Content]
Index: language_import_helper.php
===================================================================
--- language_import_helper.php (revision 15158)
+++ language_import_helper.php (working copy)
@@ -593,6 +593,7 @@
if ($root_node->Children) {
$this->_processLanguages($root_node->firstChild);
+ $this->_processLanguageData($root_node->firstChild);
}
if ($this->_debugMode) {
@@ -723,8 +724,6 @@
}
do {
- $language_id = false;
-
$fields_hash = Array (
'PackName' => $language_node->Attributes['PACKNAME'],
'LocalName' => $language_node->Attributes['PACKNAME'],
@@ -748,16 +747,56 @@
do {
switch ($sub_node->Name) {
case 'PHRASES':
+ case 'EVENTS':
+ case 'COUNTRIES':
+ break;
+
+ case 'REPLACEMENTS':
+ // added since v2
+ $replacements = $sub_node->Data;
+
+ if ($fields_hash['Encoding'] != 'plain') {
+ $replacements = base64_decode($replacements);
+ }
+
+ $fields_hash['FilenameReplacements'] = $replacements;
+ break;
+
+ default:
+ if ($version == 1) {
+ $fields_hash[ $field_mapping[$sub_node->Name] ] = $sub_node->Data;
+ }
+ break;
+ }
+ } while (($sub_node =& $sub_node->NextSibling()));
+
+ $this->_processLanguage($fields_hash);
+ } while (($language_node =& $language_node->NextSibling()));
+ }
+
+ /**
+ * Processes parsed XML
+ *
+ * @param kXMLNode $language_node
+ */
+ function _processLanguageData(&$language_node)
+ {
+ do {
+ $encoding = $language_node->Attributes['ENCODING'];
+ $language_id = $this->_languages[crc32($language_node->Attributes['PACKNAME'])];
+
+ $sub_node =& $language_node->firstChild;
+ /* @var $sub_node kXMLNode */
+
+ do {
+ switch ($sub_node->Name) {
+ case 'PHRASES':
if ($sub_node->Children) {
- if (!$language_id) {
- $language_id = $this->_processLanguage($fields_hash);
- }
-
if ($this->_debugMode) {
$start_time = getmicrotime();
}
- $this->_processPhrases($sub_node->firstChild, $language_id, $fields_hash['Encoding']);
+ $this->_processPhrases($sub_node->firstChild, $language_id, $encoding);
if ($this->_debugMode) {
$this->Application->Debugger->appendHTML(__CLASS__ . '::' . '_processPhrases: ' . (getmicrotime() - $start_time));
@@ -767,40 +806,15 @@
case 'EVENTS':
if ($sub_node->Children) {
- if (!$language_id) {
- $language_id = $this->_processLanguage($fields_hash);
- }
-
- $this->_processEvents($sub_node->firstChild, $language_id, $fields_hash['Encoding']);
+ $this->_processEvents($sub_node->firstChild, $language_id, $encoding);
}
break;
case 'COUNTRIES':
if ($sub_node->Children) {
- if (!$language_id) {
- $language_id = $this->_processLanguage($fields_hash);
- }
-
- $this->_processCountries($sub_node->firstChild, $language_id, $fields_hash['Encoding']);
+ $this->_processCountries($sub_node->firstChild, $language_id, $encoding);
}
break;
-
- case 'REPLACEMENTS':
- // added since v2
- $replacements = $sub_node->Data;
-
- if ($fields_hash['Encoding'] != 'plain') {
- $replacements = base64_decode($replacements);
- }
-
- $fields_hash['FilenameReplacements'] = $replacements;
- break;
-
- default:
- if ($version == 1) {
- $fields_hash[ $field_mapping[$sub_node->Name] ] = $sub_node->Data;
- }
- break;
}
} while (($sub_node =& $sub_node->NextSibling()));
} while (($language_node =& $language_node->NextSibling()));
@@ -844,19 +858,21 @@
$column_translation = base64_decode($column_translation);
}
- if (array_key_exists($phrase_key, $other_translations)) {
- $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation;
- $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation;
- $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation;
+ if (!array_key_exists($phrase_key, $other_translations)) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$phrase_key] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$phrase_key]['l' . $other_language_id . '_Translation'] = '';
+ $other_translations[$phrase_key]['l' . $other_language_id . '_HintTranslation'] = '';
+ $other_translations[$phrase_key]['l' . $other_language_id . '_ColumnTranslation'] = '';
+ }
}
- else {
- $other_translations[$phrase_key] = Array (
- 'l' . $language_id . '_Translation' => $translation,
- 'l' . $language_id . '_HintTranslation' => $hint_translation,
- 'l' . $language_id . '_ColumnTranslation' => $column_translation,
- );
- }
+ $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation;
+ $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation;
+ $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation;
+
$fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]);
$this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false);
}
@@ -906,17 +922,19 @@
'MessageType' => $event_node->Attributes['MESSAGETYPE'],
);
- if (array_key_exists($event_id, $other_translations)) {
- $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject'];
- $other_translations[$event_id]['l' . $language_id . '_Body'] = $parsed['Body'];
+ if (!array_key_exists($event_id, $other_translations)) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$event_id] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$event_id]['l' . $other_language_id . '_Subject'] = '';
+ $other_translations[$event_id]['l' . $other_language_id . '_Body'] = '';
+ }
}
- else {
- $other_translations[$event_id] = Array (
- 'l' . $language_id . '_Subject' => $parsed['Subject'],
- 'l' . $language_id . '_Body' => $parsed['Body'],
- );
- }
+ $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject'];
+ $other_translations[$event_id]['l' . $language_id . '_Body'] = $parsed['Body'];
+
if ($parsed['Headers']) {
$other_translations[$event_id]['Headers'] = $parsed['Headers'];
}
@@ -970,15 +988,17 @@
'CountryStateId' => $country_state_id,
);
- if (array_key_exists($country_state_id, $other_translations)) {
- $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation;
+ if (!array_key_exists($country_state_id, $other_translations)) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$country_state_id] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$country_state_id]['l' . $other_language_id . '_Name'] = '';
+ }
}
- else {
- $other_translations[$country_state_id] = Array (
- 'l' . $language_id . '_Name' => $translation,
- );
- }
+ $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation;
+
$fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]);
$this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false);
@@ -1032,7 +1052,7 @@
// 4. collect ID of every processed language
if (!in_array($language_id, $this->_languages)) {
- $this->_languages[] = $language_id;
+ $this->_languages[crc32($fields_hash['PackName'])] = $language_id;
}
return $language_id;
missing_phrase_breaks_multiple_language_import_520.patch [^] (10,950 bytes) 2012-05-05 10:04
[Show Content]
Index: units/helpers/language_import_helper.php
===================================================================
--- units/helpers/language_import_helper.php (revision 15239)
+++ units/helpers/language_import_helper.php (working copy)
@@ -180,8 +180,6 @@
$this->_updateEventsCache();
}
- $this->_initImportTables();
-
$phrase_types = explode('|', substr($phrase_types, 1, -1) );
// $module_ids = explode('|', substr($module_ids, 1, -1) );
@@ -229,7 +227,8 @@
$phrase_types = explode('|', substr($phrase_types, 1, -1) );
$module_ids = explode('|', substr($module_ids, 1, -1) );
- $ret = '<LANGUAGES Version="' . $this->_latestVersion . '">' . "\n";
+ $ret = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
+ $ret .= '<LANGUAGES Version="' . $this->_latestVersion . '">' . "\n";
$export_fields = $this->_getExportFields();
@@ -780,8 +779,6 @@
}
foreach ($languages as $language_node) {
- $language_id = false;
-
$fields_hash = Array (
'PackName' => (string)$language_node['PackName'],
'LocalName' => (string)$language_node['PackName'],
@@ -804,29 +801,10 @@
/* @var $sub_node SimpleXMLElement */
if ( in_array($sub_node->getName(), $container_nodes) ) {
- // PHP 5.3 version would be: !$sub_node->count()
- if ( !count($sub_node->children()) ) {
continue;
- }
-
- if ( !$language_id ) {
- $language_id = $this->_processLanguage($fields_hash);
- }
}
switch ($sub_node->getName()) {
- case 'PHRASES':
- $this->_processPhrases($sub_node, $language_id, $fields_hash['Encoding']);
- break;
-
- case 'EVENTS':
- $this->_processEvents($sub_node, $language_id, $fields_hash['Encoding']);
- break;
-
- case 'COUNTRIES':
- $this->_processCountries($sub_node, $language_id, $fields_hash['Encoding']);
- break;
-
case 'REPLACEMENTS':
// added since v2
$replacements = (string)$sub_node;
@@ -851,10 +829,60 @@
break;
}
}
+
+ $this->_processLanguage($fields_hash);
}
+
+ $ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
+ /* @var $ml_helper kMultiLanguageHelper */
+
+ // create ML columns for new languages
+ $ml_helper->resetState();
+ $ml_helper->massCreateFields();
+
+ // create temp tables after new language columns were added
+ $this->_initImportTables();
}
/**
+ * Processes parsed XML
+ *
+ * @param SimpleXMLElement $languages
+ */
+ function _processLanguageData($languages)
+ {
+ foreach ($languages as $language_node) {
+ $encoding = (string)$language_node['Encoding'];
+ $language_id = $this->_languages[kUtil::crc32((string)$language_node['PackName'])];
+
+ $container_nodes = Array ('PHRASES', 'EVENTS', 'COUNTRIES');
+
+ foreach ($language_node as $sub_node) {
+ /* @var $sub_node SimpleXMLElement */
+
+ if ( !in_array($sub_node->getName(), $container_nodes) || !count($sub_node->children()) ) {
+ // PHP 5.3 version would be: !$sub_node->count()
+ continue;
+ }
+
+ switch ($sub_node->getName()) {
+ case 'PHRASES':
+ $this->_processPhrases($sub_node, $language_id, $encoding);
+ break;
+
+ case 'EVENTS':
+ $this->_processEvents($sub_node, $language_id, $encoding);
+ break;
+
+ case 'COUNTRIES':
+ $this->_processCountries($sub_node, $language_id, $encoding);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
* Decodes e-mail template design from language pack
*
* @param Array $fields_hash
@@ -912,19 +940,21 @@
$column_translation = base64_decode($column_translation);
}
- if ( array_key_exists($phrase_key, $other_translations) ) {
- $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation;
- $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation;
- $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation;
+ if ( !array_key_exists($phrase_key, $other_translations) ) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$phrase_key] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$phrase_key]['l' . $other_language_id . '_Translation'] = '';
+ $other_translations[$phrase_key]['l' . $other_language_id . '_HintTranslation'] = '';
+ $other_translations[$phrase_key]['l' . $other_language_id . '_ColumnTranslation'] = '';
+ }
}
- else {
- $other_translations[$phrase_key] = Array (
- 'l' . $language_id . '_Translation' => $translation,
- 'l' . $language_id . '_HintTranslation' => $hint_translation,
- 'l' . $language_id . '_ColumnTranslation' => $column_translation,
- );
- }
+ $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation;
+ $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation;
+ $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation;
+
$fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]);
$this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false);
}
@@ -981,19 +1011,21 @@
$parsed = $email_message_helper->parseTemplate($template, $message_type);
}
- if ( array_key_exists($event_id, $other_translations) ) {
- $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject'];
- $other_translations[$event_id]['l' . $language_id . '_HtmlBody'] = $parsed['HtmlBody'];
- $other_translations[$event_id]['l' . $language_id . '_PlainTextBody'] = $parsed['PlainTextBody'];
+ if ( !array_key_exists($event_id, $other_translations) ) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$event_id] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$event_id]['l' . $other_language_id . '_Subject'] = '';
+ $other_translations[$event_id]['l' . $other_language_id . '_HtmlBody'] = '';
+ $other_translations[$event_id]['l' . $other_language_id . '_PlainTextBody'] = '';
+ }
}
- else {
- $other_translations[$event_id] = Array (
- 'l' . $language_id . '_Subject' => $parsed['Subject'],
- 'l' . $language_id . '_HtmlBody' => $parsed['HtmlBody'],
- 'l' . $language_id . '_PlainTextBody' => $parsed['PlainTextBody'],
- );
- }
+ $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject'];
+ $other_translations[$event_id]['l' . $language_id . '_HtmlBody'] = $parsed['HtmlBody'];
+ $other_translations[$event_id]['l' . $language_id . '_PlainTextBody'] = $parsed['PlainTextBody'];
+
if ( $parsed['Headers'] ) {
$other_translations[$event_id]['Headers'] = $parsed['Headers'];
}
@@ -1051,13 +1083,18 @@
$fields_hash = Array ('CountryStateId' => $country_state_id);
- if ( array_key_exists($country_state_id, $other_translations) ) {
- $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation;
+
+ if ( !array_key_exists($country_state_id, $other_translations) ) {
+ // ensure translation in every language to make same column count in every insert
+ $other_translations[$country_state_id] = Array ();
+
+ foreach ($this->_languages as $other_language_id) {
+ $other_translations[$country_state_id]['l' . $other_language_id . '_Name'] = '';
+ }
}
- else {
- $other_translations[$country_state_id] = Array ('l' . $language_id . '_Name' => $translation);
- }
+ $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation;
+
$fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]);
$this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false);
@@ -1111,7 +1148,7 @@
// 4. collect ID of every processed language
if (!in_array($language_id, $this->_languages)) {
- $this->_languages[] = $language_id;
+ $this->_languages[kUtil::crc32($fields_hash['PackName'])] = $language_id;
}
return $language_id;
Index: units/helpers/multilanguage_helper.php
===================================================================
--- units/helpers/multilanguage_helper.php (revision 15165)
+++ units/helpers/multilanguage_helper.php (working copy)
@@ -21,6 +21,14 @@
class kMultiLanguageHelper extends kHelper {
/**
+ * Determines, that language info should be requeried
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $initMade = false;
+
+ /**
* Maximal language id
*
* @var int
@@ -61,18 +69,21 @@
*/
var $curFields = Array();
+ public function resetState()
+ {
+ $this->initMade = false;
+ }
+
/**
* Updates language count in system (always is divisible by 5)
*
*/
- protected function initLanguageCount()
+ protected function _queryLanguages()
{
- static $init_made = false;
-
- if (!$init_made) {
+ if ( !$this->initMade ) {
$this->languagesIDs = $this->getActualLanguages();
- $this->languageCount = max( max($this->languagesIDs), 5 );
- $init_made = true;
+ $this->languageCount = max(max($this->languagesIDs), 5);
+ $this->initMade = true;
}
}
@@ -83,10 +94,10 @@
*/
protected function getActualLanguages()
{
- $cache_key = 'language_ids[%LangSerial%]';
+ $cache_key = 'actual_language_ids[%LangSerial%]';
$ret = $this->Application->getCache($cache_key);
- if ($ret === false) {
+ if ( $ret === false ) {
$this->Conn->nextQueryCachable = true;
$sql = 'SELECT ' . $this->Application->getUnitOption('lang', 'IDField') . '
FROM ' . $this->Application->getUnitOption('lang', 'TableName');
@@ -116,20 +127,23 @@
*/
public function getLanguages()
{
- static $languages = null;
+ $cache_key = 'processable_language_ids[%LangSerial%]';
+ $ret = $this->Application->getCache($cache_key);
- if ( !isset($languages) ) {
- $languages = Array ();
- $this->initLanguageCount();
+ if ( $ret === false ) {
+ $ret = Array ();
+ $this->_queryLanguages();
for ($language_id = 1; $language_id <= $this->languageCount; $language_id++) {
if ( $this->LanguageFound($language_id) ) {
- $languages[] = $language_id;
+ $ret[] = $language_id;
}
}
+
+ $this->Application->setCache($cache_key, $ret);
}
- return $languages;
+ return $ret;
}
function scanTable($mask)
@@ -195,7 +209,7 @@
return ;
}
- $this->initLanguageCount();
+ $this->_queryLanguages();
$sqls = Array ();
$this->readTableStructure($table_name, $refresh);
language_data_not_imported_520.patch [^] (1,186 bytes) 2012-05-16 09:34
[Show Content]
Index: units/helpers/language_import_helper.php
===================================================================
--- units/helpers/language_import_helper.php (revision 15331)
+++ units/helpers/language_import_helper.php (working copy)
@@ -648,6 +648,7 @@
// PHP 5.3 version would be: $languages->count()
if ( count($languages->children()) ) {
$this->_processLanguages($languages);
+ $this->_processLanguageData($languages);
}
if ( $this->_debugMode ) {
@@ -833,12 +834,14 @@
$this->_processLanguage($fields_hash);
}
- $ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
- /* @var $ml_helper kMultiLanguageHelper */
+ if ( !defined('IS_INSTALL') || !IS_INSTALL ) {
+ $ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
+ /* @var $ml_helper kMultiLanguageHelper */
- // create ML columns for new languages
- $ml_helper->resetState();
- $ml_helper->massCreateFields();
+ // create ML columns for new languages
+ $ml_helper->resetState();
+ $ml_helper->massCreateFields();
+ }
// create temp tables after new language columns were added
$this->_initImportTables();
htmlspecialchars_breaks_down_language_pack.patch [^] (1,082 bytes) 2012-05-27 14:59
[Show Content]
Index: units/helpers/language_import_helper.php
===================================================================
--- units/helpers/language_import_helper.php (revision 15338)
+++ units/helpers/language_import_helper.php (working copy)
@@ -319,7 +319,7 @@
$ret .= "\t" . '<LANGUAGE Encoding="' . $this->_exportEncoding . '"';
foreach ($export_fields as $export_field) {
- $ret .= ' ' . $export_field . '="' . htmlspecialchars($language_info[$export_field]) . '"';
+ $ret .= ' ' . $export_field . '="' . htmlspecialchars($language_info[$export_field], NULL, 'UTF-8') . '"';
}
$ret .= '>' . "\n";
@@ -364,8 +364,8 @@
$column_translation = base64_encode($column_translation);
}
else {
- $hint_translation = htmlspecialchars($hint_translation);
- $column_translation = htmlspecialchars($column_translation);
+ $hint_translation = htmlspecialchars($hint_translation, NULL, 'UTF-8');
+ $column_translation = htmlspecialchars($column_translation, NULL, 'UTF-8');
}
$attributes = Array (
|