Translatation failing for CSRF token - symfony

I have a problem. In my form the text The CSRF token is invalid. Please try to resubmit the form. is not translating to French. I have the following in my translations/validator.fr.yml file:
The CSRF token is invalid. Please try to resubmit the form.: 'Actualisez le formulaire svp'
I am using Symfony 2.7.

After reading your comments, if you want your translations to be in French you can set a default locale for your application, and you must also enable the translator in your configuration. In your app/config/config.yml you would put:
parameters:
locale: fr
framework:
translator: { fallbacks: ["%locale%"] }
default_locale: "%locale%"
The translator line is commented out when you first install Symfony (see the master app/config/config.yml file).

Related

Default locale doesn't change in symfony 4

I'm trying to change locale from 'en' to 'lt' as a default, but not changing at all it only adds as a "Fallback locale", but not as a main. So following that problem I'm getting another one, that routes by language is incorrect. So the first problem should solve all others.
services.yaml
parameters:
locale: 'lt'
framework.yaml
framework:
default_locale: '%locale%'
and results:
So by that my Routes using EN language routes instead LT
Any solutions? tried without %locale% variables, clearing cache etc..
If you are using translations, have a look in translations.yaml :
framework:
default_locale: '%locale%'
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- '%locale%'
The %locale% variable is defined in services.yaml.
If you're using an event subscriber to track a user defined locale you might want to check that event subscriber's config in services.yaml :
App\EventSubscriber\LocaleSubscriber:
arguments: ['%kernel.default_locale%']

Symfony2 translations loaded but not translated

Im using FOS RestBundle and JMSSerializer (maybe its doing something i dont know) and want to returns a translated message in json. I wanted to use the translator service however the trans() method not working.
$this->get('translator')->trans('translator.key.here')
The translations seem to be loaded correctly as i dumped translator and found there the translated message under the current locale and 'translator.key.here' key. However the trans function simply gives back the key string.
Any idea?
Edit: In twig its working perfectly.
In my messages.hu yml file:
translator:
key:
here: some message
In the config also set fallbacks:
translator: { fallbacks: [hu] }
default_locale: "%locale%"
When i dumped translator in the object i found under en locale the right message key pair:
"translator.key.here" => "some message"
Try this in parameters.yml:
locale: hu
and in config.yml:
framework:
translator: { fallbacks: ["%locale%"] }
default_locale: "%locale%"
and in translation folder create file: messages.hu.yml
Well i found a solution.. still dont know why not working simply but it works if i set directly the translation domain.
translator->trans('key.goes.here', array(), 'messages); if somebody has the some issue in the future.

configure jms_i18n_routing for InvalidConfigurationException

I want to use the JMSi18nRoutingBundle. So i already have installed it in my project. Now when i try to run the server the commandline says:
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
The child node "default_locale" at path "jms_i18n_routing" must be configured.
But the path in this file is dynamic and will be only changed through the setPath() method. So where and how i have to configure it?
ok solved it!
the configuration to the JMSi18nRoutingBundle:
jms_i18n_routing:
default_locale: en
locales: [en, de]
strategy: prefix
need to be written in the config.yml. Additionally to this, the Translator in the Config has to be enabled. That´s all.

symfony2 locale and validation messages

locale: pl in my parameters.yml but my validation messages are in english not polish,
I have also try locale: pl_PL but this also didn't work
Each time I cleared cache
You have to uncommented the translator service of the framework component in config.yml to activate translations, also for other symfony components. Changing the paramater in parameters.yml isn't enough.
framework:
translator: { fallback: %locale% }
Take a look at the official documentation.

Symfony2 translation: locale is ignored

Some time ago, I started translating the Symfony 2.1 website I'm working on, using the "correct way" through /{ _locale } in the URL. Now the translation worked fine for most routes, but some of them (/login, /register, ...) kept coming in the default language (fr in this instance), because they didn't have the { _locale } part in their url.
Through the debug panel I realised that the locale was not actually changed through url navigation (unlike this had me believe).
So I then went there, where I found information and link to set up a listener in order to change the session locale in function of the path that is called.
All defaults locale declarations (both in config.yml and the listener itself) are "fr".
When I switch languages, I can actually see on the debug panel that the session locale changes. However, it would appear that the translation has somehow been broken : every translation bit is made in english, even though the default language is french, and despite the session locale being "fr".
Where could that come from? How can I fix it?
Thanks in advance.
More technical information:
routing.yml:
AuraeLCUserBundle:
resource: "#AuraeLCUserBundle/Resources/config/routing.yml"
prefix: /{_locale}/
defaults: { _locale: fr }
requirements:
_locale: en|fr
a twig example:
<p>{{ 'layout.greeting.welcome'|trans({}, 'AuraeLCUserBundle') }}</p>
3 things here are critical.
default lang (setted in config) and if your using translatable doctrine extension:
# app/config/config.yml
framework:
session: { default_locale: 'fr_FR' }
translator: { fallback: 'en' }
.....
stof_doctrine_extensions:
default_locale: 'fr_FR'
They must be different because of circular reference exception appears when the default locale won't go.
Translator is looking for files yaml|xml|gettext with sufix fr_FR ex:
messages.fr_FR.yml
messages.en.yml
yourcatalogue.fr_FR.yml
yourcatalogue.en.yml
Read this for more details:
Change default locale in Symfony2
http://symfony.com/doc/2.0/book/translation.html
http://0hlsson.se/2011/07/27/symfony2-and-translatable-example/

Resources