raul / translate_routes Goto Github PK
View Code? Open in Web Editor NEWRails plugin to translate your URLs and routing helpers on an clean way.
License: MIT License
Rails plugin to translate your URLs and routing helpers on an clean way.
License: MIT License
This commit removed option which I found very usefull. What was the logic behind this change.
What I need, is to use non-localized root to detect the locale, and use language prefix on every variation. How to acomplish this with never versions?
In your lib/tasks/translate_routes_tasks.rake you were requiring 'environment' which had as consequence to require 'environment' in every task, because rails require plugins rakefiles and tasks automatically.
The problem is you do not always want to require the environment. When deploying for example, you may have rake task to copy database.yml.sample to database.yml which is not requiring environment because the environnment is not configured ( ie : database.yml is not present ). This is going to fail because of misconfigured environment, blocking you from deploying correctly.
This scenario can be reproduced when using both inploy and your plugin.
The solution is to make your rake task depending on the environment task instead of just requiring it which have a side effect as explained.
You can find in my fork a corrected version of your task, and in my pull request.
Regards,
Hi
Where do I set the prefix_on_default_locale configuration option?
I did not find it on the wiki.
Kind regards,
Michael
Hi,
When using the plugin with rails 3.0.1, I encounter an error while showing the "link_to edit_model-name_path(instance). The plugin mistake the param instance for the param locale.
The workaround is using edit_model-name_path(:id => instance.id), but I don't think it is how it should be.
Regards
Hey,
I was playing around with Ruby 1.9.2+Rails 3.1 and noticed that translate_routes doesn't work with this version. It gives the following error:
route_translator.rb:223:in `gsub': wrong argument type nil (expected Regexp) (TypeError)
Anyone got it working with 3.1? Any plans to bring support for the new version?
Hi.
good plugin
link_to [:admin, @my_object]
or form_for [:admin, @my_object]
not work in rails-3.1.rc4 and throw exception:
undefined method `hash_for_admin_my_object_path' for #<Module:0x617e050>
Hi!
I need some times the root_path helper without locale. Is there a possibility to get it with example root_path(:no_locale) or something else?
Bye
Hey,
I'm porting an application to Rails 3, I dumped search_logic in favor of meta_search. I'm having some problems with the sort helpers generated by meta_search in combination of translated_routes, if I don't set the before_filter :set_locale_from_url in application controller everything seems to be working ok, but if is set (even if it returns the same default language set in application.rb) the meta_search helper brokes up telling it can find the route used in the helper:
No route matches {:search=>{"meta_sort"=>"name.asc"}, :locale=>:es, :controller=>"users"}
I took a look to the before_filter method and the problem seems to be in:
default_url_options.merge! RouteTranslator::LOCALE_PARAM_KEY => I18n.locale
If instead of the merge! I use:
default_url_options = {RouteTranslator::LOCALE_PARAM_KEY => I18n.locale}
The :locale => :es is also set correctly and everything works as expected, I don't know about translate_routes internals so, is there any other options being used in default_url_options requiring to use the merge?
I've created a sample app https://github.com/francesc/TranslateRoutesMetaSearchBug in case anynone wants to try it out (uncomment the before_filter to see the error).
I am using the gem in my work using Rails 3, and ruby 1.9.2 and it was working like a charm until I tried to include action caching, it gives me the following error:
Routing Error
No route matches {:format=>nil, :locale=>:en, :controller=>"pages", :action=>"show", :id=>"home"}
When I commented this line in routes.rb:
ActionDispatch::Routing::Translator.translate_from_file('config','i18n-routes.yml')
The Action caching worked fine...
I'm getting this error when I rake routes in the console and it seems to be coming from my map.namespace
rake aborted!
private method `gsub' called for #Hash:0x1f1ca38
Here's the routing in question:
map.namespace :user do |user|
user.resources :articles do |articles|
articles.resources :comments
articles.resources :tags
end
end
Hi,
In my app I'm not using a prefix in the urls. The current language come from the HTTP_ACCEPT_LANGUAGE var in the request header or from my user logic.
I did have a check but I could not see a way to turn this off.
To fix this I simply created a new flag in translate_routes.rb and wrapped the prefix logic and all worked :)
translate_routes.rb
mattr_accessor :apply_prefix
@@apply_prefix = true
def self.locale_segments(orig, locale)
...
if @@apply_prefix
if add_prefix?(locale) # initial prefix i.e: /en-US
divider = DividerSegment.new(orig.segments.first.value, :optional => false) # divider ('/')
static = StaticSegment.new(locale, :optional => false) # static ('en-US')
segments += [divider, static]
end
end
...
end
and then in my case to turn it off I simply set the apply_prefix to false in my routes.rb:
ActionController::Routing::Translator.apply_prefix = false
Not sure if this is a feature you would consider.
Cheers,
Nick
Hi
First off; thanks for the awesome open source.
I really have no way of knowing if this is an issue or expected behaviour, though it seems strange.
In my production log I see the following repeated frequently, always in succession.
Translating routes (default locale: en)
Translating routes (default locale: es)
It would seem expected behaviour not to translate the routes using the non-default and I worry that google might find duplicate content. Please advise and thanks again.
Mark
I have an old Rails 2.1.2 application. There are reasons why I don't want to upgrade it, so I must work with version metioned.
I have installed a plugin for routes translation (raul/translate_routes) from an old R2.1 branch. It works great, with one exception. When I switch my default language (pl) I'm losing all 'english' routes. It's a problem as the website is public and 'english' routes have been widely indexed by Google.
mysite.com/produkty -> works
mysite.com/products -> don't work
I tried to setup redirects in routes.rb. But:
map.connect 'blahblahblah', :controller => 'redirect', :action => 'index'
works, while
map.connect 'users', :controller => 'redirect', :action => 'index'
don't work.
It means: if I have resource :users in routes.rb and I use translation for routes, something blocks my attempts to redirect "not translated" route somewhere. I guess, translated_routes somehow "takes for themselves" this route ('users').
Do You see my problem and any solution for it?
Can I do something that will make '/users' route working even with :pl locale set (or make working a redirection for this route)?
(I am thinking even about redirects at Apache .htaccess level)
Hi,
While rendering link_to root_path, the link rendered is always of the tpe http://www.example.com/?locale=choosen_language and the locale is not set.
Regards.
Hi,
I'm using rails 3.0.1, I used your plugin. Works great in development.
Give error "uninitialized constant ActionDispatch::Routing::Translator" in production environment.
Any idea how to solve this?
Michael
I use match "*url_match" for catching all unrecognized URLs and then work on them in special controller.
I expect that including translate_routes gem will bring me such routes as ":locale/*url_match"
But error occured. Wrong argument type nil (expected Regexp) in /lib/route_translator.rb:223 in 'gsub'
When you try write some scenarios in Cucumber, there are issues related with ActionController::Integration::Session (name error).
Hi !
I have error in app console.
My steps for sample application:
root_path' for class
ActionController::Integration::Session'public' from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:98:in
reset!'module_eval' from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/integration.rb:98:in
reset!'initialize' from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/console_app.rb:19:in
new'new_session' from /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/console_app.rb:11:in
app'I get the same error in my application with 2.3.5 rails.
WBR,
atlancer
P.S.
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux], MBARI 0x8770, Ruby Enterprise Edition 2009.10
Which leads to the controller not knowing what locale should be used to save fields with Globalize2
Is it somehow possible to remove the default locale? The plugin seems always to add a route for English.
Hello,
I am testing translate_routes with Redmine. I translated 'projects' to 'proiecte' and now I get 404 when submiting a new wiki page.
My modified files are config/routes.rb[1], locales/i18n-routes.yml[2] and app/controllers/application_controller.rb[3], as indicated on this wiki.
I also tried the solution to avoid applying prefix[4](I thought this might be the problem).
I don't have a clue why this is not working. Can you help me?
Thanks,
Tibi
[1] http://pastebin.com/f1247f18
[2] http://pastebin.com/f1f20e975
When running rspec against my controllers, I get "no route matches" errors for all the actions.
If I comment out the line that does the translation at routes.rb, everything is back to normal.
Curiously enough, this bug doesn't happen on my integration tests with Steak, it's only happening on the controller specs.
I've created a sample app to reproduce the problem:
https://github.com/jaimeiniesta/rspectransbug
Thanks!
When using Devise 1.1.5 with 2 models, Admin and User, it looks like translate_routes only gets the first devise route in routes.rb.
I've created a sample app to reproduce the bug:
https://github.com/jaimeiniesta/devisetransbug
Start the app, go to http://localhost:3000/users/sign_in and look into the locale switch link at the bottom. It should point you to /es/usuarios/entrar but it goes to /es/administradores/entrar instead.
I have some routes without format parameter and that breakes the gem.
The problems lines in the lines 222 and 223 from the routes_translater.rb (as far as I can tell)
final_optional_segments = path.match(/(\(.+\))$/)[1] rescue nil # i.e: (.:format)
path_segments = path.gsub(final_optional_segments,'').split("/")
When a routes doesn't have the format, the variable final_optional_segments is nil. Then the gsub in the next line fails.
Or do you see a different problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.