JmsI18NBundle - The directory where translations are must be set - php

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"

Related

Symfony 6 : how to import bundle translations?

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'

Run PHP CS fixer with GrumPHP

I'm using GrumPhp to sniff my commit in my symfony project: https://github.com/phpro/grumphp
Here is my config:
parameters:
git_dir: .
bin_dir: vendor/bin
tasks:
phpcsfixer:
config_file: ~
config: sf23
fixers: [psr2, symfony, indentation]
level: psr2
verbose: true
My question is:
Is there a way for Grumphp to automatically run php-cs-fixer when I commiting?
Yes there is!
https://github.com/phpro/grumphp/blob/master/doc/tasks.md
Since your post is a bit older here is the new updated doc, but you can still use version one! https://github.com/phpro/grumphp/blob/master/doc/tasks/php_cs_fixer2.md
You could try out this configuration but it's phpcsfixer version2!:
# grumphp.yml
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
hooks_dir: ~
hooks_preset: local
stop_on_failure: false
ignore_unstaged_changes: false
process_async_limit: 10
process_async_wait: 1000
process_timeout: 60
ascii:
failed: grumphp-grumpy.txt
succeeded: grumphp-happy.txt
tasks:
phpcsfixer2:
allow_risky: false
cache_file: ~
config: ~
rules: ['#Symfony']
using_cache: true
path_mode: ~
verbose: true
Your config looks fine, what's the output ?
Do you have the cs fixer installed and configured the grumPHP config to the path of your CS fixer?
https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage
GrumPHP always run php-cs-fixer with the --dry-run argument and this behavior is not configurable. You can read why here: https://github.com/phpro/grumphp/issues/110
But there's a way to automatically run php-cs-fixer: you have to install GrumPHP Extra Tasks and replace phpcsfixer2 with php_cs_auto_fixerv2 in your "grumpphp.yml" file.
Be aware that as of today GrumPHP Extra Tasks is not compatible with the latest version of GrumPHP but up to 0.17.2.

jms translation bundle: The format "yml~" does not exist.

In symfony2, with JMSTranslationBundle, when running
php app/console translation:extract fr --config=app
I get the issue
[JMS\TranslationBundle\Exception\InvalidArgumentException]
The format "yml~" does not exist.
my config being
jms_translation:
configs:
app:
dirs: [%kernel.root_dir%, %kernel.root_dir%/../src]
output_dir: %kernel.root_dir%/Resources/translations
ignored_domains: [routes]
excluded_names: ["*TestCase.php", "*Test.php"]
excluded_dirs: [cache, data, logs]
# extractors: [jms_i18n_routing]
Any idea as how to solve this ?
The solution is to remove all *.yml~ files from your project.

Symfony Translator is not generating cache message catalogue for default locale?

I am trying to run a Symfony 2.6.4 application on the Google AppEngine which is translated to 5 languages.
Problem is that cache:clear command generates only message catalogues for all languages except default locale (sk) and then it tries to generate missing message catalogue on the fly. Problem is that Google AppEngine is read-only. Can anybody explain why it isn't generated on cache:clear in warmup stage?
app.yml
framework:
default_locale: "sk"
translator:
fallback: "sk"
jms_i18n_routing:
default_locale: sk
locales: [cs, en, de, sk, ru]
strategy: prefix_except_default
Exception:
An exception has been thrown during the rendering of a template ("Cannot rename "vfs://root/temp/.../app/cache/prod/translations/catalogue.sk.php54e9b262334c93.83518975" to "/.../app/cache/prod/translations/catalogue.sk.php".") in base.html.twig at line 10.
Please, can anybody help me? I am trying to solve this for 3 days.

Symfony2 locale detection and translation

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/

Categories