We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Implementing multi-language support in HTML

Hello!

I have a question about a multi-language feature.

I'm using plain HTML as a "template" for my pages (and I do not want to use the volt engine). I'm using "Multi-lingual Support" as DI service:

file: Module.php (for the "frontend"):

namespace Frontend;
class Module implements \Phalcon\Mvc\ModuleDefinitionInterface
{
...
    public function registerServices($di)
    {
     ...
        $di->set('lang', function() use ($di)
            {
                $lang = $di->get("request")->getBestLanguage();
                if ($lang)
                {
                    $lang = strtolower(substr($lang,0,2));
                    if (file_exists("../app/frontend/messages/".$lang.".php")) 
                        require "../app/frontend/messages/".$lang.".php";
                    else 
                        require "../app/frontend/messages/en.php";
                }
                else
                    require "../app/frontend/messages/en.php";

                return new \Phalcon\Translate\Adapter\NativeArray(array("content" => $messages)); 
        });
    }
}

Then, in the my *.phtml files I do such things for translations :

<div><?=$this->lang->_("hello")?><div>

It is works best. But I don't want to use "php-trash" in my *.phtml files. Is there way to create user-friendly (or designer-friendly) PHTML-files and translate them before rendering (sure, without template engines and HTML-strings parsing with php)?

"It is works best. But I don't want to use "php-trash" in my *.phtml files. Is there way to create user-friendly (or designer-friendly) PHTML-files and translate them before rendering (sure, without template engines and HTML-strings parsing with php)?"

That would be the definition of a "template engine" ;-).