lib/refinery/i18n.rb in refinerycms-i18n-0.9.9.12 vs lib/refinery/i18n.rb in refinerycms-i18n-0.9.9.13
- old
+ new
@@ -25,20 +25,20 @@
::Refinery::I18n.enabled? ? { :locale => ::I18n.locale } : {}
end
def find_or_set_locale
if ::Refinery::I18n.enabled?
+ ::I18n.locale = ::Refinery::I18n.current_locale
+
if ::Refinery::I18n.has_locale?(locale = params[:locale].try(:to_sym))
- ::I18n.locale = locale
+ Thread.current[:globalize_locale] = locale
elsif locale.present? and locale != ::Refinery::I18n.default_frontend_locale
- params[:locale] = ::I18n.locale = ::Refinery::I18n.default_frontend_locale
+ params[:locale] = Thread.current[:globalize_locale] = ::Refinery::I18n.default_frontend_locale
redirect_to(params, :notice => "The locale '#{locale}' is not supported.") and return
else
- ::I18n.locale = ::Refinery::I18n.default_frontend_locale
+ Thread.current[:globalize_locale] = ::Refinery::I18n.default_frontend_locale
end
-
- Thread.current[:globalize_locale] = ::I18n.locale
end
end
prepend_before_filter :find_or_set_locale
protected :default_url_options, :find_or_set_locale
@@ -84,12 +84,12 @@
end
class << self
- attr_accessor :built_in_locales, :current_locale, :default_locale,
- :default_frontend_locale, :enabled, :locales
+ attr_accessor :built_in_locales, :current_locale, :current_frontend_locale,
+ :default_locale, :default_frontend_locale, :enabled, :locales
def enabled?
RefinerySetting.find_or_set(:i18n_translation_enabled, true, {
:scoping => 'refinery'
})
@@ -122,9 +122,25 @@
def default_locale
RefinerySetting.find_or_set(:i18n_translation_default_locale, :en, {
:scoping => 'refinery'
}).to_sym
+ end
+
+ def current_frontend_locale
+ if Thread.current[:globalize_locale].present?
+ if Thread.current[:globalize_locale].to_s != ::Refinery::I18n.default_frontend_locale.to_s
+ Thread.current[:globalize_locale]
+ else
+ ::Refinery::I18n.default_frontend_locale
+ end
+ elsif ::I18n.locale.present? && ::I18n.locale.to_s != ::Refinery::I18n.default_frontend_locale.to_s
+ ::I18n.locale
+ elsif ::Refinery::I18n.default_frontend_locale.present?
+ ::Refinery::I18n.default_frontend_locale
+ else
+ ::I18n.locale
+ end
end
def default_frontend_locale
RefinerySetting.find_or_set(:i18n_translation_default_frontend_locale, :en, {
:scoping => 'refinery'