Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation routing I18l is not working for Symfony 3.4 #112

Open
kusiu opened this issue Mar 1, 2018 · 2 comments
Open

Annotation routing I18l is not working for Symfony 3.4 #112

kusiu opened this issue Mar 1, 2018 · 2 comments

Comments

@kusiu
Copy link

kusiu commented Mar 1, 2018

I18nRoutingBundle doesn't seem to be working for Symfony 3.4.

JobController.php

use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute;

class JobController extends Controller
{
    /**
     *
     * @I18nRoute({ "en": "/jobs", "pl": "/ogloszenia" }, name="jobs")
     * @Method("GET")
     */
    public function jobsListAction()
    {
        $jobs = $this->getDoctrine()
            ->getRepository(Job::class)
            ->findAllActive();
    
        return $this->render('job/list.html.twig', [
            'jobs' => $jobs,
        ]);
    }
}

config.yml

be_simple_i18n_routing:
    annotations: true

error:

An exception has been thrown during the rendering of a template ("I18nRoute "jobs" (pl) does not exist.").
@kusiu
Copy link
Author

kusiu commented Mar 14, 2018

Ok, to fix the problem new BeSimple\I18nRoutingBundle\BeSimpleI18nRoutingBundle() needs to be placed at the beginning of bundles list in AppKernel.php

Its actually half fixed. I realised that standard annotation@Route() doesn't work.

Anyone?

@kusiu kusiu closed this as completed Mar 14, 2018
@kusiu kusiu reopened this Mar 14, 2018
@Sentence
Copy link

Sentence commented Jul 6, 2018

It works for me on multiple project with these, like yours:
(But i forked this project to update some things :))

config.yml

parameters:
    locales: [hu, en, de] # change them to [en, pl]

# ...

be_simple_i18n_routing:
    annotations: true

controlelr:

use BeSimple\I18nRoutingBundle\Routing\Annotation\I18nRoute;

class DefaultController extends Controller
{
    /**
     * @I18nRoute({"hu": "/fooldal/", "en": "/homepage/", "de": "/startseite/"}, name="homepage")
     */
    public function indexAction(Request $request)
    {
        // ...

Use method restrictions in route declaration, like this:
@I18nRoute({ "en": "/jobs", "pl": "/ogloszenia" }, name="jobs", methods={"GET"})


So probably you missed the locales in parameter section, but you can try add these line to config.yml:

parameters:
    locale: en

framework:
    translator: { fallbacks: ['%locale%'] }

Or try in routing.yml:

app:
    resource: '@AppBundle/Controller/'
    type: annotation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants