我必须实现自己的翻译加载器。我使用了以下教程: http ://blog.elendev.com/development/php/symfony/use-a-database-as-translation-provider-in-symfony-2/ 来实现我自己的翻译加载器。
我的代码没有收到任何错误,但是我的 Loader 的加载函数永远不会被执行。
有没有办法告诉 symfony 应该执行哪个翻译?
配置.yml
translation.loader.db:
class: Mysk\TranslationBundle\Services\DBLoader
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: translation.loader, alias: db}
DBLoader.php
class DBLoader implements LoaderInterface {
private $transaltionRepository;
private $languageRepository;
/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager){
$this->transaltionRepository = $entityManager->getRepository("MyskTranslationBundle:LanguageTranslation");
$this->languageRepository = $entityManager->getRepository("MyskTranslationBundle:Language");
echo "yeah";
}
function load($resource, $locale, $domain = 'messages'){
die();
//Load on the db for the specified local
$language = $this->languageRepository->getLanguage($locale);
$translations = $this->transaltionRepository->getTranslations($language, $domain);
$catalogue = new MessageCatalogue($locale);
foreach($translations as $translation){
$catalogue->set($translation->getLanguageToken()->getToken(), $translation->getTranslation(), $domain);
}
return $catalogue;
}}
有任何想法吗?
干杯蒂莫