From 696d67805d326d948b1463afbf9f772b5e326818 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Thu, 31 Oct 2013 12:43:29 +0100 Subject: [PATCH] finish to implement translation --- core/lib/Thelia/Core/Thelia.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/core/lib/Thelia/Core/Thelia.php b/core/lib/Thelia/Core/Thelia.php index 9b0d1402f..3d476ad30 100755 --- a/core/lib/Thelia/Core/Thelia.php +++ b/core/lib/Thelia/Core/Thelia.php @@ -47,6 +47,7 @@ use Thelia\Config\DatabaseConfiguration; use Thelia\Config\DefinePropel; use Thelia\Core\TheliaContainerBuilder; use Thelia\Core\DependencyInjection\Loader\XmlFileLoader; +use Thelia\Model\ConfigQuery; use Symfony\Component\Config\FileLocator; use Propel\Runtime\Propel; @@ -122,7 +123,8 @@ class Thelia extends Kernel if (defined("THELIA_INSTALL_MODE") === false) { $modules = \Thelia\Model\ModuleQuery::getActivated(); - + $translator = $container->getDefinition('thelia.translator'); + $dirs = array(); foreach ($modules as $module) { try { @@ -138,10 +140,38 @@ class Thelia extends Kernel $loader = new XmlFileLoader($container, new FileLocator(THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/Config")); $loader->load("config.xml"); + + if (is_dir($dir = THELIA_MODULE_DIR . "/" . ucfirst($module->getCode()) . "/I18n")) { + $dirs[] = $dir; + } } catch (\InvalidArgumentException $e) { // FIXME: process module configuration exception } } + + //Load translation from templates + //admin template + if(is_dir($dir = THELIA_TEMPLATE_DIR . '/admin/default/I18n')) { + $dirs[] = $dir; + } + + //front template + $template = ConfigQuery::getActiveTemplate(); + if(is_dir($dir = THELIA_TEMPLATE_DIR . $template . "/I18n")) { + $dirs[] = $dir; + } + + if ($dirs) { + $finder = Finder::create() + ->files() + ->depth(0) + ->in($dirs); + + foreach ($finder as $file) { + list($locale, $format) = explode('.', $file->getBaseName(), 2); + $translator->addMethodCall('addResource', array($format, (string) $file, $locale)); + } + } } }