<?php

namespace KupShop\KupShopBundle\Util\Smarty;

use KupShop\KupShopBundle\Util\Locale\TemplateTranslator;
use KupShop\KupShopBundle\Util\Locale\WarningGettextTranslator;
use Smarty;

require_once 'compiler.t.ml.php';

/**
 * Smarty Multi-Language Class.
 */
class SmartyML extends \Smarty
{
    public $language;

    public function __construct($locale)
    {
        parent::__construct();

        $this->language = $locale;
    }

    /**
     * @return WarningGettextTranslator
     */
    public function loadTranslations()
    {
        return TemplateTranslator::getService()->get($this->language);
    }

    public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
    {
        // We need to set the cache id and the compile id so a new script will be
        // compiled for each language. This makes things really fast ;-)
        $compile_id = $this->language.$this->compile_id;
        $cache_id = $this->language.$this->cache_id;

        // Now call parent method
        return parent::fetch($template, $cache_id, $compile_id, $parent);
    }

    public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
    {
        $compile_id = $this->language.$this->compile_id;
        $cache_id = $this->language.$this->cache_id;

        parent::display($template, $cache_id, $compile_id, $parent);
    }
}
