Class: Utopia::Localization::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/localization.rb

Overview

A wrapper to provide easy access to locale related data in the request.

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Wrapper

Returns a new instance of Wrapper.



13
14
15
# File 'lib/utopia/localization.rb', line 13

def initialize(env)
	@env = env
end

Instance Method Details

#all_localesObject

Returns an empty array if not localized.



36
37
38
# File 'lib/utopia/localization.rb', line 36

def all_locales
	localization && localization.all_locales || []
end

#current_localeObject

Returns the current locale or nil if not localized.



26
27
28
# File 'lib/utopia/localization.rb', line 26

def current_locale
	@env[CURRENT_LOCALE_KEY]
end

#default_localeObject

Returns the default locale or nil if not localized.



31
32
33
# File 'lib/utopia/localization.rb', line 31

def default_locale
	localization && localization.default_locale
end

#localizationObject



17
18
19
# File 'lib/utopia/localization.rb', line 17

def localization
	@env[LOCALIZATION_KEY]
end

#localized?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/utopia/localization.rb', line 21

def localized?
	localization != nil
end

#localized_path(path, locale) ⇒ Object



40
41
42
# File 'lib/utopia/localization.rb', line 40

def localized_path(path, locale)
	"/#{locale}#{path}"
end