Symfony 4 translation are not working - symfony

the problem is not symfony, is me lol, I need help cause is not working fine, when i change my locale the text is still in english, there is my code
translation.yaml
framework:
default_locale: '%locale%'
translator:
paths:
- '%kernel.project_dir%/translations'
fallbacks:
- '%locale%'
framework.yaml
framework:
secret: '%env(APP_SECRET)%'
default_locale: en
csrf_protection: true
On my FrontController
`/**
* #Route("/{_locale}/",
* requirements={"_locale"="en|es"},
* name="index")
*/
public function index()
{
if($this->getUser()){
return $this->redirectToRoute('index');
}else{
$register= new Register();
$form = $this->createForm(RegisterType::class, $register,array(
'empty_data'=>'user_register',
'validation_groups' => array('default', 'empty_data'),
));
}`
my messages.es.xlf
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="sign_in">
<source>Sign in</source>
<target>Entrar</target>
</trans-unit>
</body>
</file>
on my template
{{ 'Sign in'|trans }}
well, the problem, is i change my url http://...../en/ to http://..../es/ is not working, but if i change my fallback manuale to es on translation.yaml is working fine, but then dons't work on /en/ any idea??

Related

FosJSRoutingBundle, route does not exist

I'm trying to generate URL in my Javascript but I can't due to this error:
Error: The route "my_route" does not exist.
I don't know why but the route is not recongnized...
What I did:
1) Get the bundle by composer
2) Published the assets :
php bin/console assets:install --symlink public
3) Use this in JS:
Routing.generate("my_route")
4) And then, this in my controller:
/**
* #Route("/route/to/route", options = { "expose" = true }, name="my_route")
* #param Request $request
* #return Response
*/
public function my_route(Request $request){
some things... };
So, it's not working...
I checked the JS dependencies that are loaded in the page:
<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
The first work but the second return error 404... Why ?
Regards

EasyAdminBundle entities labels translations

I'm unable to configure translations. My config.yml has (among others) this entry:
easy_admin:
entities:
Blog:
label: app.blog
class: AppBundle\Entity\Blog
I've also created a translation resorce: messages.es.xliff with this entry:
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="es" target-language="es" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="app.blog">
<source>app.blog</source>
<target>Blog</target>
</trans-unit>
</body>
</file>
</xliff>
but the translated literal doesn't appear in the left menu.
Thank you very much for your help.
At last I've changed the name of translation ressource to EasyAdminBundle.es.yml and now everything works fine.
Ensure you have the translator service enabled. In app/config/config.yml:
framework:
translator: { fallbacks: ["en"] }

Override FOSUserBundle routes Symfony2

I would like to override some routes from FOSUserBundle
MyBundle/Resources/config/routing/security.yml
fos_user_security_login:
path: /{_locale}/login
defaults: { _controller: FOSUserBundle:Security:login }
requirements:
_locale: %locales%
fos_user_security_check:
path: /login_check
defaults: { _controller: FOSUserBundle:Security:check }
requirements:
_locale: %locales%
fos_user_security_logout:
path: /{_locale}/logout
defaults: { _controller: FOSUserBundle:Security:logout }
requirements:
_locale: %locales%
But it does not works, route are not found
MyBundle/Resources/config/routing/security.xml
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="fos_user_security_login" pattern="/{_locale}/login">
<default key="_controller">FOSUserBundle:Security:login</default>
</route>
<route id="fos_user_security_check" pattern="/login_check">
<default key="_controller">FOSUserBundle:Security:check</default>
<requirement key="_method">POST</requirement>
</route>
<route id="fos_user_security_logout" pattern="/{_locale}/logout">
<default key="_controller">FOSUserBundle:Security:logout</default>
</route>
</routes>
This works but I don't know how to pass my locales parameter from parameter.yml
First of all the the yaml routes are not working because the FOSUserBundle Routes are defined in xml.
So your yaml routes won't imported.
here the FOSUserBundle Routes:
https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/config/routing
If the FOSUserBundle is the parent bundle of your userbundle you are able to rewrite the FOSUserBundle routing resources.
How to do this is explained here:
http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
Further more to answer to the last point how to pass the locale into the route is described here:
http://symfony.com/doc/current/cookbook/bundles/inheritance.html#overriding-resources-templates-routing-etc
<route id="contact" path="/{_locale}/contact">
<default key="_controller">AcmeDemoBundle:Contact:index</default>
<requirement key="_locale">%locales%</requirement>
</route>

Symfony2 - "Invalid Resource Exception" when translating twig template

I am trying to translate labels in my twig template located in Resources/views/User/ folder:
<label for="username">{% trans %}Username{% endtrans %} </label>
And the following is a section from my login.ka.xliff file located in my project under "translations" folder:
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
and this is my route to the login page:
login:
path: /login/{_locale}
defaults: { _controller: ExampleBundle:LogIn:login }
requirements:
_locale: en|ka
I have two problems:
When I try to open the login page with a locale (say, ka) I get the:
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »
I know I can get the locale from request using $request->getLocale(); but how do I specify that login page should use login.ka.xliff file for translations?
Ok, I seem to have provided not enough info, so here it is:
I put my translation file in Example:MyBundle:Resources:translations (this is what I meant above "in my project").
I get exception when rending my login view and the following is the full version of the exception I get:
"An exception has been thrown during the rendering of a template ("") in ExampleMyBundle:User:login.html.twig at line 32.
500 Internal Server Error - Twig_Error_Runtime
1 linked Exception:
InvalidResourceException »"
And yes, I did try clearing cache each time I made changes, but it didn't help.
And also, I added the complete version of my login.ka.xliff file.
Thanks again!
Your xliff file seems to be invalid - it should look like this: ( containing the xml-namespace, body, ... ).
<!-- messages.ka.xliff -->
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
</body>
</file>
</xliff>
The file should be named messages.ka.xliff if you haven't actually specified a different translation domain in your template!
{{ 'Username'|trans({}, "login") }}
... or configured a different default translation-domain in your template ...
{% trans_default_domain "login" %}
<trans-unit id="1">
<source>Username</source>
<target>მომხმარებელი</target>
</trans-unit>
... is an invalid xliff-file.

Can't get assetic to cssrewrite prod images properly

Using Symfony and Assetic I cannot get css images to 'dump' correctly in my prod environment.
They continue to link back to the web/bundle/...etc.. location.
I have a very basic cssrewrite setup:
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
filters:
cssrewrite:
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
My template:
{% stylesheets 'bundles/<my bundle>/css/style.css' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
I have the prod version of app.php in place with debug false:
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$apcLoader = new ApcClassLoader('sf2', $loader);
$loader->unregister();
$apcLoader->register(true);
*/
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
I have done:
app/console assets:install --symlink
All seems fine
Then I clear the prod cache
OK
app/console assetic:dump --env=prod
My css and js copy out with the expected file names, however I still have url('../../bundle/..etc../images/bg.png'); appearing in my css
In the symlinked version the css is: url('../images/bg.png');
So it must be something to do with assetic.
What I expect is for the 'dump'ed css to contain links like url('../images/bg.png');
And for the images themselves to be copied out to web/images/123abc.png
Should I expect this from assetic and if so what am I doing wrong?
Thanks, in advance.
// In Config.yml file
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
In app.php file
//If it is in dev environment In your app_dev.php file contain like this
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();
// If it is in prod environment, In your app.php file contain like this
$kernel = new AppKernel('prod', true);
$kernel->loadClassCache();

Resources