Symfony2 Database Translation Loader isn't executed

心不动则不痛 提交于 2019-12-01 09:16:26
flu

Aldo answered this already but just to make it an official answer and to help others:

You need to create a "fake" translation file to trigger your loader

From Symfony Dependency Injection Tags: "translation.loader"

[...] If you're loading translations from a database, you'll still need a resource file, but it might either be blank or contain a little bit of information about loading those resources from the database. The file is key to trigger the load method on your custom loader.

So you need to crate files of the form <domain>.<locale>.<loader-alias> in your translations folder app/Resources/translations/.

In your case one file would be app/Resources/translations/messages.en.db for English.

http://blog.elendev.com/page/3/#post-26 or http://blog.elendev.com/development/php/symfony/use-a-database-as-translation-provider-in-symfony-2/ Another issue here is that there are no LanguageRepository class in the example. You can use this example.

<?php
namespace TranslationBundle\Repository;
use Doctrine\ORM\EntityRepository;
class LanguageRepository extends EntityRepository
{
    public function getLanguage($locale)
    {
        return $this->findOneBy(array('locale' => $locale));
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!