@@ -14,6 +14,7 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\Module;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Core\Template\TemplateHelper;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
@@ -25,13 +26,45 @@ use Thelia\Tools\URL;
|
||||
*/
|
||||
class TranslationsController extends BaseAdminController
|
||||
{
|
||||
/**
|
||||
* @param string $item_name the modume code
|
||||
* @return Module the module object
|
||||
* @throws \InvalidArgumentException if module was not found
|
||||
*/
|
||||
protected function getModule($item_name) {
|
||||
if (null !== $module = ModuleQuery::create()->findPk($item_name))
|
||||
return $module;
|
||||
|
||||
throw new \InvalidArgumentException(
|
||||
$this->getTranslator()->trans("No module found for code '%item'", ['%item' => $item_name])
|
||||
);
|
||||
}
|
||||
|
||||
protected function getModuleTemplateNames(Module $module, $template_type) {
|
||||
$templates =
|
||||
TemplateHelper::getInstance()->getList(
|
||||
$template_type,
|
||||
$module->getAbsoluteTemplateBasePath()
|
||||
);
|
||||
|
||||
$names = [];
|
||||
|
||||
foreach($templates as $template) $names[] = $template->getName();
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
protected function renderTemplate()
|
||||
{
|
||||
|
||||
// Get related strings, if all input data are here
|
||||
$item_to_translate = $this->getRequest()->get('item_to_translate');
|
||||
|
||||
$item_id = $this->getRequest()->get('item_id', '');
|
||||
$item_name = $this->getRequest()->get('item_name', '');
|
||||
|
||||
if ($item_to_translate == 'mo' && ! empty($item_name))
|
||||
$module_part = $this->getRequest()->get('module_part', '');
|
||||
else
|
||||
$module_part = false;
|
||||
|
||||
$all_strings = array();
|
||||
|
||||
@@ -41,51 +74,106 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
$templateArguments = array(
|
||||
'item_to_translate' => $item_to_translate,
|
||||
'item_id' => $item_id,
|
||||
'item_name' => $item_name,
|
||||
'module_part' => $module_part,
|
||||
'view_missing_traductions_only' => $this->getRequest()->get('view_missing_traductions_only', 0),
|
||||
'max_input_vars_warning' => false,
|
||||
);
|
||||
|
||||
// Find the i18n directory, and the directory to examine.
|
||||
|
||||
if (! empty($item_id) || $item_to_translate == 'co') {
|
||||
if (! empty($item_name) || $item_to_translate == 'co') {
|
||||
|
||||
switch ($item_to_translate) {
|
||||
|
||||
// Module core
|
||||
case 'mo' :
|
||||
if (null !== $module = ModuleQuery::create()->findPk($item_id)) {
|
||||
$module = $this->getModule($item_name);
|
||||
|
||||
if ($module_part == 'core') {
|
||||
$directory = $module->getAbsoluteBaseDir();
|
||||
$domain = $module->getTranslationDomain();
|
||||
$i18n_directory = $module->getAbsoluteI18nPath();
|
||||
$walkMode = TemplateHelper::WALK_MODE_PHP;
|
||||
}
|
||||
else if ($module_part == 'admin-includes') {
|
||||
$directory = $module->getAbsoluteAdminIncludesPath();
|
||||
$domain = $module->getAdminIncludesTranslationDomain();
|
||||
$i18n_directory = $module->getAbsoluteAdminIncludesI18nPath();
|
||||
$walkMode = TemplateHelper::WALK_MODE_TEMPLATE;
|
||||
}
|
||||
else if (! empty($module_part)) {
|
||||
// Front or back office template, form of $module_part is [bo|fo].subdir-name
|
||||
list($type, $subdir) = explode('.', $module_part);
|
||||
|
||||
if ($type == 'bo') {
|
||||
$directory = $module->getAbsoluteBackOfficeTemplatePath($subdir);
|
||||
$domain = $module->getBackOfficeTemplateTranslationDomain($subdir);
|
||||
$i18n_directory = $module->getAbsoluteBackOfficeI18nTemplatePath($subdir);
|
||||
}
|
||||
else if ($type == 'fo') {
|
||||
$directory = $module->getAbsoluteFrontOfficeTemplatePath($subdir);
|
||||
$domain = $module->getFrontOfficeTemplateTranslationDomain($subdir);
|
||||
$i18n_directory = $module->getAbsoluteFrontOfficeI18nTemplatePath($subdir);
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException("Undefined module template type: '$type'.");
|
||||
}
|
||||
$walkMode = TemplateHelper::WALK_MODE_TEMPLATE;
|
||||
|
||||
}
|
||||
|
||||
// List front and back office templates defined by this module
|
||||
$templateArguments['back_office_templates'] =
|
||||
$this->getModuleTemplateNames($module, TemplateDefinition::BACK_OFFICE);
|
||||
|
||||
$templateArguments['front_office_templates'] =
|
||||
$this->getModuleTemplateNames($module, TemplateDefinition::FRONT_OFFICE);
|
||||
|
||||
break;
|
||||
|
||||
// Thelia Core
|
||||
case 'co' :
|
||||
$directory = THELIA_ROOT . 'core/lib/Thelia';
|
||||
$domain = 'core';
|
||||
$i18n_directory = THELIA_ROOT . 'core/lib/Thelia/Config/I18n';
|
||||
$walkMode = TemplateHelper::WALK_MODE_PHP;
|
||||
break;
|
||||
|
||||
// Front-office template
|
||||
case 'fo' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::FRONT_OFFICE);
|
||||
$template = new TemplateDefinition($item_name, TemplateDefinition::FRONT_OFFICE);
|
||||
break;
|
||||
|
||||
// Back-office template
|
||||
case 'bo' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::BACK_OFFICE);
|
||||
$template = new TemplateDefinition($item_name, TemplateDefinition::BACK_OFFICE);
|
||||
break;
|
||||
|
||||
// PDF templates
|
||||
case 'pf' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::PDF);
|
||||
$template = new TemplateDefinition($item_name, TemplateDefinition::PDF);
|
||||
break;
|
||||
|
||||
// Email templates
|
||||
case 'ma' :
|
||||
$template = new TemplateDefinition($item_id, TemplateDefinition::EMAIL);
|
||||
$template = new TemplateDefinition($item_name, TemplateDefinition::EMAIL);
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
throw new \InvalidArgumentException(
|
||||
$this->getTranslator()->trans("Undefined translation type: %item", ['%item' => $item_to_translate])
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
if ($template) {
|
||||
$directory = $template->getAbsolutePath();
|
||||
|
||||
$i18n_directory = $template->getAbsoluteI18nPath();
|
||||
|
||||
$domain = $template->getTranslationDomain();
|
||||
}
|
||||
|
||||
// Load strings to translate
|
||||
@@ -102,11 +190,11 @@ class TranslationsController extends BaseAdminController
|
||||
|
||||
if (! empty($texts)) {
|
||||
|
||||
$file = sprintf("%s/%s.php", $i18n_directory, $this->getCurrentEditionLocale());
|
||||
$file = sprintf("%s".DS."%s.php", $i18n_directory, $this->getCurrentEditionLocale());
|
||||
|
||||
$translations = $this->getRequest()->get('translation', array());
|
||||
|
||||
TemplateHelper::getInstance()->writeTranslation($file, $texts, $translations);
|
||||
TemplateHelper::getInstance()->writeTranslation($file, $texts, $translations, true);
|
||||
|
||||
if ($save_mode == 'stay')
|
||||
$this->redirectToRoute("admin.configuration.translations", $templateArguments);
|
||||
@@ -122,6 +210,7 @@ class TranslationsController extends BaseAdminController
|
||||
$walkMode,
|
||||
$this->getTranslator(),
|
||||
$this->getCurrentEditionLocale(),
|
||||
$domain,
|
||||
$all_strings
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user