Giter VIP home page Giter VIP logo

Comments (4)

enriclluelles avatar enriclluelles commented on August 14, 2024

It looks like it's translating city to ville... Will take a look later. Thanks for the info

from route_translator.

optimum-dulopin avatar optimum-dulopin commented on August 14, 2024

hi,
after few hours of research, I found difference between 2.0.1 and 3.0.1
on 2.0.1
translations_for method return [route.app, conditions, requirements, defaults, new_name] where
requirements = { :city_id => /\d+/, :category_id => /\d+/, :user_id => /\d+/, :subcategory_id => /\d+/, :prefixid => /[A-Z]{3}/, :controller=>"annonces", :action=>"index"}
and
conditions = {:path_info=>"/fr/(:userslug(-:user_id)/)...', :request_method=>/^GET$/}

but on 3.0.1
translations_for method call add_route on [app, new_conditions, new_requirements, new_defaults, new_route_name, anchor] where
new_requirements = { :city_id => /\d+/, :category_id => /\d+/, :user_id => /\d+/, :subcategory_id => /\d+/, :prefixid => /[A-Z]{3}/, :controller=>"annonces", :action=>"index"}
and
new_conditions = { :city_id => /\d+/, :category_id => /\d+/, :user_id => /\d+/, :subcategory_id => /\d+/, :prefixid => /[A-Z]{3}/, :controller=>"annonces", :action=>"index", :path_info=>"/fr/(:userslug(-:user_id)/)...', :request_method=>/^GET$/}

so if I just change condition and remove all what is already in new_requirements (ie I just keep conditions = {:path_info=>"/fr/(:userslug(-:user_id)/)...', :request_method=>/^GET$/}) then it is working fine.

it seems it is

      mapping = Mapping.new(@set, @scope, path, options)
      app, conditions, requirements, defaults, as, anchor = mapping.to_route

which is giving this values to conditions. So is that me who is doing something bad ? is it normal to have this contraints in conditions ?

because when such, It is bugging on journey
routes.sort_by(&:precedence).find_all { |r|

133 r.constraints.all? { |k,v| v === req.send(k) } &&

134 r.verb === req.request_method

135 }
saying that req.send(k) is incorrect as "undefined method `city_id' for #ActionDispatch::Request:0x00000006041ec8"

any idea ?

thanks

from route_translator.

enriclluelles avatar enriclluelles commented on August 14, 2024

I'm sorry but I didn't quite get your question. I suggest that next time you report and issue like this you wrap your code with ```

Although what happened with city and ville was partly my fault because I think I made a mistake when adding unscoped fallbacs in translations. I've deleted that in version 3.1.0 of the gem

I did a quick test with this in config/routes.rb:

RouteTranslator32TestApp::Application.routes.draw do
  localized do
    get 'products_path', {
      controller: 'products',
      action: 'index',
      constraints: { 
        city_id: /\d+/,
        category_id: /\d+/,
        user_id: /\d+/,
        subcategory_id: /\d+/,
        prefixid: /[A-Z]{3}/
      },
      as: :products
    }
  end
end

config/locales/all.yml

fr:
  routes:
    products_path: "(:userslug(-:user_id)/)articles(/:categoryslug-:rubrique_id(/:subcategoryslug-:subcategory_id))(/:cityslug-_:city_id)(/:productslug-:prefixid:id)(/:action)"

Then I tried running rake routes and the output it showed me was:

products_en GET /products_path(.:format)                                                                                                                                                  products#index {:city_id=>/\d+/, :category_id=>/\d+/, :user_id=>/\d+/, :subcategory_id=>/\d+/, :prefixid=>/[A-Z]{3}/, :locale=>"en"}
products_fr GET /fr/(:userslug(-:user_id)/)articles(/:categoryslug-:rubrique_id(/:subcategoryslug-:subcategory_id))(/:cityslug-_:city_id)(/:productslug-:prefixid:id)(/:action)(.:format) products#index {:city_id=>/\d+/, :category_id=>/\d+/, :user_id=>/\d+/, :subcategory_id=>/\d+/, :prefixid=>/[A-Z]{3}/, :locale=>"fr"}

So I guess it works

Although I will give you one bit of advice regarding the route structure that you chose and adding it to the translation value: Don't do that.
It's hard to read, hard to spot mistakes in it, and adds no value. You're way better of defining your route with namespaces or scopes like its shown in the guides

from route_translator.

optimum-dulopin avatar optimum-dulopin commented on August 14, 2024

Hi,
I know it is not best solution, but it was just the most easy for me and actually the only one that fullfill all my requirements.
I put new version of route translator, but I still have the same easy and need to easy my little patch to make it work.

And I have another kind of issue. Im using nginx, and I have to make their a rewrite and I dont know why but for utf8 characters, it rewrite it lowercased

here is a route : /ka/განცხადებები

/ka/%E1%83%92%E1%83%90%E1%83%9C%E1%83%AA%E1%83%AE%E1%83%90%E1%83%93%E1%83%94%E1%83%91%E1%83%94%E1%83%91%E1%83%98/

become

/ka/%e1%83%92%e1%83%90%e1%83%9c%e1%83%aa%e1%83%ae%e1%83%90%e1%83%93%e1%83%94%e1%83%91%e1%83%94%e1%83%91%e1%83%98

ie all uppercase letter become lowercase, that cause à pb with my rails app.

and because of this, my route are not recognized. if I changed just this and have other uft8 letters (lowercased also) in params, rails can convert and handle them normally.

Just routes are not recognized, ie %E1%83%92%E1%83%90%E1%83%9C%E1%83%AA%E1%83%AE%E1%83%90%E1%83%93%E1%83%94%E1%83%91%E1%83%94%E1%83%91%E1%83%98

is different than
%e1%83%92%e1%83%90%e1%83%9c%e1%83%aa%e1%83%ae%e1%83%90%e1%83%93%e1%83%94%e1%83%91%e1%83%94%e1%83%91%e1%83%98

whereas it should be equal as it is
განცხადებები

do u know what could be the reason ?

thanks

from route_translator.

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.