lib/boty/locale.rb in boty-0.0.17.1 vs lib/boty/locale.rb in boty-0.1.0

- old
+ new

@@ -1,11 +1,24 @@ module Boty class Locale - def self.reload + def self.reload(locale = nil) + _locale = new + I18n.load_path = _locale.locales_paths.uniq + I18n.available_locales = I18n::Backend::Simple.new.available_locales + _locale.set_locale locale if locale + end + + def locales_paths default_locales_path = File.expand_path("../../../locale/**/*.yml", __FILE__) - locales = (Dir["locale/**/*.yml"] + Dir[default_locales_path]). + (Dir["locale/**/*.yml"] + Dir[default_locales_path]). map { |file| File.expand_path file } - I18n.load_path = locales.uniq - I18n.available_locales = I18n::Backend::Simple.new.available_locales + end + + def set_locale(locale) + begin + I18n.locale = locale + rescue I18n::InvalidLocale + I18n.locale = :en + end end end end