2012-01-17 16:04:45 +00:00
|
|
|
module Locomotive
|
|
|
|
module ActionController
|
|
|
|
module LocaleHelpers
|
|
|
|
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2012-02-09 10:36:10 +00:00
|
|
|
helper_method :current_content_locale, :localized?
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def current_content_locale
|
|
|
|
::Mongoid::Fields::I18n.locale
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def set_current_content_locale
|
|
|
|
if params[:content_locale].present?
|
|
|
|
session[:content_locale] = params[:content_locale]
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
unless current_site.locales.include?(session[:content_locale])
|
|
|
|
session[:content_locale] = current_site.default_locale
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
::Mongoid::Fields::I18n.locale = session[:content_locale]
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
self.setup_i18n_fallbacks
|
2012-01-26 01:33:39 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
# logger.debug "*** content locale = #{session[:content_locale]} / #{::Mongoid::Fields::I18n.locale}"
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def set_back_office_locale
|
|
|
|
::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale
|
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def back_to_default_site_locale
|
|
|
|
session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale
|
|
|
|
end
|
2012-01-26 15:51:32 +00:00
|
|
|
|
2012-02-05 23:54:09 +00:00
|
|
|
def setup_i18n_fallbacks
|
|
|
|
(current_site.locales || []).each do |locale|
|
|
|
|
::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))
|
2012-01-26 01:33:39 +00:00
|
|
|
end
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
|
2012-02-09 10:36:10 +00:00
|
|
|
def localized?
|
|
|
|
!!@locomotive_localized
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
def localized(enable_it = true)
|
|
|
|
before_filter do |c|
|
|
|
|
c.instance_variable_set(:@locomotive_localized, enable_it)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-01-17 16:04:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|