adhearsion-i18n 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b79e86d823fcae890f17fbaa1aba1944e1b69323
4
- data.tar.gz: 0270e6e92f4829b690a8d1a2154605d94c02e711
3
+ metadata.gz: eb8f300e9d8e250e39920a4c1346f9723771b630
4
+ data.tar.gz: 4b946892c2dcb82f20b23b7a43116f74dd45dbab
5
5
  SHA512:
6
- metadata.gz: ad98b93929680aed34ed0c4d36ced32f38f9208df8300262f787cf11c9bb3425939a7d0993ef92d410bdfef7917b25984fadabb81199f8626db13f6319ce05ee
7
- data.tar.gz: 004ebe0363f04b5c5284f97f4295f543744bf1537bbaca051c5dd47b8ed1f496d6aad353265982adc8dbeb651115f8b694000ed1ae8ba582f8dd62ee4630bf32
6
+ metadata.gz: 9822ef3b0f07a72b17703e01077f7abc5772e3993cee90677ab9a001adafe61044796b9dfaad3ec920089f976aef1a80b932e45fe074cf9c19d198b4201df405
7
+ data.tar.gz: cc84d54b7071ae75b091f2c2a784a7135e6771e1eef275fa804a49dfe11df2912f610f958ba0316f224ee9bc00c5116946d291fe6cc1cb0eda7bcba6e3db721b
@@ -0,0 +1,12 @@
1
+ # v0.0.3
2
+ * [FEATURE] Add rake task to validate that all defined audio prompts are found within Adhearsion application
3
+ * [FEATURE] Allow translation lookups to fallback if an adhearsion-i18n structure isn't found
4
+
5
+ # v0.0.2
6
+ * [FEATURE] Infer audio path from language
7
+ * [FEATURE] Allow setting per-call default language
8
+ * [FEATURE] Ignore missing string translations
9
+ * [FEATURE] Make audio path configurable
10
+
11
+ # v0.0.1
12
+ * First release: Adhearsion plugin for Internationalization based on Ruby I18n
data/README.md CHANGED
@@ -33,13 +33,13 @@ en.yml:
33
33
  en:
34
34
  string1:
35
35
  audio: /path/to/string1.wav
36
- text: String One
36
+ text: 'String One'
37
37
 
38
38
  string2:
39
- audio: /path/to/string2.wav
39
+ audio: '/path/to/string2.wav'
40
40
 
41
41
  string3:
42
- text: String Three
42
+ text: 'String Three'
43
43
  ```
44
44
 
45
45
  example_controller.rb:
@@ -61,6 +61,60 @@ class ExampleController < Adhearsion::CallController
61
61
  end
62
62
  ```
63
63
 
64
+ ## String interpolations
65
+
66
+ adhearsion-i18n supports string interpolations just as i18n itself does. However there are some guidelines we recommend:
67
+
68
+ * When you want to craft TTS strings that contain variable data, use SSML instead
69
+ * Use interpolations only for audio files, not for TTS text strings
70
+
71
+ The reason for this is that it is not practical to assume that you can interpolate text into a recorded audio file. Thus while your app may start with TTS-only today, following this practice will ensure that you can more easily convert to recorded audio in the future.
72
+
73
+ Example:
74
+
75
+ Bad:
76
+
77
+ ```Ruby
78
+ play t(:hello, name: 'Ben')
79
+ ```
80
+
81
+ Good:
82
+
83
+ ```Ruby
84
+ play t(:hello), 'Ben'
85
+ ```
86
+
87
+ Further discussion on this issue can be found in [issue #3](https://github.com/adhearsion/adhearsion-i18n/issues/3).
88
+
89
+ ## Verifying audio prompts
90
+
91
+ adhearsion-i18n adds a rake task to Adhearsion applications that will check to ensure each defined audio file is present in the application. This assumes that the audio files are kept in the Adhearsion application itself and not hosted externally.
92
+
93
+ Given a YAML locale file like:
94
+
95
+ ```yaml
96
+ en:
97
+ hello:
98
+ audio: hello.wav
99
+ missing_prompt:
100
+ audio: missing_prompt.wav
101
+ ```
102
+
103
+ Assuming the default location of `#{Adhearsion.root}/audio`, this example assumes that `hello.wav` is present, but `missing_prompt.wav` is missing.
104
+
105
+ Then run the rake task to validate the prompts and see output like this:
106
+
107
+ ```Bash
108
+ $ rake i18n:validate_files
109
+ [2014-05-07 16:03:00.792] DEBUG AdhearsionI18n::Plugin: Adding /Users/bklang/myapp/config/locales to the I18n load path
110
+ [2014-05-07 16:03:00.792] INFO AdhearsionI18n::Plugin: Adhearsion I18n loaded
111
+
112
+ Adhearsion configured environment: development
113
+ [2014-05-07 16:03:00.833] INFO Object: [en] Missing audio file: /Users/bklang/myapp/audio/en/missing_prompt.wav
114
+ [2014-05-07 16:03:00.833] ERROR Object: Errors detected! Number of errors by locale:
115
+ [2014-05-07 16:03:00.833] ERROR Object: [en]: 1 missing prompts
116
+ ```
117
+
64
118
  ## Credits
65
119
 
66
120
  Copyright (C) 2014 The Adhearsion Foundation
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new :spec
6
+
7
+ task default: :spec
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.add_runtime_dependency 'activesupport', [">= 3.0.0", "< 5.0.0"]
25
- s.add_runtime_dependency 'adhearsion', ["~> 2.0"]
25
+ s.add_runtime_dependency 'adhearsion', ["~> 2.5"]
26
26
  s.add_runtime_dependency 'i18n', ["~> 0.6"]
27
27
 
28
28
  s.add_development_dependency 'rspec', ["~> 2.11"]
@@ -7,6 +7,11 @@ module AdhearsionI18n::CallControllerMethods
7
7
  prompt = ::I18n.t "#{key}.audio", options
8
8
  text = ::I18n.t "#{key}.text", options
9
9
 
10
+ if prompt.empty? && text.empty?
11
+ # Look for a translation key that doesn't follow the Adhearsion-I18n structure
12
+ text = ::I18n.t key, options
13
+ end
14
+
10
15
  unless prompt.empty?
11
16
  prompt = "#{config['audio_path']}/#{this_locale}/#{prompt}"
12
17
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'yaml'
2
3
 
3
4
  class AdhearsionI18n::Plugin < Adhearsion::Plugin
4
5
  init :i18n do
@@ -20,4 +21,45 @@ class AdhearsionI18n::Plugin < Adhearsion::Plugin
20
21
  Base path from which audio files can be found. May be a filesystem path or some other URL (like HTTP)
21
22
  __
22
23
  end
24
+
25
+ tasks do
26
+ namespace :i18n do
27
+ desc "Validate configured audio prompt files exist"
28
+ task :validate_files do
29
+ config = Adhearsion.config.i18n
30
+ locale_files = Dir.glob(I18n.load_path)
31
+
32
+ locale_errors = {}
33
+ locale_files.each do |locale_file|
34
+ # We only support YAML for now
35
+ next unless locale_file =~ /\.ya?ml$/
36
+ prompts = YAML.load File.read(locale_file)
37
+
38
+ locale = prompts.keys.first
39
+ prompts = prompts[locale]
40
+
41
+ prompts.each_pair do |key, mapping|
42
+ # Not all prompts will have audio files
43
+ next unless mapping['audio']
44
+
45
+ file = File.absolute_path "#{config['audio_path']}/#{locale}/#{mapping['audio']}"
46
+ unless File.exist?(file)
47
+ logger.info "[#{locale}] Missing audio file: #{file}"
48
+ locale_errors[locale] ||= 0
49
+ locale_errors[locale] += 1
50
+ end
51
+ end
52
+ end
53
+
54
+ if locale_errors.keys.count > 0
55
+ logger.error "Errors detected! Number of errors by locale:"
56
+ locale_errors.each_pair do |locale, err_count|
57
+ logger.error "[#{locale}]: #{err_count} missing prompts"
58
+ end
59
+ else
60
+ logger.info "All configured prompt files successfully validated."
61
+ end
62
+ end
63
+ end
64
+ end
23
65
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class AdhearsionI18n
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -80,5 +80,12 @@ describe AdhearsionI18n::CallControllerMethods do
80
80
  end
81
81
  end
82
82
  end
83
+
84
+ it 'should fall back to a text translation if the locale structure does not break out audio vs. tts' do
85
+ ssml = controller.t :seventeen, locale: 'it'
86
+ ssml.should == RubySpeech::SSML.draw(language: 'it') do
87
+ string 'diciassette'
88
+ end
89
+ end
83
90
  end
84
91
  end
@@ -8,3 +8,6 @@ en:
8
8
 
9
9
  many_people_out_today:
10
10
  text: There are many people out today
11
+
12
+ # Simulating an external, non adhearsion-i18n translation:
13
+ seventeen: seventeen
@@ -8,3 +8,6 @@ it:
8
8
 
9
9
  many_people_out_today:
10
10
  text: Ci sono molti persone fuori oggi
11
+
12
+ # Simulating an external, non adhearsion-i18n translation:
13
+ seventeen: diciassette
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhearsion-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Klang
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-24 00:00:00.000000000 Z
12
+ date: 2014-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.0'
40
+ version: '2.5'
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '2.5'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: i18n
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -81,9 +81,11 @@ extensions: []
81
81
  extra_rdoc_files: []
82
82
  files:
83
83
  - ".gitignore"
84
+ - CHANGELOG.md
84
85
  - Gemfile
85
86
  - LICENSE
86
87
  - README.md
88
+ - Rakefile
87
89
  - adhearsion-i18n.gemspec
88
90
  - lib/adhearsion-i18n.rb
89
91
  - lib/adhearsion-i18n/call_controller_methods.rb
@@ -113,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.2.1
118
+ rubygems_version: 2.2.2
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Internationalization helpers for Adhearsion applications