Kanni Farhad
Kanni Farhad

Reputation: 48

I am trying to integrate my template to twig with "The i18n Extension". Stuck on integration with xgettext

The integration works fine. But when I am trying to integrate it with xgettext for template string i get fatal error. There is an error

Fatal error: Uncaught Twig_Error_Loader: Unable to find template "C:/MAMP/htdocs/views/site/blocks/contactform.html" (looked into: C:\MAMP\htdocs/views/site). in C:\MAMP\htdocs\components\twig\Loader\Filesystem.php:232 Stack trace: 0 C:\MAMP\htdocs\components\twig\Loader\Filesystem.php(150): Twig_Loader_Filesystem->findTemplate('C:/MAMP/htdocs/...') #1 C:\MAMP\htdocs\components\twig\Environment.php(329): Twig_Loader_Filesystem->getCacheKey('C:\MAMP\htdocs/...') #2 C:\MAMP\htdocs\components\twig\Environment.php(419): Twig_Environment->getTemplateClass('C:\MAMP\htdocs/...') #3 C:\MAMP\htdocs\controllers\mainController.php(43): Twig_Environment->loadTemplate('C:\MAMP\htdocs/...') #4 C:\MAMP\htdocs\controllers\siteController.php(22): mainController->loadTwig() #5 C:\MAMP\htdocs\components\router.php(83): siteController->actionIndex() #6 C:\MAMP\htdocs\index.php(12): Router->Run() #7 {main} thrown in C:\MAMP\htdocs\components\twig\Loader\Filesystem.php on line 232

And here is my code:

class mainController {

  var $twig = null;
  public $configs;
  public $langlibrary;

  const DEFAULT_LANGUAGE = 'en';

  public function __construct() {
    $this->configs = Config::getConfigiration();
  }

  public function loadTwig() {

    require_once 'components/Twig/Autoloader.php';
    Twig_Autoloader::register();

    $tplDir = ROOT.'/views/site';
    $tmpDir = 'cache';
    $loader = new Twig_Loader_Filesystem($tplDir);

    $this->twig = new Twig_Environment($loader, array(
        'cache' => $tmpDir,
        'auto_reload' => true
    ));

    $this->twig->addExtension(new Twig_Extensions_Extension_I18n());

    // THE PROBLEM BEGINS WHEN ADD CODE BELOW FOR INETGRATION
    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
    {
        // force compilation
        if ($file->isFile()) {
            $this->twig->loadTemplate(str_replace($tplDir.'/', '', $file));
        }
    }

Upvotes: 0

Views: 139

Answers (1)

Kanni Farhad
Kanni Farhad

Reputation: 48

The fault was Windows web development environment in my computer. By the way i tried all of them Wamp, Mamp, Denwer in all of them was this problem. so better use Linux )

Upvotes: 0

Related Questions