// Improved localization pack import at the installation #PSCFV-4404

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17547 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dMetzger
2012-09-26 08:12:54 +00:00
parent 1dbbcbebab
commit 1b4a2e0504
3 changed files with 91 additions and 64 deletions

View File

@@ -718,14 +718,18 @@ class LanguageCore extends ObjectModel
else
Language::_copyNoneFlag($insert_id);
$files_copy = array('/en.jpg', '/en-default-thickbox.jpg', '/en-default-home.jpg', '/en-default-large.jpg', '/en-default-medium.jpg', '/en-default-small.jpg', '/en-default-large_scene.jpg');
$tos = array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_);
foreach ($tos as $to)
$files_copy = array(
'/en.jpg',
'/en-default-thickbox_default.jpg',
'/en-default-home_default.jpg',
'/en-default-large_default.jpg',
'/en-default-medium_default.jpg',
'/en-default-small_default.jpg',
'/en-default-scene_default.jpg'
);
foreach (array(_PS_CAT_IMG_DIR_, _PS_MANU_IMG_DIR_, _PS_PROD_IMG_DIR_, _PS_SUPP_IMG_DIR_) as $to)
foreach ($files_copy as $file)
{
$name = str_replace('/en', '/'.$iso_code, $file);
copy(dirname(__FILE__).'/../img/l'.$file, $to.$name);
}
@copy(dirname(__FILE__).'/../img/l'.$file, $to.str_replace('/en', '/'.$iso_code, $file));
return true;
}
else

View File

@@ -53,9 +53,7 @@ class LocalizationPackCore
$res &= $this->installConfiguration($xml);
$res &= $this->installModules($xml);
$res &= $this->updateDefaultGroupDisplayMethod($xml);
if (!defined('_PS_MODE_DEV_') || !_PS_MODE_DEV_)
$res &= $this->_installLanguages($xml, $install_mode);
$res &= $this->_installLanguages($xml, $install_mode);
if ($res && isset($this->iso_code_lang))
{
@@ -158,9 +156,9 @@ class LocalizationPackCore
$tax->rate = (float)$attributes['rate'];
$tax->active = 1;
if (!$tax->validateFields())
if ($error = $tax->validateFields(false, true) || $error = $tax->validateFieldsLang(false, true))
{
$this->_errors[] = Tools::displayError('Invalid tax properties.');
$this->_errors[] = Tools::displayError('Invalid tax properties.').' '.$error;
return false;
}
@@ -301,44 +299,40 @@ class LocalizationPackCore
$native_iso_code = array();
foreach ($native_lang as $lang)
$native_iso_code[] = $lang['iso_code'];
if ((in_array((string)$attributes['iso_code'], $native_iso_code) && !$install_mode)
|| !in_array((string)$attributes['iso_code'], $native_iso_code))
// if we are not in an installation context or if the pack is not available in the local directory
if (!$install_mode || !in_array((string)$attributes['iso_code'], $native_iso_code))
{
$errno = 0;
$errstr = '';
if (@fsockopen('api.prestashop.com', 80, $errno, $errstr, 10))
if (!@fsockopen('api.prestashop.com', 80, $errno, $errstr, 5))
$this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
elseif (!($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code']))))
$this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
elseif ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.$attributes['iso_code'].'.gzip'))
{
if ($lang_pack = Tools::jsonDecode(Tools::file_get_contents('http://www.prestashop.com/download/lang_packs/get_language_pack.php?version='._PS_VERSION_.'&iso_lang='.$attributes['iso_code'])))
$file = _PS_TRANSLATIONS_DIR_.$attributes['iso_code'].'.gzip';
if (file_put_contents($file, $content))
{
if ($content = Tools::file_get_contents('http://translations.prestashop.com/download/lang_packs/gzip/'.$lang_pack->version.'/'.$attributes['iso_code'].'.gzip'))
$gz = new Archive_Tar($file, true);
if (!$gz->extract(_PS_TRANSLATIONS_DIR_.'../', false))
{
$file = _PS_TRANSLATIONS_DIR_.$attributes['iso_code'].'.gzip';
if (file_put_contents($file, $content))
{
$gz = new Archive_Tar($file, true);
if (!$gz->extract(_PS_TRANSLATIONS_DIR_.'../', false))
{
$this->_errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ').(string)$attributes['iso_code'];
return false;
}
if (!Language::checkAndAddLanguage((string)$attributes['iso_code']))
{
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ').(string)$attributes['iso_code'];
return false;
}
@unlink($file);
}
else
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
$this->_errors[] = Tools::displayError('Cannot decompress the translation file for the following language: ').(string)$attributes['iso_code'];
return false;
}
if (!Language::checkAndAddLanguage((string)$attributes['iso_code']))
{
$this->_errors[] = Tools::displayError('An error occurred while creating the language: ').(string)$attributes['iso_code'];
return false;
}
@unlink($file);
}
else
$this->_errors[] = Tools::displayError('Error occurred when language was checked according to your Prestashop version.');
$this->_errors[] = Tools::displayError('Server does not have permissions for writing.');
}
else
$this->_errors[] = Tools::displayError('Archive cannot be downloaded from prestashop.com.');
}
}
// change the default language if there is only one language in the localization pack

View File

@@ -1,23 +1,52 @@
<?xml version="1.0" encoding="UTF-8" ?>
<localizationPack name="Ukraine" version="1.0">
<currencies>
<currency name="Hryvnia" iso_code="UAH" iso_code_num="980" sign="₴" blank="1" conversion_rate="10.8304" format="2" decimals="1" />
</currencies>
<languages>
<language iso_code="uk" />
</languages>
<taxes>
<tax id="1" name="ПДВ UA 20%" rate="20" />
<taxRulesGroup name="UA Standard Rate (20%)">
<taxRule iso_code_country="ua" id_tax="1" />
</taxRulesGroup>
</taxes>
<units>
<unit type="weight" value="kg" />
<unit type="volume" value="L" />
<unit type="short_distance" value="cm" />
<unit type="base_distance" value="m" />
<unit type="long_distance" value="km" />
</units>
</localizationPack>
<?xml version="1.0" encoding="UTF-8" ?>
<localizationPack name="Ukraine" version="1.0">
<currencies>
<currency name="Гривна" iso_code="UAH" iso_code_num="980" sign="₴" blank="1" conversion_rate="1" format="2" decimals="1" />
<currency name="Евро" iso_code="EUR" iso_code_num="978" sign="€" blank="1" conversion_rate="0.09396" format="2" decimals="1" />
<currency name="Доллар" iso_code="USD" iso_code_num="840" sign="$" blank="0" conversion_rate="0.12315" format="1" decimals="1" />
</currencies>
<languages>
<language iso_code="ru" />
</languages>
<taxes>
<tax id="1" name="НДС 20%" rate="20" />
<taxRulesGroup name="НДС (20%)">
<taxRule iso_code_country="ua" id_tax="1" />
</taxRulesGroup>
</taxes>
<states>
<state name="Винницкая область" iso_code="05" country="UA" zone="Europe" />
<state name="Волынская область" iso_code="07" country="UA" zone="Europe" />
<state name="Днепропетровская область" iso_code="12" country="UA" zone="Europe" />
<state name="Донецкая область" iso_code="14" country="UA" zone="Europe" />
<state name="Житомирская область" iso_code="18" country="UA" zone="Europe" />
<state name="Закарпатская область" iso_code="21" country="UA" zone="Europe" />
<state name="Запорожская область" iso_code="23" country="UA" zone="Europe" />
<state name="Ивано-Франковская область" iso_code="26" country="UA" zone="Europe" />
<state name="Киевская область" iso_code="32" country="UA" zone="Europe" />
<state name="Кировоградская область" iso_code="35" country="UA" zone="Europe" />
<state name="Луганская область" iso_code="09" country="UA" zone="Europe" />
<state name="Львовская область" iso_code="46" country="UA" zone="Europe" />
<state name="Николаевская область" iso_code="48" country="UA" zone="Europe" />
<state name="Одесская область" iso_code="51" country="UA" zone="Europe" />
<state name="Полтавская область" iso_code="53" country="UA" zone="Europe" />
<state name="Ровненская область" iso_code="19" country="UA" zone="Europe" />
<state name="Сумская область" iso_code="59" country="UA" zone="Europe" />
<state name="Тернопольская область" iso_code="61" country="UA" zone="Europe" />
<state name="Харьковская область" iso_code="63" country="UA" zone="Europe" />
<state name="Херсонская область" iso_code="65" country="UA" zone="Europe" />
<state name="Хмельницкая область" iso_code="68" country="UA" zone="Europe" />
<state name="Черкасская область" iso_code="71" country="UA" zone="Europe" />
<state name="Черниговская область" iso_code="74" country="UA" zone="Europe" />
<state name="Черновицкая область" iso_code="77" country="UA" zone="Europe" />
<state name="Автономная Республика Крым" iso_code="43" country="UA" zone="Europe" />
</states>
<units>
<unit type="weight" value="кг" />
<unit type="volume" value="л" />
<unit type="short_distance" value="см" />
<unit type="base_distance" value="м" />
<unit type="long_distance" value="км" />
</units>
</localizationPack>