Reputation: 971
I have a Symfony web application written in Symfony 2.8. All translations work correctly in dev mode ,But the translations of second language not loading in production mode. If I enable debug in app.php , translations will load completely.
$kernel = new AppKernel('prod', false);
TO
$kernel = new AppKernel('prod', true);
But it is not a good choice.
My config.yml is:
parameters:
locale: fa
framework:
#esi: ~
translator: { fallbacks: ["%locale%" , en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
I put the messages.fa.yml and messages.en.yml files in app directory.
Upvotes: 0
Views: 1175
Reputation: 1129
Try follow my instructions:
1) Move your trans.yml files into src->nameBundle->Resources->translations
2) In src->nameBunndle create or update DependencyInjection
folder
3) In DependencyInjection
folder create Configuration.php
and NameExtension.php
where name is your name of bundle.
4) Code 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) Code 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');
}
}
Upvotes: 1