Symfony2 Database Translation Loader isn't executed

后端 未结 2 1549
灰色年华
灰色年华 2021-01-14 09:43

I have to implement my own translation loader. I\'ve used the tutorial on: http://blog.elendev.com/development/php/symfony/use-a-database-as-translation-provider-in-symfony-

相关标签:
2条回答
  • 2021-01-14 10:02

    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));
        }
    }
    
    0 讨论(0)
  • 2021-01-14 10:05

    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.

    0 讨论(0)
提交回复
热议问题