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

highvoltage routing with locale. #109

Closed
talhait07 opened this issue Nov 6, 2013 · 6 comments
Closed

highvoltage routing with locale. #109

talhait07 opened this issue Nov 6, 2013 · 6 comments

Comments

@talhait07
Copy link

I am using this gem.I am facing a problem with routing.
I am getting something like this :
localehost:3000/pages/privacy-policy?locale=en
But i need the url to be :
localhost:3000/en/pages/privacy-policy

In my routes file i wrote:
scope ":locale", locale: /en|bn|hi/ do
match "/pages/:id" => 'pages#show', :as => :page, :format => false
end

what should i do now.

@talhait07
Copy link
Author

Is any one there to checkout this issue?

@harlow
Copy link
Contributor

harlow commented Nov 7, 2013

Hello @talhait07 I suggest that you read over the Rails I18n page here:
http://guides.rubyonrails.org/i18n.html

There are several components to getting Rails to work with localization.

Add a before filter to your Application controller

# app/controllers/application_controller.rb
before_action :set_locale

def set_locale
  I18n.locale = params[:locale] || I18n.default_locale
end

Disable the default High Voltage routes

# config/initializers/high_voltage.rb
HighVoltage.configure do |config|
  config.routes = false
end

Set up the routes file

# config/routes.rb
scope "/:locale", locale: /en|bn|hi/ do
  get "/pages/:id" => 'high_voltage/pages#show', :as => :page, :format => false
end

Add a page to the applcation

# app/views/pages/about.html.erb
<%= t 'hello' %>

Make sure that there are corresponding locale files

/config/locale/en.yml
/config/locale/bn.yml

One last note is there is a know issue with High Voltage.

You'll need to specify routes like this <%= link_to 'About Us', page_path(id: 'about') %>

Hopefully this is enough information to get you started with localization

@harlow
Copy link
Contributor

harlow commented Jan 3, 2014

Closing the thread. Feel free to open back up if the last response isn't working as expected.

@harlow harlow closed this as completed Jan 3, 2014
@BGuimberteau
Copy link

Hi when i try to scope high_voltage with locale i get this error :

actionpack-4.0.4/lib/action_dispatch/routing/route_set.rb:428:in `add_route': Invalid route name, already in use: 'page'  (ArgumentError)
You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming.

Do you make your test with Rails 4 ?

Thanks in advance for your answer.

@harlow
Copy link
Contributor

harlow commented Mar 28, 2014

@BGuimberteau I believe you'll need to disable to default routes that High Voltage creates.

# config/initializers/high_voltage.rb
HighVoltage.configure do |config|
  config.routes = false
end

@BGuimberteau
Copy link

Neat! Just perfect, thank you very much.

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

3 participants