adhearsion-i18n 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/adhearsion-i18n/call_controller_methods.rb +24 -4
- data/lib/adhearsion-i18n/plugin.rb +10 -1
- data/lib/adhearsion-i18n/version.rb +1 -1
- data/spec/call_controller_methods_spec.rb +84 -0
- data/spec/fixtures/locale/en.yml +10 -0
- data/spec/fixtures/locale/it.yml +10 -0
- data/spec/spec_helper.rb +15 -0
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b79e86d823fcae890f17fbaa1aba1944e1b69323
|
4
|
+
data.tar.gz: 0270e6e92f4829b690a8d1a2154605d94c02e711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad98b93929680aed34ed0c4d36ced32f38f9208df8300262f787cf11c9bb3425939a7d0993ef92d410bdfef7917b25984fadabb81199f8626db13f6319ce05ee
|
7
|
+
data.tar.gz: 004ebe0363f04b5c5284f97f4295f543744bf1537bbaca051c5dd47b8ed1f496d6aad353265982adc8dbeb651115f8b694000ed1ae8ba582f8dd62ee4630bf32
|
data/README.md
CHANGED
@@ -17,6 +17,14 @@ See `rake config:show` to see a full list of options.
|
|
17
17
|
|
18
18
|
Make sure to create your locales in `config/locales` within your Adhearsion app.
|
19
19
|
|
20
|
+
adhearsion-i18n uses the [i18n gem](https://github.com/svenfuchs/i18n). For example, if you want to change the default locale, put something like this in config/adhearsion.rb:
|
21
|
+
|
22
|
+
```Ruby
|
23
|
+
I18n.default_locale = :de
|
24
|
+
```
|
25
|
+
|
26
|
+
More docs (though admittedly Rails-specific - read carefully) can be found at http://guides.rubyonrails.org/i18n.html
|
27
|
+
|
20
28
|
## Examples
|
21
29
|
|
22
30
|
en.yml:
|
@@ -57,6 +65,6 @@ end
|
|
57
65
|
|
58
66
|
Copyright (C) 2014 The Adhearsion Foundation
|
59
67
|
|
60
|
-
adhearsion-i18n is released under the [MIT license](http://opensource.org/licenses/MIT). Please see the [LICENSE](https://github.com/
|
68
|
+
adhearsion-i18n is released under the [MIT license](http://opensource.org/licenses/MIT). Please see the [LICENSE](https://github.com/adhearsion/adhearsion-i18n/blob/master/LICENSE) file for details.
|
61
69
|
|
62
70
|
adhearsion-i18n was created by [Ben Klang](https://twitter.com/bklang) with support from [Mojo Lingo](https://mojolingo.com) and their clients.
|
@@ -1,11 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module AdhearsionI18n::CallControllerMethods
|
4
|
-
def t(key)
|
5
|
-
|
6
|
-
|
4
|
+
def t(key, options = {})
|
5
|
+
this_locale = options[:locale] || locale
|
6
|
+
options = {default: '', locale: locale}.merge(options)
|
7
|
+
prompt = ::I18n.t "#{key}.audio", options
|
8
|
+
text = ::I18n.t "#{key}.text", options
|
7
9
|
|
8
|
-
|
10
|
+
unless prompt.empty?
|
11
|
+
prompt = "#{config['audio_path']}/#{this_locale}/#{prompt}"
|
12
|
+
end
|
13
|
+
|
14
|
+
RubySpeech::SSML.draw language: this_locale do
|
9
15
|
if prompt.empty?
|
10
16
|
string text
|
11
17
|
else
|
@@ -13,4 +19,18 @@ module AdhearsionI18n::CallControllerMethods
|
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
22
|
+
|
23
|
+
def locale
|
24
|
+
call[:locale] || I18n.default_locale
|
25
|
+
end
|
26
|
+
|
27
|
+
def locale=(l)
|
28
|
+
call[:locale] = l
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def config
|
34
|
+
Adhearsion.config.i18n
|
35
|
+
end
|
16
36
|
end
|
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
class AdhearsionI18n::Plugin < Adhearsion::Plugin
|
4
4
|
init :i18n do
|
5
|
-
::Adhearsion::CallController.mixin ::
|
5
|
+
::Adhearsion::CallController.mixin ::AdhearsionI18n::CallControllerMethods
|
6
|
+
|
7
|
+
config.locale_path.each do |dir|
|
8
|
+
logger.debug "Adding #{dir} to the I18n load path"
|
9
|
+
I18n.load_path += Dir["#{dir}/**/*.yml"]
|
10
|
+
end
|
11
|
+
|
6
12
|
logger.info "Adhearsion I18n loaded"
|
7
13
|
end
|
8
14
|
|
@@ -10,5 +16,8 @@ class AdhearsionI18n::Plugin < Adhearsion::Plugin
|
|
10
16
|
locale_path ["#{Adhearsion.root}/config/locales"], transform: Proc.new { |v| v.split ':' }, desc: <<-__
|
11
17
|
List of directories from which to load locale data, colon-delimited
|
12
18
|
__
|
19
|
+
audio_path "#{Adhearsion.root}/audio", desc: <<-__
|
20
|
+
Base path from which audio files can be found. May be a filesystem path or some other URL (like HTTP)
|
21
|
+
__
|
13
22
|
end
|
14
23
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe AdhearsionI18n::CallControllerMethods do
|
6
|
+
|
7
|
+
let(:call_id) { SecureRandom.uuid }
|
8
|
+
let(:call) { Adhearsion::Call.new }
|
9
|
+
let(:block) { nil }
|
10
|
+
|
11
|
+
subject(:controller) { Class.new(Adhearsion::CallController).new call }
|
12
|
+
|
13
|
+
before :all do
|
14
|
+
Adhearsion.config.i18n['locale_path'] = ["#{File.dirname(__FILE__)}/fixtures/locale"]
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
I18n.default_locale = :en
|
19
|
+
double call, write_command: true, id: call_id
|
20
|
+
Adhearsion::Plugin.init_plugins
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'getting and setting the locale' do
|
24
|
+
it 'should be able to set and get the locale' do
|
25
|
+
controller.locale.should == :en
|
26
|
+
controller.locale = :it
|
27
|
+
controller.locale.should == :it
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'requesting a translation' do
|
32
|
+
it 'should use a default locale' do
|
33
|
+
ssml = controller.t :have_many_cats
|
34
|
+
ssml['xml:lang'].should =~ /^en/
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should allow overriding the locale per-request' do
|
38
|
+
ssml = controller.t :have_many_cats, locale: 'it'
|
39
|
+
ssml['xml:lang'].should =~ /^it/
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should allow overriding the locale for the entire call' do
|
43
|
+
controller.locale = 'it'
|
44
|
+
ssml = controller.t :have_many_cats
|
45
|
+
ssml['xml:lang'].should =~ /^it/
|
46
|
+
controller2 = Class.new(Adhearsion::CallController).new call
|
47
|
+
controller2.locale.should == 'it'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should generate proper SSML with both audio and text fallback translations' do
|
51
|
+
ssml = controller.t :have_many_cats
|
52
|
+
ssml.should == RubySpeech::SSML.draw(language: 'en') do
|
53
|
+
audio src: "/audio/en/have_many_cats.wav" do
|
54
|
+
string 'I have quite a few cats'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should generate proper SSML with only audio (no fallback text) translations' do
|
60
|
+
ssml = controller.t :my_shirt_is_white
|
61
|
+
ssml.should == RubySpeech::SSML.draw(language: 'en') do
|
62
|
+
audio src: "/audio/en/my_shirt_is_white.wav" do
|
63
|
+
string ''
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should generate proper SSML with only text (no audio) translations' do
|
69
|
+
ssml = controller.t :many_people_out_today
|
70
|
+
ssml.should == RubySpeech::SSML.draw(language: 'en') do
|
71
|
+
string 'There are many people out today'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should generate a path to the audio prompt based on the requested locale' do
|
76
|
+
ssml = controller.t :my_shirt_is_white, locale: 'it'
|
77
|
+
ssml.should == RubySpeech::SSML.draw(language: 'it') do
|
78
|
+
audio src: "/audio/it/la_mia_camicia_e_bianca.wav" do
|
79
|
+
string ''
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'adhearsion'
|
4
|
+
require 'adhearsion-i18n'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.color_enabled = true
|
8
|
+
config.tty = true
|
9
|
+
|
10
|
+
config.mock_with :rspec
|
11
|
+
config.filter_run :focus => true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
|
14
|
+
config.backtrace_clean_patterns = [/rspec/]
|
15
|
+
end
|
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.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -89,6 +89,10 @@ files:
|
|
89
89
|
- lib/adhearsion-i18n/call_controller_methods.rb
|
90
90
|
- lib/adhearsion-i18n/plugin.rb
|
91
91
|
- lib/adhearsion-i18n/version.rb
|
92
|
+
- spec/call_controller_methods_spec.rb
|
93
|
+
- spec/fixtures/locale/en.yml
|
94
|
+
- spec/fixtures/locale/it.yml
|
95
|
+
- spec/spec_helper.rb
|
92
96
|
homepage: http://adhearsion.com
|
93
97
|
licenses:
|
94
98
|
- MIT
|
@@ -113,5 +117,9 @@ rubygems_version: 2.2.1
|
|
113
117
|
signing_key:
|
114
118
|
specification_version: 4
|
115
119
|
summary: Internationalization helpers for Adhearsion applications
|
116
|
-
test_files:
|
120
|
+
test_files:
|
121
|
+
- spec/call_controller_methods_spec.rb
|
122
|
+
- spec/fixtures/locale/en.yml
|
123
|
+
- spec/fixtures/locale/it.yml
|
124
|
+
- spec/spec_helper.rb
|
117
125
|
has_rdoc:
|