0

My website is localized in two languages right now:

www.website.com/book

www.website.com/de/book

I just use the "de" local, not the "en" in the url.

Is there a way to change the de-urls to e.g.

www.website.com/de/buch

without using an extra gem? I already use the globalize gem but due to many problems in the past I prefer to use as few gems as possible.

Part of my application.rb is:

class Application < Rails::Application

config.active_record.whitelist_attributes = false

config.i18n.default_locale = :en
config.i18n.available_locales = [:en, :de]
config.i18n.fallbacks = true
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
config.i18n.enforce_available_locales = true

Part of my application_controller.rb is:

before_filter :set_locale

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

def default_url_options(options = {})
    { :locale => ((I18n.locale == I18n.default_locale) ? nil : I18n.locale) }.merge options
end

The routes are localized too.

user929062
  • 807
  • 4
  • 12
  • 33

1 Answers1

0

https://github.com/norman/friendly_id-globalize does exactly what you want.

It is however, indeed a gem.

The point is, if you are not willing to use a gem, you would have to write about as much code as is in the gem yourself, since there is no easy way to accomplish these kind of translated slug urls.

Such a thing would however far exceed the boundaries of a Q&A format like stackoverflow.

Arjan
  • 6,264
  • 2
  • 26
  • 42