lib/refinery/i18n.rb in refinerycms-i18n-0.9.8.12 vs lib/refinery/i18n.rb in refinerycms-i18n-0.9.9

- old
+ new

@@ -20,41 +20,53 @@ prepend_before_filter :find_or_set_locale def find_or_set_locale if ::Refinery::I18n.enabled? if ::Refinery::I18n.has_locale?(locale = params[:locale].try(:to_sym)) - ::I18n.locale = locale + Thread.current[:globalize_locale] = ::I18n.locale = locale elsif locale.present? and locale != ::Refinery::I18n.default_frontend_locale - params[:locale] = I18n.locale = ::Refinery::I18n.default_frontend_locale + Thread.current[:globalize_locale] = params[:locale] = I18n.locale = ::Refinery::I18n.default_frontend_locale redirect_to(params, :notice => "The locale '#{locale.to_s}' is not supported.") and return else - ::I18n.locale = ::Refinery::I18n.default_frontend_locale + Thread.current[:globalize_locale] = ::I18n.locale = ::Refinery::I18n.default_frontend_locale end end end protected :default_url_options, :find_or_set_locale end ::Admin::BaseController.class_eval do - prepend_before_filter :find_or_set_locale + # globalize! should be prepended first so that it runs after find_or_set_locale + prepend_before_filter :globalize!, :find_or_set_locale def find_or_set_locale if (params[:set_locale].present? and ::Refinery::I18n.locales.include?(params[:set_locale].to_sym)) ::Refinery::I18n.current_locale = params[:set_locale].to_sym redirect_back_or_default(admin_dashboard_path) and return else ::I18n.locale = ::Refinery::I18n.current_locale end end - protected :find_or_set_locale + def globalize! + Thread.current[:globalize_locale] = (params[:switch_locale] || ::Refinery::I18n.default_frontend_locale) + end + + protected :find_or_set_locale, :globalize! end end config.after_initialize do ::Refinery::I18n.setup! if defined?(RefinerySetting) and RefinerySetting.table_exists? + + Refinery::Plugin.register do |plugin| + plugin.name = "refinery_i18n" + plugin.version = %q{0.9.9} + plugin.hide_from_menu = true + plugin.always_allow_access = true + end end end class << self @@ -110,16 +122,24 @@ })).to_sym end def default_frontend_locale (@default_frontend_locale ||= RefinerySetting.find_or_set(:i18n_translation_default_frontend_locale, - :en, { + :en, { :scoping => 'refinery', :callback_proc_as_string => %q{::Refinery::I18n.setup!} })).to_sym end + def frontend_locales + @frontend_locales ||= RefinerySetting.find_or_set(:i18n_translation_frontend_locales, + [self.default_frontend_locale], { + :scoping => 'refinery', + :callback_proc_as_string => %q{::Refinery::I18n.setup!} + }) + end + def locales @locales ||= RefinerySetting.find_or_set(:i18n_translation_locales, self.built_in_locales, { :scoping => 'refinery', :callback_proc_as_string => %q{::Refinery::I18n.setup!} @@ -136,9 +156,10 @@ @enabled = nil @locales = nil @default_locale = nil @default_frontend_locale = nil @current_locale = nil + @frontend_locales = nil self.load_base_locales! self.load_refinery_locales! self.load_app_locales! self.set_default_locale! \ No newline at end of file