私のプロジェクトでは、翻訳翻訳会社を賢明にseprateする必要がありますので、Translatorクラスを作成してください。 「FatalErrorException:エラー:134217728バイトのメモリサイズが枯渇しました」というエラーが発生しました。私のクラスは続いているSymfony2翻訳ロード社は賢明ですが100社作成エラー:許容メモリサイズ
----- Added this code in service file ------
#<your project name>/src/Raghuvir/UserBundle/Resources/config/services.yml
services:
translate:
class: Raghuvir\UserBundle\Translation\RaghuvirTranslator
arguments: ["@service_container", "@logger"]
翻訳クラス
<?php
namespace Raghuvir\UserBundle\Translation;
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
class RaghuvirTranslator extends Translator
{
/**
* {@inheritdoc}
*
* @api
*/
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
{
$snCompanyId = $this->container->get('session')->get('id_clinic');
if (null === $locale) {
$locale = $this->getLocale();
}
if ($snCompanyId == "") {
$domain = 'messages';
}else{
$domain = $snCompanyId.'_messages';
}
$referef = $this->container->get('request')->server->get('REQUEST_URI');
if(preg_match('/super/', $referef)) {
$domain = 'messages';
} else if(preg_match('/admin/', $referef)) {
$adminLangFilePath = $this->container->get('kernel')->getRootDir() . '/../src/RaghuvirClinicAdmin/DefaultBundle/Resources/translations/'.$domain;
if($this->container->getParameter('admin_translation') == 0 || !file_exists($adminLangFilePath.'.'.$locale.'.yml')) {
$domain = 'messages';
}
} else if(preg_match('/api/', $referef) || preg_match('/rest/', $referef)) {
$apiLangFilePath = $this->container->get('kernel')->getRootDir() . '/../src/RaghuvirApi/ApiBundle/Resources/translations/'.$domain;
if($this->container->getParameter('api_translation') == 0 || !file_exists($apiLangFilePath.'.'.$locale.'.yml')) {
$domain = 'messages';
}
} else {
$domain = 'messages';
}
if (!isset($this->catalogues[$locale])) {
$this->loadCatalogue($locale);
}
// Change translation domain to 'messages' if a translation can't be found in the
// current domain
if ('messages' !== $domain && false === $this->catalogues[$locale]->has((string) $id, $domain)) {
$domain = 'messages';
}
return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);
}
}