configure jms_i18n_routing for InvalidConfigurationException - symfony

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.

Related

How to disable Cache in Symfony 5.2?

How can I completely disable the cache in Symfony 5.2?
I use PHP config file (services.php) and not the yaml ones.
In the docs, I cannot find anything matching.
Try configuring the two pools that are always enabled by default to use the Symfony\Component\Cache\Adapter\NullAdapter
framework:
cache:
app: cache.adapter.null
system: cache.adapter.null
services:
cache.adapter.null:
class: Symfony\Component\Cache\Adapter\NullAdapter
arguments: [~] # small trick to avoid arguments errors on compile-time.
https://symfony.com/doc/current/cache.html#configuring-cache-with-frameworkbundle
https://stackoverflow.com/a/46898727/6127393

How to generate document with Symfony 3.4 using Symfony flex

With Symfony flex, one of the change is that there is no default bundle when using the symfony/skeleton.
I don't find a way to use the command doctrine:mongodb:generate:documents in this context.
Could you please tell me how to use it ?
Exemple:
php bin\console doctrine:mongodb:generate:documents App
2018-02-17T18:35:22+00:00 [error] Error thrown while running command "doctrine:mongodb:generate:documents AppBundle --document Test". Message: "No bundle AppBundle was found."
In DoctrineODMCommand.php line 87:
No bundle AppBundle was found.
doctrine:mongodb:generate:documents [--document [DOCUMENT]] [--no-backup] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> <bundle>
This is how I setup my project
composer create-project symfony/skeleton:3.4 test
composer config "platform.ext-mongo" "1.6.16" && composer require "alcaeus/mongo-php-adapter"
composer require doctrine/mongodb-odm-bundle
Thanks
Regards,
Chris
There is a similar issue with doctrine orm and doctrine:generate:entities. The Doctrine team discourages users from using these commands and therefore does no longer want to maintain them.
I think the easiest workaround I've seen so far is:
Create a Symfony 3.3 style application using the Symfony installer.
Generate the entities in the AppBundle as you did before
Change the namespace from AppBundle to App.
Move the files into your Symfony 4 project.
Some of the Symfony team also set out to provide similar code generation in a MakerBundle. As far as I can tell there is nothing for generating ODM-style entities, but you could open an issue or contribute something for this yourself.
For reference see: https://github.com/doctrine/DoctrineBundle/issues/729
The MongoDBBundle requires you have "Bundle" but with Symfony flex you are using FrameworkBundle and not "AppBundle" unless you created it before, I think you have not created it, so it tells you that it does not exist.
You can not use the "FrameworkBundle" either beacause FrameworkBundle have other namspace and other base path, so the command to generate the documents does not know where the files are.
After a lot of time figuring out how to diry-fix it:
Create custom Bundle inside your project (EX: AppCoreBundle)
Define custom mapping inside packages/doctrine_mongodb.yaml (change type value if you use xml or yaml)
doctrine_mongodb:
auto_generate_proxy_classes: '%kernel.debug%'
auto_generate_hydrator_classes: '%kernel.debug%'
connections:
default:
server: '%env(MONGODB_URL)%'
options: {}
default_database: '%env(MONGODB_DB)%'
document_managers:
default:
auto_mapping: true
mappings:
AppCoreBundle:
is_bundle: true
type: annotation
dir: '/Document'
prefix: App\CoreBundle\Document
alias: AppCoreBundle
Change the directory "src" to "App" to avoid issues then update psr-4 namaspace inside composer.json: "App\\": "App/"
Move all Documents to the Bundle Document directory and change package names.
You will also have to change ALL references to "src" directory in your project, for example in services.yaml.
Then execute: rm -rf var/cache/* && composer install to force to clear cache and refs.
Then execute: php bin/console doctrine:mongodb:generate:documents AppCoreBundle
Important!
This solution solves compatibility problems with MongoODMBundle with Symfony 4 but it is not a correct way. The right fix involves modifying the behavior of the bundle or Symfony 4.

JMSI18nRoutingBundle and translatable routes catalog location

I am using JMSI18nRoutingBundle for internalisation of the routes of an application and it is some nice piece of software but unfortunately not very well documented and I am not sure how to achieve the translation of the strings in the routes for the different locales regardless of the fact it is given as an example in the docs.
What I would like is to have (default local without prefix, all others translated and with locale prefix):
/contact
/de/kontakt
The problem is with the following configuration:
jms_i18n_routing:
default_locale: en
locales: [en, de]
strategy: prefix_except_default
The routes are generated as:
/contact
/de/contact
I could not see a setting where to input kontakt for the de route, is it part of some special message catalog or per-route configuration option?
I found out that it is handled by the translations catalog. The routes are loaded from it. There is a command to extract them from the router and put them into the catalog:
php bin/console translation:extract LANGUAGE --bundle=BUNDLE --enable-extractor=jms_i18n_routing --output-format=xliff --dir=RESOURCE_FOLDER --domain=routes
Where LANGUAGE is the target language, BUNDLE is the bundle to extract the routes from and RESOURCE_FOLDER is where to put the translations.

Snc_redis exception when loading

I'm getting the following exception:
InvalidConfigurationException: The child node "clients" at path "snc_redis" must be configured.
I use Symfony 2.3 SncRedisBundle 1.1.x-dev
In config.yml I have
clients:
default:
type: predis
alias: default
dsn: redis://localhost
logging: %kernel.debug%
And I've followed the docs here for installation...
Any idea what would cause this ?
The bundle is looking for configuration values under snc_redis root (as you can see here), which you did not provide.
Now, all this wouldn't normally be a problem, but the clients child node is mandatory (as you can see here), which causes the error above.
Simply make the root configuration node in your config.yml to be snc_redis and the problem will go away. You probably simply missed it when doing copy-paste.

JMS I18n routes translations are ignored

I'm trying to use the JMSI18nRoutingBundle to translate my routes. I've installed and configured it like it's shown in the documentation :
composer.json:
"jms/i18n-routing-bundle": "1.1.*#dev",
AppKernel.php:
new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
new JMS\TranslationBundle\JMSTranslationBundle(),
And config.yml:
jms_i18n_routing:
default_locale: %locale%
locales: [en, fr]
catalogue: routes
strategy: custom
Then I'm trying to extract the translations for the routes. The command given in the doc
php app/console translation:extract fr --enable-extractor=jms_i18n_routing
doesn't work at all, but I found this command on internet that works better:
php app/console translation:extract fr --enable-extractor=jms_i18n_routing --bundle="TeduleCoreBundle" --domain="routes"
With this, the translations are extracted in a routes.fr.yml file in AcmeCoreBundle/Resources/translations. The file contains the translations for all the routes in all the locales, instead of only the routes for the AcmeCoreBundle in the fr locale like specified in the command, but oh well, it works...
However, when I do a php app/console router:debug, none of the routes are translated. Instead, I end up with something like this:
en_fr__RG__tedule_app_account_profile ANY ANY ANY /myaccount
en__RG__tedule_app_account_profile ANY ANY ANY /myaccount
fr__RG__tedule_app_account_profile ANY ANY ANY /myaccount
en_fr__RG__tedule_app_account_notifications ANY ANY ANY /myaccount/notifications
en__RG__tedule_app_account_notifications ANY ANY ANY /myaccount/notifications
fr__RG__tedule_app_account_notifications ANY ANY ANY /myaccount/notifications
en_fr__RG__tedule_app_account_password ANY ANY ANY /myaccount/password
en__RG__tedule_app_account_password ANY ANY ANY /myaccount/password
fr__RG__tedule_app_account_password ANY ANY ANY /myaccount/password
As you can see, each route appears 3 times (en_fr, en and fr), and the pattern isn't translated according to what I wrote in the routes.fr.yml file.
I tried clearing the cache, putting the routes.fr.yml file in app/Resources/translations, separating the translations between two files routes.fr.yml and routes.en.yml, nothing works...
That happens to me too but I solved it by moving the translation files of the routes to the "app/Resources/translations"
This works to me:
php app/console translation:extract en_US --bundle=MyBundle --enable-extractor=jms_i18n_routing --output-format=xliff --domain=routes --keep --output-dir=app/Resources/translations

Resources