Git Product home page Git Product logo

jmsi18nroutingbundle's Introduction

jmsi18nroutingbundle's People

Contributors

acasademont avatar alcalyn avatar analogic avatar asm89 avatar cdfre avatar cmfcmf avatar deguif avatar frosas avatar gimler avatar janatjak avatar jonathaningram avatar jpierront avatar kbond avatar lightcoresystems avatar lunetics avatar nyholm avatar schmittjoh avatar seldaek avatar sroze avatar svetlinstaevworldstores avatar toooni avatar tricki avatar vytsci avatar xwb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jmsi18nroutingbundle's Issues

Locale not being prefixed when redirecting to /login*

Hi,

I seem to be having an issue using the prefix strategy when using this bundle with Symfony 2.0.7 (standard edition). I'm not sure if this is an issue with the bundle, a change in FOSUserBundle (I use that as my user provider), or a change in Symfony itself.

The locale is correctly prefixed in all of my routes except when trying to directly access the secured section of my site when not logged in. Instead of redirecting to /{_locale}/login, I keep getting redirected to /login, which causes Symfony to throw a NotFoundHttpException due to the route not existing.

For example, if a user tries to access /en/members before they've logged in, it redirects them to /login instead of /en/login. The same thing happens when trying to access /fr/members/. As far as I can tell, this is a fairly new problem that just started in Symfony 2.0.7. It may also impact 2.0.6 but I haven't tested it on that version. I'm pretty confident that it was working in 2.0.6.

Presumably there's an issue with the way I have my firewall configured or there's an issue with another part of my configuration. This does seem a bit odd though since the locale is correctly prefixed in every other situation (as far as I can tell).

In config.yml:

jms_i18n_routing:
    default_locale: %locale%
    locales: [en, fr]
    strategy: prefix

In my security.yml:

firewalls:
    frontend:
        pattern: ^/.*
        provider: fos_userbundle
        form_login:
            check_path: /login_check
            login_path: /login
        logout:
            path: /logout
            target: /
        anonymous: true

access_control:
    - { path: ^/[a-z][a-z]/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/[a-z][a-z]/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/[a-z][a-z]/members, role: ROLE_MEMBER }
    - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY}

After running php app/console router:debug I get the following security routes:

en_fos_user_security_login           ANY      /en/login
fr_fos_user_security_login           ANY      /fr/login
en_fos_user_security_check           ANY      /en/login_check
fr_fos_user_security_check           ANY      /fr/login_check
en_fos_user_security_logout          ANY      /en/logout
fr_fos_user_security_logout          ANY      /fr/logout

I've currently implemented a simple workaround that allows users to login without an exception being thrown by explicitly setting the default locale in my firewall:

firewalls:
    frontend:
        pattern: ^/.*
        provider: fos_userbundle
        form_login:
            check_path: /%locale%/login_check
            login_path: /%locale%/login
        logout:
            path: /%locale%/logout
            target: /
        anonymous: true

But as you can imagine, this is less than ideal since it always uses the default locale when prompting users to login. Thanks for your help and/or input.

Keep up the great work. This bundle has saved me tons of development time. :)

Default Locale problem

Hi,

Why is it the default locale always goes to "en" even though it is in the list. Any ideas?

Here's the config.

jms_i18n_routing:
default_locale: ie
locales: [pt,dk,ie]
strategy: prefix

Thanks in advance.

Customize route description and retrieve it in translation file

Hi,

Is there a way to set a custom description for each route ?
I mean, for example, adding in routing.xml file a custom description for each route and be able to retrieve it in route.lang.xliff file.

My other question is about the way to ignore routes from being translated.
Using "_" prefix on route name do the job, but, for external bundle which needs a specific route name, i can't do that. Is there another way to do that ?

Thanks a lot for your help.

Ghislain

Route has missing parameters.

Hi. I encountered a problem where I can't find the cause.

When I enter the page:

/en/blog/10/post

I get error:

("The "pl__RG__post_show" route has some missing mandatory parameters ("id").")

When I remove from this template twig extends function:

{% extends 'TestBundle:Frontend:layout.html.twig' %}

Then the page runs fine 8-|, but with no layout (that's obvious).

This only happens when i have parameters in my routes.
Btw: Shouldn't the route name be en__RG__post_show.

I don't have routes translated.
I use strategy: prefix_except_default with pl as a default.
It happens on all my locales.

Any idea where the problem might be ?

Route 'xxx' does not exist with strategy "prefix_except_default"

In some cases i get an error, that a specific route does not exist. I am using the JMSI18nRoutingBundle with the following config:

jms_i18n_routing:
    default_locale: %locale%
    locales: [de, fr, en, it]
    strategy: prefix_except_default

maybe it occurs because i have locales like de_CH or de_AT.. But most of the time the routes are working fine. I found out, that i had the error when i was using the twig render function to render a specific action into my template.
There is also a issue on some form fields when using the sonata admin bundle.

at the moment i made a little hack to get a fallback if this exception will be thrown.

Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumber.php starting on line 109:

    private function generateGenerateMethod()
    {
        return <<<EOF
    public function generate(\$name, \$parameters = array(), \$absolute = false)
    {
        if (!isset(self::\$declaredRoutes[\$name])) {
            if (isset(self::\$declaredRoutes['de__RG__'.\$name])) {
                \$name = 'de__RG__'.\$name;
            }else{
                throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', \$name));
            }
        }

        list(\$variables, \$defaults, \$requirements, \$tokens) = self::\$declaredRoutes[\$name];

        return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$absolute);
    }
EOF;
    }

language switcher doc missing

The documentation is missing a language switcher example, so here is one working for me with Symfony 2.0, symfony 2.1 can use _route_params and avoid using the first loop for filling "routeParams".

for the locals variable, I created it in parameters.ini like this :

locales[] = en
locales[] = fr
locales[] = nl
locales[] = de

and then I loaded it in twig globals thru config.yml :

twig:
globals:
locales: %locales%

And now, just copy paste the following code where you want to see language switcher in you template

{# Language switcher #}
{% for locale in locales %}                                     
    <li><a href="{{ app.request.attributes.get("_route"), app.request.attributes.all|merge({"_locale": locale})) }}">{{ locale }}</a></li>
{% endfor %}

Strategy "custom" don't work ?

In app/config/config_dev.yml

jms_i18n_routing:
    default_locale: fr
    locales: [fr, en]
    strategy: custom
    hosts:
        fr: fr.domain.local
        en: en.domain.local

In app/Resources/translations/routes.en.yml

MyLittleBundle_homepage: '/hello/{name}'

In app/Resources/translations/routes.fr.yml

MyLittleBundle_homepage: '/bonjour/{name}'

OK (anormal) http://fr.domain.local/hello/Name
OK http://en.domain.local/hello/Name

FAILLED http://fr.domain.local/bonjour/Name
FAILLED (normal) http://fr.domain.local/bonjour/Name

Did I miss something?

Undetected routes ?

Hi,

I've installed the bundle, and have a project with basically only 2 pages so far:
In my app/config/routing.yml :

_localeDispatcher:
    pattern:  /
    defaults: { _controller: MyAppBundle:LocaleDispatcher:index }

_welcome:
    pattern:  /welcome
    defaults: { _controller:MyAppBundle:Welcome:index }

In my app/config/config.yml

jms_i18n_routing:
    default_locale: en
    locales: [fr, en_CA, en, es]
    strategy: prefix

Basically, my first page decide what's the best locale for the visitor, and redirect him to the proper route.
The URI his generated this way:

$arrParam = array('_locale' => $this->get('session')->getLocale());
$url = $this->container->get('router')->generate('_welcome', $arrParam);

So a couple of problems:

  1. I've setup the prefix strategy, and the $url variable contain /welcome?_locale=en instead of /en/welcome
  2. If I try to access /en/welcome, the route is not found
  3. If I run i18n:extract-routes en --dry-run, none of my route are detected, only those of FOSUserBundle will appear.

I feel like it's a configuration problem, but their's almost no documentation or tutorials aside from /resources/doc/index.rst :(

wrong url generated using twig path function in Symfony 2.1 (master)

the symfony/twig path function does not generate the correct url in symfony 2.1:
when i do have set a locale like fr_CH my links are like: mylink.ch/xyz instead of mylink.ch/fr/xyz.. for example in sf 2.0 this was working as expected.

I do have the following settings:

jms_i18n_routing:
    default_locale: de
    locales: [de, fr, en, it]
    strategy: prefix_except_default

Please mention in the docs that routes starting with _ are excluded

If you test the bundle with the default AcmeDemoBundle, it is not working. Because the routes start with an underscore. I nearly discarded the plugin because of this.

It would be good to mention it the documentation, that routes beginning with an underscore are excluded by default.
Thanks!

$router->routeCollection() -> get() problem

Hello,

I discovered a bug when using this bundle with PagerFanta and AdminGenerator bundle. I guess this can be found on any other bundle that use the following procedure :

<?php
$request = $this->container->get('request');
$routeName = $request->attributes->get('_route');

$router->getRouteCollection()->get($routeName)->compile()->getVariables()

The collection object returned has all the routes prefixed with all the locales so it's fine, but when you call ->get() with the route name from the $request attributes it will throw a fatal error. That's logical because the route name from this object isn't prefixed with the locale.

My quick and dirty fix to avoid getting me stuck for the rest of the day is to return a proxy object instead of Symfony\Component\Routing\RouteCollection.

I will be glad to help on this issue if I can.

multiple hosts, shared url due to en_UK and en_US

For my current project I need separate hosts for en_UK and en_US, while most urls are still the same.

Thus, / and /, with both the same.

This comes with a single small issue: when two routes share the same url, the match() cannot distinguish between the two routes (/ is only matched to the first (or is it to the last?) match). This can be fixed: take for example locales en_US and en_UK, with

en_US_news_overview: /news

Assume we are on host en_UK, but the matcher finds the routing for the host corresponding en_US. We can now check if there exists an en_UK route (just replace the en_US part of en_US_news_overview with en_UK and generate the url). If this url is the same as the active url than there is no need to redirect to the other host, allowing multiple hosts to share urls. This change is even compatible with the current system.

A last feature I require is the following. Currently, when the url is not available for the active host a redirect is used.
Instead of redirecting to the other host I'd want a RouteNotFoundException to be thrown. This could be a configurable option: 'redirect_to_host' with standard value true, again BC.

Have you got any concerns regarding this approach, or any tips / advice?
I'll make a PR for this as soon as I can (probably this Thursday)

multiple hosts with same locales

proposal for feature addition:

currently it's possible to have only one host per locale, e.g.

jms_i18n_routing:
    default_locale: cs
    locales: [cs, en]
    strategy: custom
    hosts:
        cs: domain.cz
        en: domain.com

if I need to have more than 1 domain with same locale, I am unable to do this... following setup doesn't work (end up with exception 'Invalid type for path "jms_i18n_routing.hosts.cs". Expected scalar, but got array.')

    hosts:
        cs: [domain.cz, domain2.cz]

it would be nice to add such a support for multiple domains with same locale

I18nRouter construct, object is being passed instead of array.

Hi,

Could you help me with this. I have installed the bundle using composer and added configuration properly but I have encountered this problem.

ErrorException: Catchable Fatal Error: Argument 5 passed to JMS\I18nRoutingBundle\Router\I18nRouter::__construct() must be an array, object given, called in app\cache\dev\appDevDebugProjectContainer.php on line 2132 and defined in app\cache\dev\classes.php line 10421

Thanks.

Compatibility with FOSUserBundle

Hi,

I already installed FOSUserBundle and it worked ok.

Now I have just installed your bundle and when I try to log in (en/login or es/login), I get:

You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.

This is output of router:debug and my security.yml file:


_wdt                                          ANY      /_wdt/{token}
_profiler_search                              ANY      /_profiler/search
_profiler_purge                               ANY      /_profiler/purge
_profiler_info                                ANY      /_profiler/info/{about}
_profiler_import                              ANY      /_profiler/import
_profiler_export                              ANY      /_profiler/export/{token}.txt
_profiler_phpinfo                             ANY      /_profiler/phpinfo
_profiler_search_results                      ANY      /_profiler/{token}/search/results
_profiler                                     ANY      /_profiler/{token}
_profiler_redirect                            ANY      /_profiler/
_configurator_home                            ANY      /_configurator/
_configurator_step                            ANY      /_configurator/step/{index}
_configurator_final                           ANY      /_configurator/final
en__RG__sonata_default_default_index          ANY      /en/helloooooooooooooo/{name}
es__RG__sonata_default_default_index          ANY      /es/helloooooooooooooo/{name}
en__RG__sports_frontend_default_index         ANY      /en/hello/{name}
es__RG__sports_frontend_default_index         ANY      /es/hello/{name}
en__RG__sports_frontend_wall_index            ANY      /en/wall
es__RG__sports_frontend_wall_index            ANY      /es/wall
en__RG__sports_user_default_index             ANY      /en/hello/{name}
es__RG__sports_user_default_index             ANY      /es/hello/{name}
en__RG__fos_user_security_login               ANY      /en/login
es__RG__fos_user_security_login               ANY      /es/login
en__RG__fos_user_security_check               ANY      /en/login_check
es__RG__fos_user_security_check               ANY      /es/login_check
en__RG__fos_user_security_logout              ANY      /en/logout
es__RG__fos_user_security_logout              ANY      /es/logout
en__RG__fos_user_profile_show                 GET      /en/profile/
es__RG__fos_user_profile_show                 GET      /es/profile/
en__RG__fos_user_profile_edit                 ANY      /en/profile/edit
es__RG__fos_user_profile_edit                 ANY      /es/profile/edit
en__RG__fos_user_registration_register        ANY      /en/register/
es__RG__fos_user_registration_register        ANY      /es/register/
en__RG__fos_user_registration_check_email     GET      /en/register/check-email
es__RG__fos_user_registration_check_email     GET      /es/register/check-email
en__RG__fos_user_registration_confirm         GET      /en/register/confirm/{token}
es__RG__fos_user_registration_confirm         GET      /es/register/confirm/{token}
en__RG__fos_user_registration_confirmed       GET      /en/register/confirmed
es__RG__fos_user_registration_confirmed       GET      /es/register/confirmed
en__RG__fos_user_resetting_request            GET      /en/resetting/request
es__RG__fos_user_resetting_request            GET      /es/resetting/request
en__RG__fos_user_resetting_send_email         POST     /en/resetting/send-email
es__RG__fos_user_resetting_send_email         POST     /es/resetting/send-email
en__RG__fos_user_resetting_check_email        GET      /en/resetting/check-email
es__RG__fos_user_resetting_check_email        GET      /es/resetting/check-email
en__RG__fos_user_resetting_reset              GET|POST /en/resetting/reset/{token}
es__RG__fos_user_resetting_reset              GET|POST /es/resetting/reset/{token}
en__RG__fos_user_change_password              GET|POST /en/profile/change-password
es__RG__fos_user_change_password              GET|POST /es/profile/change-password
en__RG__sonata_admin_dashboard                ANY      /en/admin/dashboard
es__RG__sonata_admin_dashboard                ANY      /es/admin/dashboard
en__RG__sonata_admin_retrieve_form_element    ANY      /en/admin/core/get-form-field-element
es__RG__sonata_admin_retrieve_form_element    ANY      /es/admin/core/get-form-field-element
en__RG__sonata_admin_append_form_element      ANY      /en/admin/core/append-form-field-element
es__RG__sonata_admin_append_form_element      ANY      /es/admin/core/append-form-field-element
en__RG__sonata_admin_short_object_information ANY      /en/admin/core/get-short-object-description
es__RG__sonata_admin_short_object_information ANY      /es/admin/core/get-short-object-description
en__RG__sonata_admin_set_object_field_value   ANY      /en/admin/core/set-object-field-value
es__RG__sonata_admin_set_object_field_value   ANY      /es/admin/core/set-object-field-value
en__RG__tag_list                              ANY      /en/admin/tag/list
es__RG__tag_list                              ANY      /es/admin/tag/list
en__RG__tag_create                            ANY      /en/admin/tag/create
es__RG__tag_create                            ANY      /es/admin/tag/create
en__RG__tag_batch                             ANY      /en/admin/tag/batch
es__RG__tag_batch                             ANY      /es/admin/tag/batch
en__RG__tag_edit                              ANY      /en/admin/tag/{id}/edit
es__RG__tag_edit                              ANY      /es/admin/tag/{id}/edit
en__RG__tag_delete                            ANY      /en/admin/tag/{id}/delete
es__RG__tag_delete                            ANY      /es/admin/tag/{id}/delete
en__RG__tag_show                              ANY      /en/admin/tag/{id}/show
es__RG__tag_show                              ANY      /es/admin/tag/{id}/show
en__RG__tag_export                            ANY      /en/admin/tag/export
es__RG__tag_export                            ANY      /es/admin/tag/export

security:
    path: fos_user_security_logout
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_USER }
        - { path: ^/hello/, role: ROLE_USER }

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

a case where locale is not parsed correctly

I'm reporting this problem here but it just might be that the problem is in sf itself.
In case you have a whole application password protected and you switch a language on the login form or you enter the url with locale but without a trailing / e.g you enter http://example.com/en instead of http://example.com/en/ the _locale doesn't get populated as the redirect is issued and the login page is still on the default or previously used locale.

Incompatibility with Symfony 2.0

Hi,

Thank you for your great work!
When installing on symfony 2.0.x I have an error:

Fatal error: Call to undefined method Symfony\Component\HttpFoundation\Request::getLocale() in /Users/bartoldi/Sites/corpotition.dev/Symfony/vendor/bundles/JMS/I18nRoutingBundle/EventListener/CookieSettingListener.php on line 29

route names with 2-letter prefix don't get picked up

It seems like this route

hk_homepage:
pattern: /
defaults: { _controller: HelloKotSiteBundle:Default:index }

doesn't get picked up, whereas this one does

homepage:
pattern: /
defaults: { _controller: HelloKotSiteBundle:Default:index }

I assume the 2 letter "hk_" prefix creates a conflict with the 2-letter locale prefix "en_", "de_".

No big deal, I will remove my prefixes in my routes, but I thought I'd mention this.

do not overwrite the router service

$container->setAlias('router', 'jms_i18n_routing.router');

this is currently necessary because the bundles router service is defined like so:
<service id="jms_i18n_routing.router" class="%jms_i18n_routing.router.class%" parent="router.default" public="false">

instead it would be better to simply decorate router.default

see this hint for how to do it:

[10:53 ] <beberlei> schmittjoh: make your router named router.dfault and rename the original one to router.default.framework or something
[10:54 ] <beberlei> thats what I do when i decorate

Need help : generateUrl : how to get the slugs from route translations ?

Hi,

I'm using JMSI18nRoutingBundle with route translations, plus a language switcher of my own, since the recipe page for that remains empty.

The route translations are working properly with the slugs I've set :

sn_homepage:
    pattern:  /members/{username}
    defaults: { _controller: MSWSocialNetworkBundle:Wall:home }

and in route translation files something like :

MSW_sn_homepage: /membres/{username}

for the french transation of the route.

The routes are working properly when I call them in different languages and a username from my browser.

However, I use the following code in my language switcher controller :

$url = $this->generateUrl($previous_route_name, array('_locale' => $form['language_switcher']));
return $this->redirect($url);

Then I get an error message stating that the required route parameter username isn't passed, of course it works if I manually pass 'username' => 'someone' in the params array of the generateUrl function.

So, in other words, how could I generate the route in my language switcher controller so that the slugs defined in any route translations could be taken in account ?

Many thanks for any help !

Call to undefined method BooleanNodeDefinition::info()

I got this, when tried to install vendors.
Symfony 2.0.17

PHP Fatal error: Call to undefined method Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition::info() in /var/www/kairos/vendor/bundles/JMS/I18nRoutingBundle/DependencyInjection/Configuration.php on line 104
PHP Stack trace:
PHP 1. {main}() /var/www/kairos/app/console:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/kairos/app/console:16
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/kairos/vendor/symfony/src/Symfony/Component/Console/Application.php:118
PHP 4. Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() /var/www/kairos/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:67
PHP 5. Symfony\Component\HttpKernel\Kernel->boot() /var/www/kairos/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:81
PHP 6. Symfony\Component\HttpKernel\Kernel->initializeContainer() /var/www/kairos/app/bootstrap.php.cache:517
PHP 7. Symfony\Component\HttpKernel\Kernel->buildContainer() /var/www/kairos/app/bootstrap.php.cache:783
PHP 8. Symfony\Component\DependencyInjection\ContainerBuilder->compile() /var/www/kairos/app/bootstrap.php.cache:872
PHP 9. Symfony\Component\DependencyInjection\Compiler\Compiler->compile() /var/www/kairos/vendor/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:436
PHP 10. Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process() /var/www/kairos/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:119
PHP 11. Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process() /var/www/kairos/vendor/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php:39
PHP 12. JMS\I18nRoutingBundle\DependencyInjection\JMSI18nRoutingExtension->load() /var/www/kairos/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php:42
PHP 13. Symfony\Component\Config\Definition\Processor->processConfiguration() /var/www/kairos/vendor/bundles/JMS/I18nRoutingBundle/DependencyInjection/JMSI18nRoutingExtension.php:37
PHP 14. JMS\I18nRoutingBundle\DependencyInjection\Configuration->getConfigTreeBuilder() /var/www/kairos/vendor/symfony/src/Symfony/Component/Config/Definition/Processor.php:52

Need a way to ignore some bundles

I have two bundles, one requires i18n the other not.

CheFrontBundle:
    resource: "@CheFrontBundle/Controller/"
    type:     annotation
    prefix:   /

_CheAdminBundle:
    resource: "@CheAdminBundle/Controller/"
    type:     annotation
    prefix:   /admin

So i added _ to the CheAdminBundle, but it is still visible to the JMSI18nRoutingBundle bundle. However i added the _ to the route inside the bundle CheAdminBundle:

from:

@Route("/", name = "index")

to

@Route("/", name = "_index")

and this route got ignore.

However it would be a hell to prefix all the routes inside this bundle.
So is there some other way to ignore this bundle, or mayble make the

_CheAdminBundle:
    resource: "@CheAdminBundle/Controller/"
    type:     annotation
    prefix:   /admin

syntax work?

page 404 not found with JMSI18nRoutingBundle

Hello,

i use JMSI18nRoutingBundle and i would like to know how to customize the error's pages (404 error, 500 error, etc).

i use symfony 2.0.17 and i already have custom the symfony error's pages but with the JMSL18nRoutingBundle, i've got an error.

Here is the error:

Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in /home/www/hobbynote/app/cache/prod/appprodUrlMatcher.php:772 Stack trace:
#0 /home/www/hobbynote/vendor/bundles/JMS/I18nRoutingBundle/Router/I18nRouter.php(161): appprodUrlMatcher->match('/fzzfzrf')
#1 /home/www/hobbynote/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php(73): JMS\I18nRoutingBundle\Router\I18nRouter->match('/fzzfzrf')
#2 [internal function]: Symfony\Bundle\FrameworkBundle\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent))
#3 /home/www/hobbynote/vendor/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(148): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\GetResponseEvent))
#4 /home/www/hobbynote/vendor/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php(49): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'kernel.request', Object(Symfony\Component\HttpKerne in /home/www/hobbynote/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php on line 83

Translate variable from route

Hi i was wondering is they have a way to translate variable from a route , and get the original var without translation (kind of backward translation):

E.g route with translation:

route.yml :

search_by_cat:
pattern: /search/{cat}/{slug}
defaults:{_controller: AcmeBundle:search:searchByCat}

routes.en.yml

/search/{cat}/{slug}

translation file :
aws.cars : awesome-cars

call in the view (twig):
path("search_by_cat",{'cat'=aws.cars,',slug':cars.slug})

output in the view :

/search/awesome-cars/new-bwm-m5

Eg on the controller side for previous example :

public function searchByCatAction($cat,$slug) {

// output : "aws.cars" not "awesome cars"
echo $cat;

}

Thank you for your help

Make i18nLoader::ROUTING_PREFIX configurable

It would be nice to have a way to change the routing prefix. I'm using simple locale code and in my case the prefix is pretty useless and IMHO quite noisy when debugging routes using the router:debug command. I understand the need of a prefix when using complex locale codes but this prefix should be configurable.

Access the list of all available locales in Twig

Johannes, could you please document how to get an array of locales (jms_i18n_routing.locales) and default locale (jms_i18n_routing.default_locale) in Twig? This can be useful for listing all available locales in templates.

The parent definition "router.default" defined for definition "jms_i18n_routing.router" does not exist.

Hi,

I have installed your bundle as submodule in symfony RC4 (vendor/bundles/JMS). I followed your instructions and added the bundle in my kernel.

But when i call my website following exception is thrown:

RuntimeException: The parent definition "router.default" defined for definition "jms_i18n_routing.router" does not exist.

in /var/www/uplimit/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php line 63
at ResolveDefinitionTemplatesPass->resolveDefinition() in /var/www/uplimit/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php line 49
at ResolveDefinitionTemplatesPass->process() in /var/www/uplimit/vendor/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php line 109
at Compiler->compile() in /var/www/uplimit/vendor/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php line 394
at ContainerBuilder->compile() in /var/www/uplimit/app/bootstrap.php.cache line 1227
at Kernel->buildContainer() in /var/www/uplimit/app/bootstrap.php.cache line 1138
at Kernel->initializeContainer() in /var/www/uplimit/app/bootstrap.php.cache line 869
at Kernel->boot() in /var/www/uplimit/app/bootstrap.php.cache line 1038
at Kernel->loadClassCache() in /var/www/uplimit/web/app_dev.php line 17

I have added the config lines after your security extra bundle:

jms_security_extra:
secure_controllers: true
secure_all_services: false

jms_i18n_routing:
default_locale: en
locales: [en, de]
strategy: prefix

Have I done something wrong? :/

How to prevent Routing translation for some pattern (ex: /admin)

Hi

I am using this bundle to translate routes in my web application.
It works fine, but I would like some urls to not be translated, for instance those who belong to admin area that start with /admin prefix (and of course are under a Symfony2 security firewall)

Is there any easy way (I mean, using just config.yml configurations) to do so? I am unable to find it in the code

If not, is there any "not-so-easy" way to do so? :)

Thanks and regards

The requested language "en" was not available. Available languages: "nl, fr"

Hi,

I set up JMSI18nRoutingBundle with the following config:

jms_i18n_routing:
default_locale: nl
locales: [nl, fr]
strategy: prefix

Default locale is everywhere possible set on 'nl'...

Most of the time this works as intended, but sometimes the cookie gets set on 'en' and I have to delete the hl cookie to get this fixed. Although I never mention the locale 'en' the cookie still gets set on 'en', how is that possible?

wrong routes.xx.yml conten when I use locale_country (e.g. en_GB)

configuration:

jms_i18n_routing:
    default_locale: en_GB
    locales: [en_EN, en_GB]
    strategy: custom
    hosts:
        en_EN: %host_name.en_EN%
        en_GB: %host_name.en_GB%

routing file for en_GB (routes.en_GB.yml) after translation:extract or i18n:extract-routes

# Desc: /hello/{name}
GB_xxx_default_index: '/hello/{name}'   # FIXME
# Desc: /hello/{name}
xxx_default_index: '/hello/{name}'   # FIXME

Symfony documentation says:
"We recommended the ISO639-1 language code, an underscore (_), then the ISO3166 country code (e.g. fr_FR for French/France)."
(http://symfony.com/doc/2.0/book/translation.html)

"hl" cookie is set to "en" if request ends in error

Steps to reproduce it:

  1. Visit a non existing page
  2. Delete the session cookie (probably PHPSESSID) or let it expire

I'm using the prefix strategy.

If I traced it correctly, ExceptionListener is duplicating the request and while LocaleListener sets the default locale to the duplicated request, CookieSettingListener gets the locale from the original one (which still has the original language setted in the Request code).

What version should i write in composer?

Hi,

in the doc about the installation it is said:

Note: Please replace dev-master in the snippet above with the latest stable branch, for example 1.0.*.

But how can i know what is the version I have to write? Now in the repository the only branch i have found is the dev one.

Anyway I tried it with 1.0.* or 1.1.* and it says:


  Problem 1
    - The requested package jms/i18n-routing-bundle 1.0.* could not be found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

My current minimum-stability is "dev".

Javier

language_country (en_AU, en_US) locale with single translation file?

I am wondering if it's at all possible to to implement a way of using language_country based routes but have a single messages..xlf file?

Basically we need to have the full locale set in the request & session eg: en_AU or en_US but the translation (ie: english) should come from a single messages.en.xlf file.

So far I haven't managed to find a way to get this working. Am I missing something or is it currently not possible?

security.yml -> access_control : %locale% in pattern ?

Hi,

I'm using JMSI18nRoutingBundle for 3 languages : en, fr, es

In the access_control section of app/config/security.yml, I noticed that a path like ^/admin isn't translated automatically as ^/fr/admin or any defined language, unlike in app/config/routing.yml, so that all the defined paths in access_control aren't catched (thus protected) by the firewall anymore (which leads to a main security issue).

The only way I found to circumvent this is to specify all the available languages for all paths, like this :

access_control:
        - { path: ^/(en|fr|es)/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/(en|fr|es)/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/(en|fr|es)/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/(en|fr|es)/admin, role: ROLE_ADMIN }

But this is not very pleasant, if one have a more complex ACL or add another language, we have to add the new language in all paths.

As a feature in a further commit for JMSI18nRoutingBundle, could you please add the possibility to use the global var %locale% in the ACL paths, like this :

access_control:
        - { path: ^/%locale%/admin, role: ROLE_ADMIN }

Or maybe there's already a workaround for this, but I couldn't find any (_locale doesn't work either).

Thanks in advance.

Firewall security login setting not localized

I have the below setting in my security.yml:

    secured_area:
        pattern:    ^/
        anonymous: ~
            form_login:
                login_path:  /login
                check_path:  /login_check

Whit this config when accessing the secured area without properly authenticated I got redirected to "/login" instead of the localized version.
Is there some settings I missed or is this a bug?

Permanent Redirect in prefix mode

Hi,
at the moment there is an 302 http code when redirecting to the localized page in prefixing mode. Can we change it to an permanent redirect (301)? It's better for SEO and avoids indexing as duplicated content.

I think change is required in JMS\I18nRoutingBundle\EventListener\LocalChoosingListener.php l. 50 as second parameter for the RedirectResponse.

Thank you.

Make use of the new Routing optimizations for prefixes

I am sure you are aware of the recent PR symfony/symfony#5734 that optimizes the route matcher for prefixes. And I can't imagine a better suited case for this PR as the locale-prefixed routes that the i18n routing bundle creates, performance would be much better as all the routes for a given locale would be grouped together. I'll have a look at it and see if it's possible.

Fatal Error after updating to lates Symfony2.1

hi,

i have just updated symfony 2.1 with composer, and i get a fatal error on my application:

[ErrorException]                                                                                                                                                                                                                                                     
  Catchable Fatal Error: Argument 5 passed to JMS\I18nRoutingBundle\Router\I18nRouter::__construct() must be an array, object given, called in /coding/af_release_1/app/cache/dev/appDevDebugProjectContainer.php on line 2292 and defined in /coding/af_release_1/ve  
  ndor/jms/i18n-routing-bundle/JMS/I18nRoutingBundle/Router/I18nRouter.php line 43         

Possibility and/or best way to use this bundle with annotations

Hi,

First, thank you for this very useful bundle!

I'm trying to use it with annotations into controllers without entire success... Have you an example about this utilization?

Here is my config parameters:

jms_i18n_routing:
    default_locale: en
    locales: [en, fr]
    strategy: prefix_except_default

What I'd want is 2 distinct URLs like these for example:

  • /welcome
  • /fr/bienvenue

Thank you for your help!

Translate an URL in the controller

Hello!

My language switcher is quite simple :

$this->getRequest()->getSession()->setLocale($locale);
$url = $this->getRequest()->headers->get('referer');
return new RedirectResponse($url);

It allows me to switch language and to be redirected to the current page. But doesn't work with the Bundle because the redirection url is still in the last language used (so the page is never translated, except on pages where there is no URL translations).

Is it possible to get a way to translate an URL in the controller ?

Thanks,

Please push the latest commit to packagist

Hello,

I would like to implement the new use_cookie feature in our project, because the cookie is the cause of a bug.
However, we use Symfony with composer and this commit is not in packagist yet. Could you please push the latest commit up there?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.