Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] UrlGenerator should try locale xx_XX and xx for i18n routes  #28733

Closed
@ampaze

Description

@ampaze

Symfony version(s) affected: 4.1.5

Description
When defining i18n routes, with only a language and not a combination of language and region, the fallback mechanism via _canonical_route does not work, when the locale contains both language and region.

How to reproduce

locale: en_US
petition_show:
    path:
        de: /petitionen/{id}/{slug}
        en: /petitions/{id}/{slug}
$this->generateUrl('petition_show', ...

Gives the error:
Unable to generate a URL for the named route "petition_show" as such route does not exist.

Possible Solution

UrlGenerator::generate should check both the full locale and only the language part of the locale.
This would have to be reflected in PhpGeneratorDumper::generateGenerateMethod.

Additional context

This would be the same behaviour as the for example the translator works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions