diff --git a/admin-dev/themes/template/translations/main.tpl b/admin-dev/themes/template/translations/main.tpl new file mode 100644 index 000000000..6cdf35738 --- /dev/null +++ b/admin-dev/themes/template/translations/main.tpl @@ -0,0 +1,165 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + + +
{l s='Modify translations'} + {l s='Here you can modify translations for all text input into PrestaShop.'}
+ {l s='First, select a section (such as Back Office or Modules), then click the flag representing the language you want to edit.'}

+
+ + + + {foreach $languages as $language} + + {$language['iso_code']} + + {/foreach} + +
+
+ +

{l s='Translation exchange'}

+
+
+ + {l s='Add / Update a language'} + +
+

{l s='You can add or update a language directly from prestashop.com here'}

+
+ + {l s='If you choose to update an existing language pack, all your previous customization in the theme named prestashop will be lost. This includes front office expressions and default e-mail templates.'} +
+ {if $packs_to_update || $packs_to_install} +
{l s='Language you want to add or update:'} +   + +
+ {else} +

{l s='Cannot connect to prestashop.com to get languages list.'}

+ {/if} + +
+


+ +
+
+ + {l s='Import a language pack manually'} + +
+ {l s='If the name format is: isocode.gzip (e.g. fr.gzip) and the language corresponding to this package does not exist, it will automatically be created.'} + {l s='Be careful, as it will replace all existing data for the destination language!'}

+ {l s='Language pack to import:'}  

+
+
+
+

+ +
+
+ {l s='Export a language'} +

{l s='Export data from one language to a file (language pack).'}
+ {l s='Choose the theme from which you want to export translations.'}
+ +     +    + +

+
+

+
+
+ {l s='Copy'} +

{l s='Copies data from one language to another.'}
+ {l s='Be careful, as it will replace all existing data for the destination language!'}
+ {l s='If necessary'}, {l s='first create a new language'}.

+
+

+

{l s='From:'}
+ +     + * +

+

+

{l s='To:'}
+ +     + +

+
+
+ +
+

* {l s='Language files (as indicated at Tools >> Languages >> Edition) must be complete to allow copying of translations'}

+
+
\ No newline at end of file diff --git a/admin-dev/themes/template/translations/translation_errors.tpl b/admin-dev/themes/template/translations/translation_errors.tpl new file mode 100644 index 000000000..5c7a47786 --- /dev/null +++ b/admin-dev/themes/template/translations/translation_errors.tpl @@ -0,0 +1,46 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{l s='Language'} : {$lang} - {$translation_type}

+{l s='Errors to translate'} : {$count} +{$limit_warning} +{if !$suoshin_exceeded} +
+ {$auto_translate} + + +

+ + {foreach $errorsArray as $key => $value} + + + + + {/foreach} +
{$key|stripslashes}=

+ +
+{/if} \ No newline at end of file diff --git a/admin-dev/themes/template/translations/translation_form.tpl b/admin-dev/themes/template/translations/translation_form.tpl new file mode 100644 index 000000000..72157e570 --- /dev/null +++ b/admin-dev/themes/template/translations/translation_form.tpl @@ -0,0 +1,74 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{l s='Language'} : {$lang} - {$translation_type}

+{l s='Expressions to translate'} : {$count}. {l s='Click on the titles to open fieldsets'}.

+{$limit_warning} +{if !$suoshin_exceeded} +
+ {$toggle_button} + {$auto_translate} + + +

+ {foreach $tabsArray as $k => $newLang} + {if !empty($newLang)} + {$occurrences = $newLang|array_count_values} + {if isset($occurrences[''])} + {$missing_translations = $occurrences['']} + {else} + {$missing_translations = 0} + {/if} +
+ {$k} - {$newLang|count} {l s='expressions'} ({$missing_translations}) +
+ + {foreach $newLang as $key => $value} + + + + + {/foreach} +
{$key|stripslashes}= + {if $key|strlen < $textarea_sized} + + {else} + + {/if} +
+
+

+ {/if} + {/foreach} +
+{/if} \ No newline at end of file diff --git a/admin-dev/themes/template/translations/translation_mails.tpl b/admin-dev/themes/template/translations/translation_mails.tpl new file mode 100644 index 000000000..1e3fc733d --- /dev/null +++ b/admin-dev/themes/template/translations/translation_mails.tpl @@ -0,0 +1,63 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{$tinyMCE} + +

{l s='Language'} : {$lang} - {$translation_type}

+{l s='Click on the titles to open fieldsets'}.

+{if !$suoshin_exceeded} +
+ {$toggle_button} + + + + +

+ + {l s='Core e-mails:'} + {$mail_content} + + {l s='Modules e-mails:'} + {foreach $module_mails as $module_name => $mails} + {$mails['display']} + {/foreach} + + {if !empty($theme_mails)} + {l s='Themes e-mails:'} + {$bool_title = false} + {foreach $theme_mails as $theme_or_module_name => $mails} + {if $theme_or_module_name != 'theme_mail' && !$bool_title} + {$bool_title = true} + {l s='E-mails modules in theme:'} + {/if} + {$mails['display']} + {/foreach} + {/if} +
+ + +
+{/if} \ No newline at end of file diff --git a/admin-dev/themes/template/translations/translation_modules.tpl b/admin-dev/themes/template/translations/translation_modules.tpl new file mode 100644 index 000000000..766064eb0 --- /dev/null +++ b/admin-dev/themes/template/translations/translation_modules.tpl @@ -0,0 +1,94 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{l s='Language'} : {$lang} - {$translation_type}

+{l s='Expressions to translate'} : {$count}. {l s='Click on the titles to open fieldsets'}.

+{$limit_warning} +{if !$suoshin_exceeded} +
+ {$toggle_button} + {$auto_translate} + + +

+ + {if count($modules_translations) > 1} +

{l s='List of Themes - Click to access theme translation:'}

+ + {/if} + + {foreach $modules_translations as $theme_name => $theme} +

>{l s='Theme:'} {if $theme_name === $default_theme_name}{l s='default'}{else}{$theme_name}{/if}

+ {foreach $theme as $module_name => $module} + {l s='Module:'} {$module_name} + {foreach $module as $template_name => $newLang} + {if !empty($newLang)} + {$occurrences = $newLang|array_count_values} + {if isset($occurrences[''])} + {$missing_translations = $occurrences['']} + {else} + {$missing_translations = 0} + {/if} +
+ {if $theme_name === 'default'}{l s='default'}{else}{$theme_name}{/if} - {$template_name} + {$newLang|count} {l s='expressions'} ({$missing_translations}) + +
+ + {foreach $newLang as $key => $value} + + + + + {/foreach} +
{$key|stripslashes}= + {* Prepare name string for md5() *} + {capture assign="name"}{strtolower($module_name)}_{strtolower($theme_name)}_{strtolower($template_name)}_{md5($key)}{/capture} + {if $key|strlen < $textarea_sized} + + {else} + + {/if} +
+
+

+ {/if} + {/foreach} + {/foreach} + {/foreach} +
+{/if} \ No newline at end of file diff --git a/controllers/admin/AdminReturnController.php b/controllers/admin/AdminReturnController.php index bcfadba1c..cf66b5da9 100644 --- a/controllers/admin/AdminReturnController.php +++ b/controllers/admin/AdminReturnController.php @@ -156,6 +156,7 @@ class AdminReturnControllerCore extends AdminController public function initToolbar() { + // If display list, we don't want the "add" button if (!$this->display) return; parent::initToolbar(); diff --git a/admin-dev/tabs/AdminTranslations.php b/controllers/admin/AdminTranslationsController.php similarity index 69% rename from admin-dev/tabs/AdminTranslations.php rename to controllers/admin/AdminTranslationsController.php index c19ecb5c2..58abc87f9 100644 --- a/admin-dev/tabs/AdminTranslations.php +++ b/controllers/admin/AdminTranslationsController.php @@ -25,14 +25,12 @@ * International Registered Trademark & Property of PrestaShop SA */ -include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php'); include_once(_PS_ADMIN_DIR_.'/../tools/tar/Archive_Tar.php'); include_once(_PS_ADMIN_DIR_.'/../tools/pear/PEAR.php'); define ('TEXTAREA_SIZED', 70); -class AdminTranslations extends AdminTab +class AdminTranslationsControllerCore extends AdminController { - protected $link_lang_pack = 'http://www.prestashop.com/download/lang_packs/get_each_language_pack.php'; protected $total_expression = 0; protected $all_iso_lang = array(); @@ -56,6 +54,58 @@ class AdminTranslations extends AdminTab self::$php_regexp = '/->l\(\''._PS_TRANS_PATTERN_.'\'(, ?\'(.+)\')?(, ?(.+))?\)/U'; } + public function initContent() + { + if ($type = Tools::getValue('type')) + $this->content .= $this->{'initForm'.ucfirst($type)}(Tools::strtolower(Tools::getValue('lang'))); + else + $this->content .= $this->initMain(); + + $this->context->smarty->assign(array('content' => $this->content)); + } + + public function initMain() + { + // Block modify + $translations = array( + 'front' => $this->l('Front Office translations'), + 'back' => $this->l('Back Office translations'), + 'errors' => $this->l('Error message translations'), + 'fields' => $this->l('Field name translations'), + 'modules' => $this->l('Module translations'), + 'pdf' => $this->l('PDF translations'), + 'mails' => $this->l('E-mail template translations'), + ); + + // Block add/update + $packs_to_install = array(); + $packs_to_update = array(); + if ($lang_packs = Tools::file_get_contents($this->link_lang_pack .'?version='._PS_VERSION_, false, @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5))))) + // Notice : for php < 5.2 compatibility, Tools::jsonDecode. The second parameter to true will set us + if ($lang_packs != '' AND $lang_packs = Tools::jsonDecode($lang_packs,true)) + foreach($lang_packs as $key => $lang_pack) + { + if (!Language::isInstalled($lang_pack['iso_code'])) + $packs_to_install[$key] = $lang_pack; + else + $packs_to_update[$key] = $lang_pack; + } + + $this->context->smarty->assign(array( + 'theme_lang_dir' =>_THEME_LANG_DIR_, + 'token' => $this->token, + 'languages' => Language::getLanguages(false), + 'translations' => $translations, + 'packs_to_install' => $packs_to_install, + 'packs_to_update' => $packs_to_update, + 'url_submit' => self::$currentIndex.'&token='.$this->token, + 'themes' => $themes = self::getThemesList(), + 'url_create_language' => 'index.php?tab=AdminLanguages&addlang&token='.Tools::getAdminToken('AdminLanguages'.(int)(Tab::getIdFromClassName('AdminLanguages')).(int)$this->context->employee->id), + )); + + return $this->context->smarty->fetch('translations/main.tpl'); + } + /** * This method merge each arrays of modules translation in * the array of modules translations @@ -188,6 +238,7 @@ class AdminTranslations extends AdminTab } return $bool_flag; } + public function submitExportLang() { $lang = strtolower(Tools::getValue('iso_code')); @@ -431,7 +482,7 @@ class AdminTranslations extends AdminTab return; } /* PrestaShop demo mode*/ - + if (Tools::isSubmit('submitCopyLang')) { if ($this->tabAccess['add'] === '1') @@ -471,7 +522,7 @@ class AdminTranslations extends AdminTab else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } - elseif (Tools::isSubmit('submitTranslationsPDF')) + elseif (Tools::isSubmit('submitTranslationsPdf')) { if ($this->tabAccess['edit'] === '1') { @@ -560,6 +611,7 @@ class AdminTranslations extends AdminTab $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } } + protected function getMailPattern() { // Let the indentation like it. @@ -683,157 +735,6 @@ class AdminTranslations extends AdminTab if (count($this->_errors) == 0) Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token.$params_redirect); } - public function display() - { - $translations = array( - 'front' => $this->l('Front Office translations'), - 'back' => $this->l('Back Office translations'), - 'errors' => $this->l('Error message translations'), - 'fields' => $this->l('Field name translations'), - 'modules' => $this->l('Module translations'), - 'pdf' => $this->l('PDF translations'), - 'mails' => $this->l('E-mail template translations'), - ); - - if ($type = Tools::getValue('type')) - $this->{'displayForm'.ucfirst($type)}(Tools::strtolower(Tools::getValue('lang'))); - else - { - $languages = Language::getLanguages(false); - echo '
'.$this->l('Modify translations').''. - $this->l('Here you can modify translations for all text input into PrestaShop.').'
'. - $this->l('First, select a section (such as Back Office or Modules), then click the flag representing the language you want to edit.').'

-
- - - '; - foreach ($languages AS $language) - echo ' - '.$language['iso_code'].' - '; - echo '
-

'.$this->l('Translation exchange').'

'; - echo '
-
- - '.$this->l('Add / Update a language').' - -

'.$this->l('You can add or update a language directly from prestashop.com here').'

'; - $this->displayWarning($this->l('If you choose to update an existing language pack, all your previous customization in the theme named prestashop will be lost. This includes front office expressions and default e-mail templates.')); - echo '
'.$this->l('Language you want to add or update:').' '; - - if ($lang_packs = Tools::file_get_contents($this->link_lang_pack .'?version='._PS_VERSION_, false, @stream_context_create(array('http' => array('method' => 'GET', 'timeout' => 5))))) - { - // Notice : for php < 5.2 compatibility, Tools::jsonDecode. The second parameter to true will set us - if ($lang_packs != '' AND $lang_packs = Tools::jsonDecode($lang_packs,true)) - { - echo ' -  '; - } - echo '
'; - } - else - echo '

'.$this->l('Cannot connect to prestashop.com to get languages list.').'

'; - echo ' -
-


'; - echo '
-
- - '.$this->l('Import a language pack manually').' - -
'. - $this->l('If the name format is: isocode.gzip (e.g. fr.gzip) and the language corresponding to this package does not exist, it will automatically be created.'). - $this->l('Be careful, as it will replace all existing data for the destination language!').'

'. - $this->l('Language pack to import:').'  

-
-
-
-

-
-
'.$this->l('Export a language').' -

'.$this->l('Export data from one language to a file (language pack).').'
'. - $this->l('Choose the theme from which you want to export translations.').'
- -     -    - -

-
-

'; - $allLanguages = Language::getLanguages(false); - echo ' -
-
'.$this->l('Copy').' -

'.$this->l('Copies data from one language to another.').'
'. - $this->l('Be careful, as it will replace all existing data for the destination language!').'
'. - $this->l('If necessary').', '.$this->l('first create a new language').'.

-
-

-

'.$this->l('From:').'
- -     - * -

-

-

'.$this->l('To:').'
- -     - -

-
-
- -
-

* '.$this->l('Language files (as indicated at Tools >> Languages >> Edition) must be complete to allow copying of translations').'

-
-
'; - } - } public function fileExists($dir, $file, $var) { @@ -948,7 +849,7 @@ class AdminTranslations extends AdminTab return $str_output; } - public function displayFormFront($lang) + public function initFormFront($lang) { $_LANG = $this->fileExists(_PS_THEME_DIR_.'lang', Tools::strtolower($lang).'.php', '_LANG'); $str_output = ''; @@ -956,7 +857,7 @@ class AdminTranslations extends AdminTab /* List templates to parse */ $templates = array_merge(scandir(_PS_THEME_DIR_), scandir(_PS_ALL_THEMES_DIR_)); $count = 0; - $files = array(); + $tabsArray = array(); foreach ($templates AS $template) if (preg_match('/^(.*).tpl$/', $template) AND (file_exists($tpl = _PS_THEME_DIR_.$template) OR file_exists($tpl = _PS_ALL_THEMES_DIR_.$template))) { @@ -983,66 +884,42 @@ class AdminTranslations extends AdminTab $newLang[$key] = (key_exists($key2, $_LANG)) ? html_entity_decode($_LANG[$key2], ENT_COMPAT, 'UTF-8') : ''; } } - $files[$template2] = $newLang; + $tabsArray[$template2] = $newLang; $count += sizeof($newLang); } - $str_output .= ' -

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('Front-Office translations').'

- '.$this->l('Total expressions').' : '.$count.'. '.$this->l('Click the fieldset title to expand or close the fieldset.').'.

'; - $str_output .= $this->displayLimitPostWarning($count); - if (!$this->suhosin_limit_exceed) - { - $str_output .= ' -
'; - $str_output .= $this->displayToggleButton(sizeof($_LANG) >= $count); - $str_output .= $this->displayAutoTranslate(); - $str_output .= '

'; - foreach ($files AS $k => $newLang) - if (sizeof($newLang)) - { - $countValues = array_count_values($newLang); - $empty = isset($countValues['']) ? $countValues[''] : 0; - $str_output .= ' -
'.$k.' - '.sizeof($newLang).' '.$this->l('expressions').' ('.$empty.') -
- '; - foreach ($newLang AS $key => $value) - { - $str_output .= ''; - } - $str_output .= ' -
'.stripslashes($key).''; - if (strlen($key) != 0 && strlen($key) < TEXTAREA_SIZED) - $str_output .= '= '; - elseif(strlen($key)) - $str_output .= '= '; - else - $str_output .= ''.implode(', ', $this->_errors).''; - $str_output .= '
-
-

'; - } - $str_output .= '
'; - } - if (!empty($this->_errors)) - $this->displayErrors(); - echo $str_output; + $tpl = $this->context->smarty->createTemplate('translations/translation_form.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('Front-Office translations'), + 'count' => $count, + 'limit_warning' => $this->displayLimitPostWarning($count), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsBack=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'tabsArray' => $tabsArray, + 'textarea_sized' => TEXTAREA_SIZED, + 'type' => 'front' + )); + return $tpl->fetch(); } - public function displayFormBack($lang) + public function initFormBack($lang) { $_LANGADM = $this->fileExists(_PS_TRANSLATIONS_DIR_.$lang, 'admin.php', '_LANGADM'); $str_output = ''; /* List templates to parse */ $count = 0; - $tabs = scandir(_PS_ADMIN_DIR_.'/tabs'); - $tabs[] = '../../classes/AdminTab.php'; + $tabs = scandir(_PS_ADMIN_CONTROLLER_DIR_); + $tabs[] = '../../classes/AdminController.php'; $files = array(); + $i=0; foreach ($tabs AS $tab) - if (preg_match('/^(.*)\.php$/', $tab) AND file_exists($tpl = _PS_ADMIN_DIR_.'/tabs/'.$tab)) + if (preg_match('/^(.*)\.php$/', $tab) AND file_exists($tpl = _PS_ADMIN_CONTROLLER_DIR_.$tab)) { - $tab = basename(substr($tab, 0, -4)); + // -4 becomes -14 to remove the ending "Controller.php" from the filename + $tab = basename(substr($tab, 0, -14)); $fd = fopen($tpl, 'r'); $content = fread($fd, filesize($tpl)); fclose($fd); @@ -1052,6 +929,7 @@ class AdminTranslations extends AdminTab $tabsArray[$tab][$key] = stripslashes(key_exists($tab.md5($key), $_LANGADM) ? html_entity_decode($_LANGADM[$tab.md5($key)], ENT_COMPAT, 'UTF-8') : ''); $count += isset($tabsArray[$tab]) ? sizeof($tabsArray[$tab]) : 0; } + foreach (array('header.inc', 'footer.inc', 'index', 'login', 'password', 'functions') AS $tab) { $tab = _PS_ADMIN_DIR_.'/'.$tab.'.php'; @@ -1065,59 +943,36 @@ class AdminTranslations extends AdminTab $count += isset($tabsArray['index']) ? sizeof($tabsArray['index']) : 0; } - $str_output .= ' -

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('Back-Office translations').'

- '.$this->l('Expressions to translate').' : '.$count.'. '.$this->l('Click on the titles to open fieldsets').'.

'; - $str_output .= $this->displayLimitPostWarning($count); - if (!$this->suhosin_limit_exceed) - { - $str_output .= ' -
'; - $str_output .= $this->displayToggleButton(); - $str_output .= $this->displayAutoTranslate(); - $str_output .= '

'; - foreach ($tabsArray AS $k => $newLang) - if (sizeof($newLang)) - { - $countValues = array_count_values($newLang); - $empty = isset($countValues['']) ? $countValues[''] : 0; - $str_output .= ' -
'.$k.' - '.sizeof($newLang).' '.$this->l('expressions').' ('.$empty.') -
- '; - foreach ($newLang AS $key => $value) - { - $str_output .= ''; - else - $str_output .= ''; - } - $str_output .= ' -
'.stripslashes($key).'= '; - if (strlen($key) < TEXTAREA_SIZED) - $str_output .= '
-
-

'; - } - $str_output .= '
'; - } - echo $str_output; + $tpl = $this->context->smarty->createTemplate('translations/translation_form.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('Back-Office translations'), + 'count' => $count, + 'limit_warning' => $this->displayLimitPostWarning($count), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsBack=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'tabsArray' => $tabsArray, + 'textarea_sized' => TEXTAREA_SIZED, + 'type' => 'back' + )); + return $tpl->fetch(); } - public function displayFormErrors($lang) + public function initFormErrors($lang) { $_ERRORS = $this->fileExists(_PS_TRANSLATIONS_DIR_.$lang, 'errors.php', '_ERRORS'); - $str_output = ''; - /* List files to parse */ $stringToTranslate = array(); $dirToParse = array(_PS_ADMIN_DIR_.'/../', _PS_ADMIN_DIR_.'/../classes/', - _PS_ADMIN_DIR_.'/../controllers/', + _PS_ADMIN_DIR_.'/../controllers/front/', + _PS_ADMIN_DIR_.'/../controllers/admin/', _PS_ADMIN_DIR_.'/../override/classes/', _PS_ADMIN_DIR_.'/../override/controllers/', - _PS_ADMIN_DIR_.'/', - _PS_ADMIN_DIR_.'/tabs/'); + _PS_ADMIN_DIR_.'/'); if (!file_exists(_PS_MODULE_DIR_)) die($this->displayWarning(Tools::displayError('Fatal error: Module directory is not here anymore ').'('._PS_MODULE_DIR_.')')); if (!is_writable(_PS_MODULE_DIR_)) @@ -1143,30 +998,29 @@ class AdminTranslations extends AdminTab $stringToTranslate[$key] = (key_exists(md5($key), $_ERRORS)) ? html_entity_decode($_ERRORS[md5($key)], ENT_COMPAT, 'UTF-8') : ''; } $irow = 0; - $str_output .= $this->displayAutoTranslate(); - $str_output .= '

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('Error translations').'

' - .$this->l('Errors to translate').' : '.sizeof($stringToTranslate).'

'; - $str_output .= $this->displayLimitPostWarning(sizeof($stringToTranslate)); - if (!$this->suhosin_limit_exceed) - { - $str_output .= ' -
-

- '; - ksort($stringToTranslate); - foreach ($stringToTranslate AS $key => $value) - $str_output .= ''; - $str_output .= '
'.stripslashes($key).'=

'; - } - echo $str_output; + + $tpl = $this->context->smarty->createTemplate('translations/translation_errors.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('Error translations'), + 'count' => count($stringToTranslate), + 'limit_warning' => $this->displayLimitPostWarning($count), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsErrors=1&token='.$this->token, + 'auto_translate' => $this->displayAutoTranslate(), + 'type' => 'errors', + 'errorsArray' => $stringToTranslate, + )); + return $tpl->fetch(); } - public function displayFormFields($lang) + public function initFormFields($lang) { $_FIELDS = $this->fileExists(_PS_TRANSLATIONS_DIR_.$lang, 'fields.php', '_FIELDS'); $str_output = ''; $classArray = array(); + $validArray = array(); $count = 0; foreach (scandir(_PS_CLASS_DIR_) AS $classFile) { @@ -1179,50 +1033,38 @@ class AdminTranslations extends AdminTab if (!is_subclass_of($className, 'ObjectModel')) continue; $classArray[$className] = call_user_func(array($className, 'getValidationRules'), $className); + + foreach ($classArray AS $className => $rules) + { + if (isset($rules['validate'])) + foreach ($rules['validate'] AS $key => $value) + $validArray[$className][$key] = array_key_exists($className.'_'.md5(addslashes($key)), $_FIELDS) ? html_entity_decode($_FIELDS[$className.'_'.md5(addslashes($key))], ENT_NOQUOTES, 'UTF-8') : ''; + + if (isset($rules['validateLang'])) + foreach ($rules['validateLang'] AS $key => $value) + $validArray[$className][$key] = array_key_exists($className.'_'.md5(addslashes($key)), $_FIELDS) ? html_entity_decode($_FIELDS[$className.'_'.md5(addslashes($key))], ENT_COMPAT, 'UTF-8') : ''; + } if (isset($classArray[$className]['validate'])) $count += sizeof($classArray[$className]['validate']); if (isset($classArray[$className]['validateLang'])) $count += sizeof($classArray[$className]['validateLang']); } - $str_output .= $this->displayAutoTranslate(); - $str_output .= ' -

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('Field name translations').'

'; - $str_output .= $this->displayLimitPostWarning($count); - if (!$this->suhosin_limit_exceed) - { - $str_output .= $this->l('Fields to translate').' : '.$count.'. '.$this->l('Click on the titles to open fieldsets').'.

-
'; - $str_output .= $this->displayToggleButton(); - $str_output .= '

'; - foreach ($classArray AS $className => $rules) - { - $translated = 0; - $toTranslate = 0; - if (isset($rules['validate'])) - foreach ($rules['validate'] AS $key => $value) - (array_key_exists($className.'_'.md5($key), $_FIELDS)) ? ++$translated : ++$toTranslate; - if (isset($rules['validateLang'])) - foreach ($rules['validateLang'] AS $key => $value) - (array_key_exists($className.'_'.md5($key), $_FIELDS)) ? ++$translated : ++$toTranslate; - $str_output .= ' -
'.$className.' - '.($toTranslate + $translated).' '.$this->l('fields').' ('.$toTranslate.') -
- '; - if (isset($rules['validate'])) - foreach ($rules['validate'] AS $key => $value) - $str_output .= ''; - if (isset($rules['validateLang'])) - foreach ($rules['validateLang'] AS $key => $value) - $str_output .= ''; - $str_output .= ' -
'.stripslashes($key).'=
'.stripslashes($key).'=
-
-

'; - } - $str_output .= '
'; - } - echo $str_output; + $tpl = $this->context->smarty->createTemplate('translations/translation_form.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('Field name translations'), + 'count' => $count, + 'limit_warning' => $this->displayLimitPostWarning($count), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsFields=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'tabsArray' => $validArray, + 'textarea_sized' => TEXTAREA_SIZED, + 'type' => 'fields' + )); + return $tpl->fetch(); } /** @@ -1482,12 +1324,12 @@ class AdminTranslations extends AdminTab } '; } - public function displayFormMails($lang, $noDisplay = false) + public function initFormMails($lang, $noDisplay = false) { $core_mails = array(); $module_mails = array(); $theme_mails = array(); - $str_output = ''; + $obj_lang = new Language(Language::getIdByIso($lang)); // get all mail subjects, this method parse each files in Prestashop !! $subject_mail = array(); @@ -1495,8 +1337,8 @@ class AdminTranslations extends AdminTab $arr_files_to_parse = array( _PS_ROOT_DIR_.'/controllers', _PS_ROOT_DIR_.'/classes', - _PS_ADMIN_DIR_.'/tabs', - PS_ADMIN_DIR, + _PS_ADMIN_DIR_.'/tabs', + _PS_ADMIN_DIR_, ); $arr_files_to_parse = array_merge($arr_files_to_parse, $modules_has_mails); foreach ($arr_files_to_parse as $path) { @@ -1509,12 +1351,13 @@ class AdminTranslations extends AdminTab { $module_mails[$module_name] = $this->getMailFiles($module_path.'/mails/', $lang, 'module_mail'); $module_mails[$module_name]['subject'] = $core_mails['subject']; + $module_mails[$module_name]['display'] = $this->displayMailContent($module_mails[$module_name], $subject_mail, $obj_lang, Tools::strtolower($module_name), sprintf($this->l('E-mails for %s module'), ''.$module_name.''), $module_name); } // Before 1.4.0.14 each theme folder was parsed, // This page was really to low to load. // Now just use the current theme. - if(_THEME_NAME_ !== AdminTranslations::DEFAULT_THEME_NAME) + if(_THEME_NAME_ !== self::DEFAULT_THEME_NAME) { if(file_exists(_PS_THEME_DIR_.'mails')) { @@ -1529,6 +1372,8 @@ class AdminTranslations extends AdminTab { $theme_mails[$module_dir] = $this->getMailFiles(_PS_THEME_DIR_.'modules/'.$module_dir.'/mails/', $lang, 'theme_module_mail'); $theme_mails[$module_dir]['subject'] = $theme_mails['theme_mail']['subject']; + $title = $theme_or_module_name != 'theme_mail' ? ucfirst(_THEME_NAME_).' '.sprintf($this->l('E-mails for %s module'), ''.$theme_or_module_name.'') : ucfirst(_THEME_NAME_).' '.$this->l('e-mails'); + $theme_mails[$module_dir]['display'] = $this->displayMailContent($theme_mails[$module_dir], $subject_mail, $obj_lang, 'theme_'.Tools::strtolower($theme_or_module_name), $title, ($theme_or_module_name != 'theme_mail' ? $theme_or_module_name : false)); } } } @@ -1553,54 +1398,22 @@ class AdminTranslations extends AdminTab return array('total' => $total, 'empty' => $empty); } - $obj_lang = new Language(Language::getIdByIso($lang)); - - // TinyMCE - $str_output .= $this->getTinyMCEForMails($obj_lang->iso_code); - - $str_output .= ''; - $str_output .= ' -

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('E-mail template translations').'

' - .$this->l('Click on the titles to open fieldsets').'.

'; - - // display form - $str_output .= ' -
'; - $str_output .= $this->displayToggleButton(); - $str_output .= $this->displaySubmitButtons(Tools::getValue('type')); - $str_output .= '

'; - - // core emails - $str_output .= $this->l('Core e-mails:'); - $str_output .= $this->displayMailContent($core_mails, $subject_mail, $obj_lang, 'core', $this->l('Core e-mails')); - // module mails - $str_output .= $this->l('Modules e-mails:'); - foreach ($module_mails as $module_name => $mails) - { - $str_output .= $this->displayMailContent($mails, $subject_mail, $obj_lang, Tools::strtolower($module_name), sprintf($this->l('E-mails for %s module'), ''.$module_name.''), $module_name); - } - // mail theme and module theme - if (!empty($theme_mails)) - { - $str_output .= $this->l('Themes e-mails:'); - $bool_title = false; - foreach ($theme_mails as $theme_or_module_name => $mails) - { - $title = $theme_or_module_name != 'theme_mail' ? ucfirst(_THEME_NAME_).' '.sprintf($this->l('E-mails for %s module'), ''.$theme_or_module_name.'') : ucfirst(_THEME_NAME_).' '.$this->l('e-mails'); - if ($theme_or_module_name != 'theme_mail' && !$bool_title) { - $bool_title = true; - $str_output .= $this->l('E-mails modules in theme:'); - } - $str_output .= $this->displayMailContent($mails, $subject_mail, $obj_lang, 'theme_'.Tools::strtolower($theme_or_module_name), $title, ($theme_or_module_name != 'theme_mail' ? $theme_or_module_name : false)); - } - } - $str_output .= ' - - '; - $str_output .= $this->displaySubmitButtons(Tools::getValue('type')); - $str_output .= '

'; - $str_output .= '
'; - echo $str_output; + $tpl = $this->context->smarty->createTemplate('translations/translation_mails.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('E-mail template translations'), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsMails=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'type' => 'mails', + 'tinyMCE' => $this->getTinyMCEForMails($obj_lang->iso_code), + 'mail_content' => $this->displayMailContent($core_mails, $subject_mail, $obj_lang, 'core', $this->l('Core e-mails')), + 'module_mails' => $module_mails, + 'theme_mails' => $theme_mails + )); + return $tpl->fetch(); + //'; } protected static function getSubjectMail($directory, $subject_mail) @@ -1738,17 +1551,14 @@ class AdminTranslations extends AdminTab } return $array_files; } - public function displayFormModules($lang) + public function initFormModules($lang) { global $_MODULES; $array_lang_src = Language::getLanguages(false); - $str_output = ''; foreach ($array_lang_src as $language) - { $this->all_iso_lang[] = $language['iso_code']; - } if (!file_exists(_PS_MODULE_DIR_)) die($this->displayWarning(Tools::displayError('Fatal error: Module directory is not here anymore ').'('._PS_MODULE_DIR_.')')); @@ -1772,61 +1582,23 @@ class AdminTranslations extends AdminTab foreach ($arr_find_and_fill as $value) $this->findAndFillTranslations($value['files'], $value['theme'], $value['module'], $value['dir'], $lang); - $str_output .= ' -

'.$this->l('Language').' : '.Tools::strtoupper($lang).' - '.$this->l('Modules translations').'

- '.$this->l('Total expressions').' : '.$this->total_expression.'. '.$this->l('Click the fieldset title to expand or close the fieldset.').'.

'; - $str_output .= $this->displayLimitPostWarning($this->total_expression); - if (!$this->suhosin_limit_exceed) - { - $str_output .= ' -
'; - $str_output .= $this->displayToggleButton(); - $str_output .= $this->displayAutoTranslate(); - $str_output .= '

'; - - if (count($this->modules_translations) > 1) - { - $str_output .= '

'.$this->l('List of Themes - Click to access theme translation:').'

'; - $str_output .= ''; - } - - foreach ($this->modules_translations AS $theme_name => $theme) - { - $str_output .= '

>'.$this->l('Theme:').' '.($theme_name === self::DEFAULT_THEME_NAME ? $this->l('default') : $theme_name ).'

'; - foreach ($theme AS $module_name => $module) - { - $str_output .= ''.$this->l('Module:').' '.$module_name.''; - foreach ($module AS $template_name => $newLang) - if (sizeof($newLang)) - { - $countValues = array_count_values($newLang); - $empty = isset($countValues['']) ? $countValues[''] : 0; - $str_output .= ' -
'.($theme_name === 'default' ? $this->l('default') : $theme_name ).' - '.$template_name.' - '.sizeof($newLang).' '.$this->l('expressions').' ('.$empty.') -
- '; - foreach ($newLang AS $key => $value) - { - $str_output .= ''; - else - $str_output .= ''; - } - $str_output .= ' -
'.stripslashes($key).'= '; - if (strlen($key) < TEXTAREA_SIZED) - $str_output .= '
-
-

'; - } - } - } - $str_output .= '
'; - } + $tpl = $this->context->smarty->createTemplate('translations/translation_modules.tpl'); + $tpl->assign(array( + 'default_theme_name' => self::DEFAULT_THEME_NAME, + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('Modules translations'), + 'count' => $this->total_expression, + 'limit_warning' => $this->displayLimitPostWarning($this->total_expression), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsModules=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'textarea_sized' => TEXTAREA_SIZED, + 'type' => 'modules', + 'modules_translations' => isset($this->modules_translations) ? $this->modules_translations : array(), + )); + return $tpl->fetch(); } - echo $str_output; } /** parse $filepath to find expression which match $regex, and return an @@ -1848,11 +1620,10 @@ class AdminTranslations extends AdminTab return $tabsArray; } - public function displayFormPDF() + public function initFormPDF() { $lang = Tools::strtolower(Tools::getValue('lang')); $_LANG = array(); - $str_output = ''; if (!file_exists(_PS_TRANSLATIONS_DIR_.$lang)) if (!mkdir(_PS_TRANSLATIONS_DIR_.$lang, 0700)) @@ -1874,50 +1645,22 @@ class AdminTranslations extends AdminTab $tabsArray = $this->_parsePdfClass(_PS_ROOT_DIR_.'/override/classes/PDF.php', $regex, $_LANGPDF, $tab, $tabsArray); $count += isset($tabsArray[$tab]) ? sizeof($tabsArray[$tab]) : 0; - $closed = sizeof($_LANGPDF) >= $count; - $str_output .= $this->displayAutoTranslate(); - $str_output .= '

'.$this->l('Language').' : '.Tools::strtoupper($lang).'

' - .$this->l('Expressions to translate').' : '.$count.'. '.$this->l('Click on the titles to open fieldsets').'.

'; - $str_output .= $this->displayLimitPostWarning($count); - if (!$this->suhosin_limit_exceed) - { - $str_output .= ' -
- - - - '; - $str_output .= '

'; - foreach ($tabsArray AS $k => $newLang) - if (sizeof($newLang)) - { - $countValues = array_count_values($newLang); - $empty = isset($countValues['']) ? $countValues[''] : 0; - $str_output .= '
'.$k.' - '.sizeof($newLang).' '.$this->l('expressions').' ('.$empty.') -
- '; - foreach ($newLang AS $key => $value) - { - $str_output .= ' - - - '; - } - $str_output .= '
'.stripslashes($key).' - = -
-
-

'; - } - $str_output .= '
'; - } - echo $str_output; + $tpl = $this->context->smarty->createTemplate('translations/translation_form.tpl'); + $tpl->assign(array( + 'lang' => Tools::strtoupper($lang), + 'translation_type' => $this->l('PDF translations'), + 'count' => $count, + 'limit_warning' => $this->displayLimitPostWarning($this->total_expression), + 'suoshin_exceeded' => $this->suhosin_limit_exceed, + 'url_submit' => self::$currentIndex.'&submitTranslationsPdf=1&token='.$this->token, + 'toggle_button' => $this->displayToggleButton(), + 'auto_translate' => $this->displayAutoTranslate(), + 'textarea_sized' => TEXTAREA_SIZED, + 'type' => 'pdf', + 'tabsArray' => $tabsArray, + )); + return $tpl->fetch(); } /**