Class: StallmanBot::Locale
- Inherits:
-
Object
- Object
- StallmanBot::Locale
- Defined in:
- lib/stallman_bot/locale.rb
Class Method Summary collapse
Class Method Details
.load_i18n(locale) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/stallman_bot/locale.rb', line 5 def self.load_i18n(locale) config = File.('../../config/locales', File.dirname(__FILE__)) I18n.load_path = Dir["#{config}/*.yml"] begin I18n.locale = locale rescue I18n::InvalidLocale puts "Locale '#{locale}' couldn't be found. Using default 'en'." I18n.locale = I18n.default_locale end end |
.missing(s) ⇒ Object
28 29 30 |
# File 'lib/stallman_bot/locale.rb', line 28 def self.missing(s) "Missing translation '#{s}' in locale." end |
.replies ⇒ Object
22 23 24 25 26 |
# File 'lib/stallman_bot/locale.rb', line 22 def self.replies I18n.t(:reply, locale: I18n.default_locale).keys.map(&:to_s) rescue NoMethodError I18n.t(:reply, locale: I18n.default_locale, default: missing('reply')) end |
.t(s) ⇒ Object
16 17 18 19 20 |
# File 'lib/stallman_bot/locale.rb', line 16 def self.t(s) I18n.t(s, raise: I18n::MissingTranslationData) rescue I18n::MissingTranslationData I18n.t(s, locale: I18n.default_locale, default: missing(s)) end |