Here is what I'm stuck on.
I'm working on Symfony2 and trying to make the translations working. But somehow, I can't make it work as it should. Here's what I got.
In the config.yml
translator: { fallback: de }
session:
default_locale: en
In messages.en.yml I have this structure:
Please log in: Bitte melden Sie sich an
I also have similar files for messages.en_US.yml, messages.ru.yml, etc.
In the code I use $this->get('session')->setLocale('ru_RU'); to change the locale.
But the translation works only when the locale is set to "en_US" or "de_DE". In any other case it returns the key, not the value. I try the translation with this code
return new Response($this->get('translator')->trans('Please log in').' '.$this->get('session')->getLocale()); and it returns the locale I have set.
So what can cause this problem?
you should clear the cache by using the symfony comand
app/console cache:clear --no-debug
then eventually restore write permission on cache/ and log/ folders as described here
I found the answer myself. Just needed to clean up the cache for Symfony. Used console to do so. Changed directory to myProject/app and used this commands to clean the cache and logs:
sudo rm -R cache/
sudo rm -R logs/
Related
I'm using Symfony 6 and don't understand how I should enable translation for dependency messages.
For example: I just installed SymfonyCasts/verify-email-bundle which provides translations in its directory (src/Resources/translations)
To enable them, I have:
installed the translation bundle with: composer require symfony/translation
set the default_locale to fr in my config/packages/translation.yaml
cleared the cache with bin/console cache:clear
also tried to manually clear translation cache as stated in other related posts : rm -rf var/log/translations
Then, all messages that should be handled by the provided translations are still in English.
I have also tried to force translation by calling myself the $translator->trans() method on the string returned by the bundle. The profiler then says the translation is missing and fallbacks to en as configured.
I have tried to copy the bundle VerifyEmailBundle.fr.xlf file into my own /translations directory but got the same error. bin/console debug:translation fr shows me the needed translations but all are marked as unused.
I encounter the same issue with multiple bundles and don't see anything in the offical documentation about this.
What am I missing?
To set default language you must set #config/packages/translation.yaml like this:
framework:
default_locale: fr
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- fr
and you can add translations at #translations/messages.fr.yml
Hello: 'Bonjour'
This friendly message is coming from: 'Ce message amical vient de'
Welcome to my new App: 'Bienvenue sur ma nouvelle application'
user:
profile:
admin: 'administrateur'
This is the error
RuntimeException: Unable to create the cache directory (1/25/20).
1- Changing the cache directory in the appKernel file didn't fix the problem
/*
public function getCacheDir()
{
return '/mnt/symfony_ram_cache/cache/'.$this->environment;
}
*/
2- Setting the permissions to "chmod 777 -R cache" didn't work, still throws the error
3- App works when I deactivate the twig cache (I obviously need it in production)
#Twig Configuration
twig:
cache: false
4- It DOES create several folders in cache (in both prod and dev) when I empty the cache directoy and reload, so what means the rights are actually set properly
5- Here is a screenshot of the error
6- PS: Updated to symfony 2.5.6 the twig bundle was updated but still have no luck
Maybe you should chown cache directory to user who fires up application (www-data?)?
Edit your
app/config/config.yml
And change this:
From:
twig:
cache: "%kernel.debug%"
To:
twig:
cache: "%kernel.cache_dir%/twig"
I don't know what was wrong, I installed symfony2 from scratch again and now it works.
When i run the command
php app/console translation:extract en --enable-extractor=jms_i18n_routing
i get the following error:
[JMS\TranslationBundle\Exception\InvalidArgumentException]
The directory where translations are must be set.
this is the bundle configuration:
jms_i18n_routing:
default_locale: it
locales: [it, en]
strategy: prefix
cookie:
enabled: false
What is wrong with that?
You can fix this by using the --dir option to define the directory where your translations are when running your translation:extractcommand.
From the documentation,
For dumping, the bundle provides you with a console command which you
can use to update your translation files, or also just to preview all
changes that have been made.
Updating Files:
php app/console translation:extract de --dir=./src/ --output-dir=./app/Resources/translations
i had to use the following command
php app/console translation:extract en --enable-extractor=jms_i18n_routing --bundle="AcmeFooBundle" --domain="routes"
I installed behat with mink and selenium2-driver for my Symfony2 project.
Is it possible to use the /app/config/behat.yml instead of the /behat.yml file?
I searched on google but I can't find anything else this command.
php bin/behat --config app/config/behat.yml
But the command isn't working either.
I think there must be a config-path in composer.json.
Yes, you can configure which config file you want to use. Look at this part of the doc.
http://docs.behat.org/guides/7.config.html#paths
What error do you get when running your command?
php bin/behat --config app/config/behat.yml
This error?
[RuntimeException]
Context class not found.
Maybe you have provided a wrong or no `bootstrap` path in your behat.yml:
http://docs.behat.org/guides/7.config.html#paths
If that's the case, I think if might be because you need to specify where to find the features in your behat.yml file.
Now you moved the file to /app/config/behat.yml, the related path from behat.yml to the feature directory has changed, so you should add the following to the file:
default:
paths:
features: ../features/
bootstrap: ../features/bootstrap
Cross-posted from the official Symfony Google Group because time is an issue:
I'm in the final push to upload my site to my host. Everything runs fine in the dev environment - no errors, no warnings. When I attempt to access it in prod (localhost/web/app.php/), I get a blank screen. I attempted to clear the cache, to see if that would help, but got the following error:
$ app/console cache:clear --env=prod
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The parameter "kernel.trusted_proxies" must be defined.
I can clear the dev cache without issue.
Please help.
You'll need to add trusted_proxies to your config, even if it is blank.
Within: app/config/config.yml add:
framework:
trusted_proxies: ~
You'll also likely want to delete your cache files (app/cache/prod) and then run your console cache clear ($ app/console cache:clear --env=prod)