class Wrapper
A wrapper to provide easy access to locale related data in the request.
Definitions
def initialize(env)
Initialize a localization wrapper for a Rack environment.
Signature
-
parameter
envHash The Rack environment.
Implementation
def initialize(env)
@env = env
end
def localization
Fetch the localization middleware associated with this request.
Signature
-
returns
Middleware | Nil The localization middleware, when active.
Implementation
def localization
@env[LOCALIZATION_KEY]
end
def localized?
Check whether the request path includes a locale.
Signature
-
returns
Boolean Whether localization is active for the current request.
Implementation
def localized?
localization != nil
end
def current_locale
Returns the current locale or nil if not localized.
Implementation
def current_locale
@env[CURRENT_LOCALE_KEY]
end
def default_locale
Returns the default locale or nil if not localized.
Implementation
def default_locale
localization && localization.default_locale
end
def all_locales
Returns an empty array if not localized.
Implementation
def all_locales
localization && localization.all_locales || []
end
def localized_path(path, locale)
Build a path with the selected locale.
Signature
-
parameter
pathUtopia::Path | String The path.
-
parameter
localeString The locale.
-
returns
String The locale-prefixed path.
Implementation
def localized_path(path, locale)
"/#{locale}#{path}"
end