Module: Padrino::Contrib::AutoLocale
- Defined in:
- lib/padrino-contrib/auto_locale.rb
Overview
This extension give to padrino the ability to change their locale inspecting.
Usage
class MyApp < Padrino::Application
register AutoLocale
set :locales, [:en, :ru, :de] # First locale is the default locale
end
# view.haml
=link_to "View this page in RU Version", switch_to_lang(:ru)
So when we call an url like: /ru/blog/posts this extension set for you :ru as I18n.locale
Defined Under Namespace
Modules: ClassMethods, Helpers
Class Method Summary collapse
- .padrino_route_added(route, verb, path, args, options, block) ⇒ Object
-
.registered(app) ⇒ Object
Helpers.
Class Method Details
.padrino_route_added(route, verb, path, args, options, block) ⇒ Object
42 43 44 |
# File 'lib/padrino-contrib/auto_locale.rb', line 42 def self.padrino_route_added(route, verb, path, args, , block) route.instance_variable_set(:@original_path, "/:lang#{route.original_path}") unless route.original_path =~/:lang/ end |
.registered(app) ⇒ Object
Helpers
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/padrino-contrib/auto_locale.rb', line 29 def self.registered(app) app.helpers Padrino::Contrib::AutoLocale::Helpers app.extend ClassMethods app.set :locales, [:en] app.before do if request.path_info =~ /^\/(#{settings.locales.join('|')})\b/ I18n.locale = $1.to_sym else I18n.locale = settings.locales[0] not_found if request.path_info !~ /^\/?$/ end end def self.padrino_route_added(route, verb, path, args, , block) route.instance_variable_set(:@original_path, "/:lang#{route.original_path}") unless route.original_path =~/:lang/ end end |