Skip to content

Routing with locale? #144

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

Closed
jmuheim opened this issue May 19, 2014 · 4 comments
Closed

Routing with locale? #144

jmuheim opened this issue May 19, 2014 · 4 comments

Comments

@jmuheim
Copy link

jmuheim commented May 19, 2014

I'd like to you high_voltage, but it doesn't seem to know about handling a locale in the path itself.

I stumbled over this post on stack overflow:
http://stackoverflow.com/questions/19809898/high-voltage-gem-routing-with-locale

So I suggest you guys take a look there and provide an answer. This would be really useful.

Thanks a lot!
Josh

@mmhan
Copy link

mmhan commented Jul 17, 2014

I'd like to upvote this. Is there no way this could be resolved?

@harlow
Copy link
Contributor

harlow commented Jul 19, 2014

Hi @jmuheim @mmhan I'm copying this response over from a previous HighVoltage issue.

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 nested URLs with locales 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 site

# 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 Jul 20, 2014

I've added a PR to update the REAME with instructions for localization. #156

Closing the issue, feel free to leave comments on the PR if any of the instruction here don't make sense.

@harlow harlow closed this as completed Jul 20, 2014
@mmhan
Copy link

mmhan commented Jul 29, 2014

Got it, Thanks!

On Mon, Jul 21, 2014 at 3:49 AM, Harlow Ward [email protected]
wrote:

Closed #144 #144.


Reply to this email directly or view it on GitHub
#144 (comment).

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