Class: Utopia::Localization::Wrapper
- Inherits:
-
Object
- Object
- Utopia::Localization::Wrapper
- Defined in:
- lib/utopia/localization/wrapper.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(env) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #localization ⇒ Object
- #localized? ⇒ Boolean
- #localized_path(path, locale) ⇒ Object
Constructor Details
#initialize(env) ⇒ Wrapper
Returns a new instance of Wrapper.
16 17 18 |
# File 'lib/utopia/localization/wrapper.rb', line 16 def initialize(env) @env = env end |
Instance Method Details
#all_locales ⇒ Object
Returns an empty array if not localized.
39 40 41 |
# File 'lib/utopia/localization/wrapper.rb', line 39 def all_locales localization && localization.all_locales || [] end |
#current_locale ⇒ Object
Returns the current locale or nil if not localized.
29 30 31 |
# File 'lib/utopia/localization/wrapper.rb', line 29 def current_locale @env[CURRENT_LOCALE_KEY] end |
#default_locale ⇒ Object
Returns the default locale or nil if not localized.
34 35 36 |
# File 'lib/utopia/localization/wrapper.rb', line 34 def default_locale localization && localization.default_locale end |
#localization ⇒ Object
20 21 22 |
# File 'lib/utopia/localization/wrapper.rb', line 20 def localization @env[LOCALIZATION_KEY] end |
#localized? ⇒ Boolean
24 25 26 |
# File 'lib/utopia/localization/wrapper.rb', line 24 def localized? localization != nil end |
#localized_path(path, locale) ⇒ Object
43 44 45 |
# File 'lib/utopia/localization/wrapper.rb', line 43 def localized_path(path, locale) "/#{locale}#{path}" end |