Skip to content

Commit

Permalink
[FEATURE] I18n now uses a formatter if specified by overriding output…
Browse files Browse the repository at this point in the history
…_formatter
  • Loading branch information
lpradovera authored and bklang committed Sep 28, 2016
1 parent 7fe96ec commit 5b4d009
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* [FEATURE] Add rake task to generate Markdown formatted prompt list for recording
* [FEATURE] Expose translator as a library class method (`AdhearsionI18n.t`)
* [BUGFIX] Fix rake task that validates recording files to handle nested i18n keys
* [FEATURE] I18n now uses a formatter if specified by overriding output_formatter

# v1.1.0
* [FEATURE] Add fallback config option to disable text fallback when audio prompts exist.
Expand Down
12 changes: 8 additions & 4 deletions lib/adhearsion-i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
%w{
version
plugin
formatter
call_controller_methods
}.each { |r| require "adhearsion-i18n/#{r}" }

Expand All @@ -23,10 +24,10 @@ def self.t(key, options = {})
prompt = "#{Adhearsion.config.i18n.audio_path}/#{this_locale}/#{prompt}"
end

RubySpeech::SSML.draw language: this_locale do
if prompt.empty?
string text
else
if prompt.empty?
output_formatter.ssml_for_text(text, language: this_locale)
else
RubySpeech::SSML.draw language: this_locale do
if Adhearsion.config.i18n.fallback
audio(src: prompt) { string text }
else
Expand All @@ -40,4 +41,7 @@ def self.locale
I18n.locale || I18n.default_locale
end

def self.output_formatter
AdhearsionI18n::Formatter.new
end
end
5 changes: 5 additions & 0 deletions lib/adhearsion-i18n/formatter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AdhearsionI18n::Formatter < Adhearsion::CallController::Output::Formatter
def ssml_for_text(argument, options = {})
RubySpeech::SSML.draw(options){ argument }
end
end

0 comments on commit 5b4d009

Please sign in to comment.