Module: Adhearsion::I18n

Defined in:
lib/adhearsion/i18n.rb

Class Method Summary collapse

Class Method Details

.localeObject



34
35
36
# File 'lib/adhearsion/i18n.rb', line 34

def self.locale
  ::I18n.locale
end

.t(key, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/adhearsion/i18n.rb', line 6

def self.t(key, options = {})
  this_locale = options[:locale] || locale
  options = {default: '', locale: locale}.merge(options)
  prompt = ::I18n.t "#{key}.audio", options
  text   = ::I18n.t "#{key}.text", options

  if prompt.empty? && text.empty?
    # Look for a translation key that doesn't follow the Adhearsion-I18n structure
    text = ::I18n.t key, options
  end

  unless prompt.empty?
    prompt = "file://#{Adhearsion.root + "/" unless Adhearsion.config.core.i18n.audio_path.start_with?("/")}#{Adhearsion.config.core.i18n.audio_path}/#{this_locale}/#{prompt}"
  end

  RubySpeech::SSML.draw language: this_locale do
    if prompt.empty?
      string text
    else
      if Adhearsion.config.core.i18n.fallback
        audio(src: prompt) { string text }
      else
        audio(src: prompt)
      end
    end
  end
end