yaml-translator 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/yaml-translator/adapters/base_adapter.rb +19 -0
- data/lib/yaml-translator/adapters/google_translate_adapter.rb +0 -3
- data/lib/yaml-translator/translator.rb +4 -1
- data/lib/yaml-translator/version.rb +1 -1
- data/spec/yaml_translator_spec.rb +13 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd1e5419f516c0e5808b709d17ebaf9571b952e2
|
4
|
+
data.tar.gz: b049be4c6a92d7ef6892f79f760e249550170b54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e2719bbd14f5ed9266aac27ea12b129447750c6bbcdbf4d35237bba1bc0111cf3a759b6d3d60ba4a72f61a9e927461075b16ae1cbbda4a01a5a024f53f1ebb7
|
7
|
+
data.tar.gz: aab388c974f11d9962ebc53e2545839ff580371a7e4ebd9289624e97f3ff4851e70423d4b246c86dc0fd69090ddd5afd57ba1372028c5b73e6c80f6eed7550f9
|
data/Gemfile.lock
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module YamlTranslator
|
2
2
|
module Adapters
|
3
3
|
class BaseAdapter
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@name = adapter_name
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
4
11
|
def translate(values, options={})
|
5
12
|
raise 'Translation processing is not implemented'
|
6
13
|
end
|
@@ -8,6 +15,18 @@ module YamlTranslator
|
|
8
15
|
def default_options
|
9
16
|
{ to: :en }
|
10
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def adapter_name
|
22
|
+
ptn = /[A-Z\s]*[^A-Z]*/
|
23
|
+
class_name = self.class.name.split('::').last
|
24
|
+
snake_case_s = class_name.gsub(/Adapter/, '').scan(ptn)
|
25
|
+
.map { |v| v.empty? ? nil : v.downcase }
|
26
|
+
.compact
|
27
|
+
.join('_')
|
28
|
+
snake_case_s.to_sym
|
29
|
+
end
|
11
30
|
end
|
12
31
|
end
|
13
32
|
end
|
@@ -2,11 +2,14 @@ require "yaml-translator/adapters"
|
|
2
2
|
|
3
3
|
module YamlTranslator
|
4
4
|
class Translator
|
5
|
-
|
6
5
|
def initialize(adapter = Adapters::NoopAdapter.new)
|
7
6
|
@adapter = adapter
|
8
7
|
end
|
9
8
|
|
9
|
+
def adapter_name
|
10
|
+
@adapter.name
|
11
|
+
end
|
12
|
+
|
10
13
|
# Translate target
|
11
14
|
#
|
12
15
|
# @param [Locale] locale of translate target
|
@@ -2,9 +2,19 @@ require 'rspec/temp_dir'
|
|
2
2
|
|
3
3
|
describe YamlTranslator do
|
4
4
|
describe '#create' do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
context 'when google translate adapter' do
|
6
|
+
it 'should be load translator' do
|
7
|
+
translator = YamlTranslator.create(:google_translate, api_key: 'xyz')
|
8
|
+
expect(translator).to be_kind_of(YamlTranslator::Translator)
|
9
|
+
expect(translator.adapter_name).to eq(:google_translate)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
context 'when noop adapter' do
|
13
|
+
it 'should be load translator' do
|
14
|
+
translator = YamlTranslator.create(:noop)
|
15
|
+
expect(translator).to be_kind_of(YamlTranslator::Translator)
|
16
|
+
expect(translator.adapter_name).to eq(:noop)
|
17
|
+
end
|
8
18
|
end
|
9
19
|
end
|
10
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noritaka Horio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: easy_translate
|