easy_translate 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/easy_translate/detection'
2
2
  require File.dirname(__FILE__) + '/easy_translate/translation'
3
+ require File.dirname(__FILE__) + '/easy_translate/translation_target'
3
4
 
4
5
  module EasyTranslate
5
6
 
@@ -11,6 +12,7 @@ module EasyTranslate
11
12
 
12
13
  extend Detection # Language Detection
13
14
  extend Translation # Language Translation
15
+ extend TranslationTarget # Language Translation Targets
14
16
 
15
17
  class << self
16
18
  attr_accessor :api_key
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require File.dirname(__FILE__) + '/request'
3
+
4
+ module EasyTranslate
5
+
6
+ module TranslationTarget
7
+
8
+ # Determine what translations are available
9
+ # @param [String] source - The source language (optional)
10
+ # @param [Hash] options - extra options
11
+ # @return [Array] an array of strings representing languages
12
+ def translations_available(target = nil, options = {})
13
+ request = TranslationTargetRequest.new(target, options)
14
+ raw = request.perform_raw
15
+ JSON.parse(raw)['data']['languages'].map do |res|
16
+ res['language']
17
+ end
18
+ end
19
+
20
+ class TranslationTargetRequest < EasyTranslate::Request
21
+
22
+ def initialize(target = nil, options = nil)
23
+ @target = target
24
+ if options
25
+ @options = options
26
+ if replacement_api_key = @options.delete(:api_key)
27
+ @options[:key] = replacement_api_key
28
+ end
29
+ end
30
+ end
31
+
32
+ def params
33
+ params = super || {}
34
+ params[:target] = @target unless @target.nil?
35
+ params.merge! @options if @options
36
+ params
37
+ end
38
+
39
+ def path
40
+ '/language/translate/v2/languages'
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -1,5 +1,5 @@
1
1
  module EasyTranslate
2
2
 
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000Z
12
+ date: 2012-01-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70158452480400 !ruby/object:Gem::Requirement
16
+ requirement: &18311100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70158452480400
24
+ version_requirements: *18311100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70158452479660 !ruby/object:Gem::Requirement
27
+ requirement: &18310680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70158452479660
35
+ version_requirements: *18310680
36
36
  description: easy_translate is a wrapper for the google translate API that makes sense
37
37
  programatically, and implements API keys
38
38
  email: john.crepezzi@gmail.com
@@ -40,12 +40,13 @@ executables: []
40
40
  extensions: []
41
41
  extra_rdoc_files: []
42
42
  files:
43
- - lib/easy_translate/detection.rb
44
- - lib/easy_translate/easy_translate_exception.rb
45
43
  - lib/easy_translate/languages.rb
46
44
  - lib/easy_translate/request.rb
47
- - lib/easy_translate/translation.rb
45
+ - lib/easy_translate/translation_target.rb
48
46
  - lib/easy_translate/version.rb
47
+ - lib/easy_translate/easy_translate_exception.rb
48
+ - lib/easy_translate/translation.rb
49
+ - lib/easy_translate/detection.rb
49
50
  - lib/easy_translate.rb
50
51
  - spec/spec_helper.rb
51
52
  homepage: https://github.com/seejohnrun/easy_translate
@@ -68,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  version: '0'
69
70
  requirements: []
70
71
  rubyforge_project:
71
- rubygems_version: 1.8.10
72
+ rubygems_version: 1.8.15
72
73
  signing_key:
73
74
  specification_version: 3
74
75
  summary: Google Translate API Wrapper for Ruby