Giter Club home page Giter Club logo

Comments (6)

willdurand avatar willdurand commented on August 15, 2024

I'm not sure it's related to the JsRoutingBundle, and I don't want to add tweaks/hacks for other bundles that are not more than widely used.

from fosjsroutingbundle.

z3yo avatar z3yo commented on August 15, 2024

Of course I understand, but by default, the router uses the following to determine which locale to use for route generation:
1 . the _locale parameter which was passed to the generate() method
2 . use the _locale parameter which is present in the request context
3 . use the configured default locale

But with the JS generate() function all of that seems to be ignored. I don't understand why ...

from fosjsroutingbundle.

stof avatar stof commented on August 15, 2024

@z3yo The I18nRoutingBundle extends the Symfony router to choose the route name according to the locale (prepending it). The JS code is not changed when including the bundle. So you would need to use the route name generated with the locale in it.

from fosjsroutingbundle.

z3yo avatar z3yo commented on August 15, 2024

I replaced JMSi18nRoutingBundle by BeSimpleI18nRoutingBundle, it process with a different way and works well with FOSJsRoutingBundle.

from fosjsroutingbundle.

pinano avatar pinano commented on August 15, 2024

I was having the same issue as @z3yo because I was loading the router files in the "assetic" way in my base template:

{% javascripts output='js/routing.js'
  'bundles/fosjsrouting/js/router.js'
  'js/fos_js_routes.js' %}
  <script src="{{ asset_url }}"></script>
{% endjavascripts %}

This was not working for me even after dumping the routes with the fos:js-routing:dump command, since all i18n routes were prefixed with "LOCALE__RG__". and using Routing.generate('my_route') inside my javascripts wasn't findindg the appropriate route.

But then I thougt I could give a try at loading the fos_js_router resources the "traditional" way:

<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>

and it's working like a charm now. I don't even need to dump the js routes anymore as the fos.Router.setData method takes care of looking for exposed routes as far as I understand. Now I can successfully use Routing.generate('my_route') inside any js script and it just creates the route in the currently selected locale.

Hope it helps.

from fosjsroutingbundle.

stof avatar stof commented on August 15, 2024

fos.Router.setData is just the JSONP callback. Taking care of exposed routes is done server-side (and the different between the controller and the command looks weird)

from fosjsroutingbundle.

Related Issues (20)

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.