我必须实现自己的翻译加载器.我使用了以下教程:http: //blog.elendev.com/development/php/symfony/use-a-database-as-translation-provider-in-symfony-2/ 来实现我自己的翻译加载器.
我的代码没有任何错误,但我的Loader的加载功能永远不会被执行.
有没有办法告诉symfony应该执行哪个翻译?
config.yml
translation.loader.db:
class: Mysk\TranslationBundle\Services\DBLoader
arguments: ["@doctrine.orm.entity_manager"]
tags:
- { name: translation.loader, alias: db}
Run Code Online (Sandbox Code Playgroud)
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(), …Run Code Online (Sandbox Code Playgroud)