Class: Utopia::Localization::RequestWrapper
- Inherits:
-
Object
- Object
- Utopia::Localization::RequestWrapper
- Defined in:
- lib/utopia/localization.rb
Overview
A wrapper to provide easy access to locale related data in the request.
Instance Method Summary collapse
-
#all_locales ⇒ Object
Returns an empty array if not localized.
-
#current_locale ⇒ Object
Returns the current locale or nil if not localized.
-
#default_locale ⇒ Object
Returns the default locale or nil if not localized.
-
#initialize(request) ⇒ RequestWrapper
constructor
A new instance of RequestWrapper.
- #localization ⇒ Object
Constructor Details
#initialize(request) ⇒ RequestWrapper
Returns a new instance of RequestWrapper.
28 29 30 31 32 33 34 |
# File 'lib/utopia/localization.rb', line 28 def initialize(request) if request.is_a? Rack::Request @env = request.env else @env = request end end |
Instance Method Details
#all_locales ⇒ Object
Returns an empty array if not localized.
51 52 53 |
# File 'lib/utopia/localization.rb', line 51 def all_locales localization && localization.all_locales || [] end |
#current_locale ⇒ Object
Returns the current locale or nil if not localized.
41 42 43 |
# File 'lib/utopia/localization.rb', line 41 def current_locale @env[CURRENT_LOCALE_KEY] end |
#default_locale ⇒ Object
Returns the default locale or nil if not localized.
46 47 48 |
# File 'lib/utopia/localization.rb', line 46 def default_locale localization && localization.default_locale end |
#localization ⇒ Object
36 37 38 |
# File 'lib/utopia/localization.rb', line 36 def localization @env[LOCALIZATION_KEY] end |