From 5b4d0095f1fcd971ca48a2741abad0523920b7c6 Mon Sep 17 00:00:00 2001 From: Luca Pradovera Date: Tue, 23 Jun 2015 22:55:37 +0200 Subject: [PATCH] [FEATURE] I18n now uses a formatter if specified by overriding output_formatter --- CHANGELOG.md | 1 + lib/adhearsion-i18n.rb | 12 ++++++++---- lib/adhearsion-i18n/formatter.rb | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 lib/adhearsion-i18n/formatter.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index f8980f8..b36757b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/adhearsion-i18n.rb b/lib/adhearsion-i18n.rb index 0e430ce..e932f63 100644 --- a/lib/adhearsion-i18n.rb +++ b/lib/adhearsion-i18n.rb @@ -3,6 +3,7 @@ %w{ version plugin + formatter call_controller_methods }.each { |r| require "adhearsion-i18n/#{r}" } @@ -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 @@ -40,4 +41,7 @@ def self.locale I18n.locale || I18n.default_locale end + def self.output_formatter + AdhearsionI18n::Formatter.new + end end diff --git a/lib/adhearsion-i18n/formatter.rb b/lib/adhearsion-i18n/formatter.rb new file mode 100644 index 0000000..e7cb902 --- /dev/null +++ b/lib/adhearsion-i18n/formatter.rb @@ -0,0 +1,5 @@ +class AdhearsionI18n::Formatter < Adhearsion::CallController::Output::Formatter + def ssml_for_text(argument, options = {}) + RubySpeech::SSML.draw(options){ argument } + end +end