JMS I18n routes translations are ignored - symfony

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

Related

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.

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 - integration of ckeditor and sonata media bundle

I am trying to integarte IvoryCKEditor with sonata media bundle. Perpose is to allow image uploads in ckeditor. I tried it using a CoopTilleulsCKEditorSonataMediaBundle but i keep getting an error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "admin_sonata_media_media_ckeditor_browser" as such route does not exist.") in "IvoryCKEditorBundle:Form:ckeditor_widget.html.twig".
Thanks :)
You should check your routes with the command:
$ php app/console debug:router | grep ckeditor
Then you have to replace admin_sonata_media_media_ckeditor_browser and admin_sonata_media_media_ckeditor_upload by routes founded with this command, in the config of ivory_ck_editor (maybe in your config.yml or your ivory_ckeditor.yml file)
If you don't have route for ckeditor, I think you should check if you install correctly the bundle.
1) install SonataFormatterBundle 2) add the bundle and its dependencies in AppKernel 3) config files 4) CLEAR CACHE 5) roll
Reason of the issue
This problem arises when trying to integrate CKEditor through the
SonataFormatterBundle without using the SonataAdminBundle.
In fact, the integration proposed by the SonataFormatterBundle is meant to only work for the SonataAdminBundle, and no easy integration for a custom admin bundle is currently available.
Note that this dependency is not specified in the documentation at the moment.
How to solve the problem
Simply install the SonataAdminBundle following this installation process. You do need to configure the bundle entirely as specified in the documentation. To add the routes that were missing, such as admin_sonata_media_media_ckeditor_browser, simply add the following to your config/routes.yml:
# This is your custom admin bundle
admin:
resource: "#AdminBundle/Controller/"
type: annotation
prefix: /admin/
# Import SonataAdminBundle routes
admin_area:
resource: "#SonataAdminBundle/Resources/config/routing/sonata_admin.xml"
prefix: /admin/sonata # put whatever prefix here
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
Just to add something.
If you are SURE that you have installed, all dependencies, and set all configs correctly, and still getting this error, then the cause may be that you have defined your 'sonata_media' prefix in routing.yml differently.
You can check all urls in your project in:
app/cache/dev/appDevUrlGenerator.php
In there you will find ALL routes in a variable $declaredRoutes
Afterwards simply put correct route name for browsing.
It will not work without SonataMediaBundle - you will need to install it with SonataFormatterBundle
Sonata become too complicated as for me, so I just use IvoryCKEditorBundle directly

Assetic Route Not Found

I have a twig extension whose purpose is to collect a list of CSS and JS file paths given to it by function calls throughout a template hierarchy and then at the end of the twig template to take the output buffer and include these files in the <head> section of the page. For the most part it has been straightforward to implement.
In my service definition for the twig extension I am injecting the assetic.helper.dynamic service into it. The problem is when I call the javascripts() or stylesheets() method to get a URL for a CSS or JS file I get an error like this:
An exception has been thrown during the rendering of a template ("None
of the chained routers were able to generate route: Route
'_assetic_bd311c7' not found")
service.yml:
admin.twig.asset_extension:
class: Zing\Delta\AdminBundle\Twig\AssetExtension
tags:
- { name: twig.extension }
arguments: ['#assetic.helper.dynamic']
In my extension I am essentially doing this to get the URL for an asset:
$assetic_helper->stylesheets(array(
'#SomeBundle/Resources/public/js/jquery.tablesort.min.js'
));
I don't understand why the router can't find the routes or why assetic is setting up the routes.
The fix ended up being to run the following commands in the following order from the project root.
$ php app/console assets:install
$ php app/console assetic:dump
$ php app/console cache:clear

Symfony2 + doctrine2: Switch to metadata driver "yml"

a short question: How to switch to the another metadata driver than annotation. How to set the metadata driver "yml" in the config.yml?
I`ve searched google and the symfony2 docu, but didnt find anything :(
thanks
You should be able to do that with the doctrine:mapping:convert command
php app/console doctrine:mapping:convert --force yml ./src/
Double check all the options available before you run the command, though
php app/console help doctrine:mapping:convert
I realize this is an older question but you can explicitly require that doctrine use the yml driver for meta data like this:
doctrine:
orm:
entity_managers:
mappings:
MyBundleName:
type: yml
dir: path/to/ymlmetadata
Be aware that if you use this configuration style then you have to put the "defaults" config node under entity_managers instead of its usual location.

Resources