Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] I18n now uses a formatter if specified by overriding output… #10

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is worth submitting as a PR to Adhearsion

def ssml_for_text(argument, options = {})
RubySpeech::SSML.draw(options){ argument }
end
end