Skip to content

Commit

Permalink
Properly make the default locale settable by refinery setting and cle…
Browse files Browse the repository at this point in the history
…an up method signatures.
  • Loading branch information
parndt committed Jun 30, 2010
1 parent 17392f8 commit 3f491c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
9 changes: 0 additions & 9 deletions config/application.rb
Expand Up @@ -24,15 +24,6 @@
# Note: These are settings that aren't dependent on environment type. For those, use the files in config/environments/
require Rails.root.join('config', 'settings.rb').to_s

# Mislav trick to fallback to default for missing translations
I18n.exception_handler = lambda do |e, locale, key, options|
if I18n::MissingTranslationData === e and locale != I18n.default_locale
I18n.translate(key, (options || {}).update(:locale => I18n.default_locale, :raise => true))
else
raise e
end
end if Rails.env == 'production'

# Bundler has shown a weakness using Rails < 3 so we are going to
# require these dependencies here until we can find another solution or until we move to
# Rails 3.0 which should fix the issue (or until Bundler fixes the issue).
Expand Down
23 changes: 17 additions & 6 deletions vendor/plugins/i18n/lib/i18n.rb
@@ -1,7 +1,7 @@
class Refinery::I18n
class << self

attr_accessor :enabled, :current_locale, :locales
attr_accessor :enabled, :current_locale, :locales, :default_locale

def enabled?
# cache this lookup as it gets very expensive.
Expand All @@ -19,8 +19,8 @@ def current_locale
@current_locale = :en
RefinerySetting[:refinery_i18n_current_locale] = :en
else
@current_locale ||= RefinerySetting.find_or_set(:refinery_i18n_current_locale,
RefinerySetting.find_or_set(:refinery_i18n_default_locale, :en))
@current_locale ||= RefinerySetting.find_or_set(:refinery_i18n_current_locale, I18n.default_locale)

end
end

Expand All @@ -45,7 +45,7 @@ def locales
})
end

def has_locale? locale
def has_locale?(locale)
locales.has_key? locale.try(:to_sym)
end

Expand All @@ -58,6 +58,15 @@ def setup!
self.load_refinery_locales!
self.load_app_locales!
self.set_default_locale!

# Mislav trick to fallback to default for missing translations
I18n.exception_handler = lambda do |e, locale, key, options|
if I18n::MissingTranslationData === e and locale != I18n.default_locale
I18n.translate(key, (options || {}).update(:locale => I18n.default_locale, :raise => true))
else
raise e
end
end if Rails.env == 'production'
end

def load_base_locales!
Expand All @@ -73,10 +82,12 @@ def load_app_locales!
end

def set_default_locale!
I18n.default_locale = current_locale
I18n.default_locale = @default_locale ||= RefinerySetting.find_or_set(:refinery_i18n_default_locale, :en, {
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
})
end

def load_locales locale_files
def load_locales(locale_files)
locale_files = locale_files.to_s if locale_files.is_a? Pathname
locale_files = Dir[locale_files] if locale_files.is_a? String
locale_files.each do |locale_file|
Expand Down

0 comments on commit 3f491c8

Please sign in to comment.