Sha256: 11d0240a2e314483f9dd846887f67eed730d1bc3d92baed1841a5a3057780f87

Contents?: true

Size: 891 Bytes

Versions: 2

Compression:

Stored size: 891 Bytes

Contents

# encoding: utf-8

module AdhearsionI18n::CallControllerMethods
  def 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 = "#{config['audio_path']}/#{this_locale}/#{prompt}"
    end

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

  def locale
    call[:locale] || I18n.default_locale
  end

  def locale=(l)
    call[:locale] = l
  end

private

  def config
    Adhearsion.config.i18n
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
adhearsion-i18n-0.0.4 lib/adhearsion-i18n/call_controller_methods.rb
adhearsion-i18n-0.0.3 lib/adhearsion-i18n/call_controller_methods.rb