我有一个用Symfony 2.8编写的Symfony Web应用程序。 所有翻译在开发模式下都能正常工作,但第二语言的翻译未在生产模式下加载。 如果我在app.php中启用调试,翻译将完全加载。
$kernel = new AppKernel('prod', false);
要
$kernel = new AppKernel('prod', true);
但这不是一个好的选择。
我的config.yml是:
parameters:
locale: fa
framework:
#esi: ~
translator: { fallbacks: ["%locale%" , en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
我将messages.fa.yml和messages.en.yml文件放在app目录中。
答案 0 :(得分:1)
请按照我的指示操作:
1)将trans.yml文件移至src->nameBundle->Resources->translations
2)在src-> nameBunndle中创建或更新DependencyInjection
文件夹
3)在DependencyInjection
文件夹中创建Configuration.php
和NameExtension.php
,其中name是您的捆绑名称。
4)代码Configuration.php
:
<?php
namespace NameBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('name'); // name you bundle
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
return $treeBuilder;
}
}
5)代码NameExtension.php
:
<?php
namespace NameBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class NameExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}