to_lang 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9bf52a1b7871b0277a755c4d0e85ff30cb30d18
4
+ data.tar.gz: 238cccb4c0cafeefe0c7c3b187880aa13e93a928
5
+ SHA512:
6
+ metadata.gz: 3edd8b9f2ba89e5475675abb194448316376fb8c3c099a4a4ba08eb1afd07c518eb6016c123a5212ddf3dbab0594046102f48ab326f965d8c03ff32e6d2ab19a
7
+ data.tar.gz: 3b8bafb0ff80ab4cd75dd5d4a7dbf87cb79ef35bea66a14548925f79bac7988a952d5bea037a7609f81dac51bfa37aec7d53d357a7522d9d850befe9af183901
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --color
2
- --format nested
@@ -1,5 +1,4 @@
1
1
  ---
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
-
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in to_lang.gemspec
4
4
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2010-2011 by Jimmy Cuadra
1
+ Copyright (C) 2010-2011, 2015 by Jimmy Cuadra
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,190 @@
1
+ [![Gem Version](https://badge.fury.io/rb/to_lang.png)](http://badge.fury.io/rb/to_lang)
2
+ [![Build Status](https://travis-ci.org/jimmycuadra/to_lang.png?branch=master)](https://travis-ci.org/jimmycuadra/to_lang)
3
+ [![Code Climate](https://codeclimate.com/github/jimmycuadra/to_lang.png)](https://codeclimate.com/github/jimmycuadra/to_lang)
4
+
5
+ # to_lang
6
+
7
+ **to_lang** is a Ruby library that adds language translation methods to strings and arrays, backed by the Google Translate API.
8
+
9
+ ## Installation
10
+
11
+ Simply run:
12
+
13
+ ``` bash
14
+ gem install to_lang
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ To use **to_lang**, require the library, then call `ToLang.start` with your Google Translate API key. At this point you will have access to all the new translation methods, which take the form `to_language`, where "language" is the language you wish to translate to.
20
+
21
+ Google Translate attempts to detect the source language, but you can specify it explicitly by calling methods in the form `to_target_language_from_source_language`, where "target language" is the language you are translating to and "source_language" is the language you are starting with. An inverted form with equivalent functionality, `from_source_language_to_target_language` is also available. These methods are generated dynamically and will not appear in a calls to `String.instance_methods` or `Array.instance_methods` until they have been called once. Strings and arrays will, however, `respond_to?` these methods prior to their dynamic definition.
22
+
23
+ The dynamic methods are simply syntactic sugar for `String#translate` and `Array#translate`, which you can use directly as well.
24
+
25
+ **to_lang** also comes with a command line utility for quick translations from the shell.
26
+
27
+ ## String Examples
28
+
29
+ Load and initialize **to_lang**:
30
+
31
+ ``` ruby
32
+ require 'to_lang'
33
+
34
+ ToLang.start('YOUR_GOOGLE_TRANSLATE_API_KEY')
35
+ ```
36
+
37
+ Translate some text to Spanish:
38
+
39
+ ``` ruby
40
+ "Very cool gem!".to_spanish # => "Muy fresco joya!"
41
+ ```
42
+
43
+ A case where the source language is ambiguous:
44
+
45
+ ``` ruby
46
+ "a pie".to_spanish # => "a pie"
47
+ "a pie".to_spanish_from_english # => "un pastel"
48
+ ```
49
+
50
+ Or equivalently:
51
+
52
+ ``` ruby
53
+ "a pie".from_english_to_spanish # => "un pastel"
54
+ ```
55
+
56
+ Using `String#translate` directly:
57
+
58
+ ``` ruby
59
+ "hello world".translate('es') # => "hola mundo"
60
+ "a pie".translate('es', :from => 'en') # => "un pastel"
61
+ ```
62
+
63
+ ## Array Examples
64
+
65
+ Arrays can be used to translate a batch of strings in a single method call and a single HTTP request. The exact same methods shown above work for arrays as well. For example, to translate an array of strings to Spanish:
66
+
67
+ ``` ruby
68
+ ["One", "Two", "Three"].to_spanish # => ["Uno", "Dos", "Tres"]
69
+ ```
70
+
71
+ ## Debugging
72
+
73
+ `translate` also has the advantage of allowing you to get debug output for a translation. `translate` accepts a `:debug` option with three possible values: `:request`, `:response`, and `:all`. `:request` will cause the method to return a hash of the parameters that will be sent to the Google Translate API. `:response` will cause the method to return the full response from the API call as a hash. `:all` will cause the method to return a hash which contains both the request hash and the full response.
74
+
75
+ ``` ruby
76
+ "hello world".translate('es', :debug => :request)
77
+ # => {:key=>"my_key", :q=>"hello world", :target=>"es"}
78
+ ```
79
+
80
+ ``` ruby
81
+ "hello world".translate('es', :debug => :response)
82
+ # => {"data"=>{"translations"=>[{"translatedText"=>"hola mundo", "detectedSourceLanguage"=>"en"}]}}
83
+ ```
84
+
85
+ ``` ruby
86
+ "hello world".translate('es', :debug => :all)
87
+ # => {:request=>{:key=>"my_key", :q=>"hello world", :target=>"es"},
88
+ # :response=>{"data"=>{"translations"=>[{"translatedText"=>"hola mundo",
89
+ # "detectedSourceLanguage"=>"en"}]}}}
90
+ ```
91
+
92
+ ## Command Line Interface
93
+
94
+ The command line utility `to_lang` has the following interface:
95
+
96
+ ```
97
+ to_lang [--key API_KEY] [--from SOURCE_LANGUAGE] --to DESTINATION_LANGUAGE STRING [STRING, ...]
98
+ ```
99
+
100
+ `to_lang` accepts a space separated list of strings to translate. At least one string is required, as is the `--to` option, which accepts a language code (e.g. "es"). `to_lang` will attempt to load a Google Translate API key from the `GOOGLE_TRANSLATE_API_KEY` environment variable. If one is not available, it must be passed in from the command line with the `--key` option. For complete usage instructions, invoke the utility with the `--help` option.
101
+
102
+ Examples:
103
+
104
+ A simple translation with the key being passed in directly from the command line:
105
+
106
+ ``` bash
107
+ to_lang --key YOUR_GOOGLE_TRANSLATE_API_KEY --to es "hello world"
108
+ hola mundo
109
+ ```
110
+
111
+ With the key in an environment variable and multiple strings:
112
+
113
+ ``` bash
114
+ to_lang --to es "hello world" "a pie"
115
+ hola mundo
116
+ a pie
117
+ ```
118
+
119
+ Specifying the source language:
120
+
121
+ ``` bash
122
+ to_lang --from en --to es "hello world" "a pie"
123
+ hola mundo
124
+ un pastel
125
+ ```
126
+
127
+ ## Supported Languages
128
+
129
+ **to_lang** adds the following methods to strings and arrays. Each of these methods can be called with an explicit source language by appending `_from_source_language` or prepending `from_source_language_` to the method name.
130
+
131
+ * to_afrikaans
132
+ * to_albanian
133
+ * to_arabic
134
+ * to_belarusian
135
+ * to_bulgarian
136
+ * to_catalan
137
+ * to_simplified_chinese
138
+ * to_traditional_chinese
139
+ * to_croatian
140
+ * to_czech
141
+ * to_danish
142
+ * to_dutch
143
+ * to_english
144
+ * to_estonian
145
+ * to_filipino
146
+ * to_finnish
147
+ * to_french
148
+ * to_galician
149
+ * to_german
150
+ * to_greek
151
+ * to_haitian_creole
152
+ * to_hebrew
153
+ * to_hindi
154
+ * to_hungarian
155
+ * to_icelandic
156
+ * to_indonesian
157
+ * to_irish
158
+ * to_italian
159
+ * to_japanese
160
+ * to_latvian
161
+ * to_lithuanian
162
+ * to_macedonian
163
+ * to_malay
164
+ * to_maltese
165
+ * to_norwegian
166
+ * to_persian
167
+ * to_polish
168
+ * to_portuguese
169
+ * to_romanian
170
+ * to_russian
171
+ * to_serbian
172
+ * to_slovak
173
+ * to_slovenian
174
+ * to_spanish
175
+ * to_swahili
176
+ * to_swedish
177
+ * to_thai
178
+ * to_turkish
179
+ * to_ukrainian
180
+ * to_vietnamese
181
+ * to_welsh
182
+ * to_yiddish
183
+
184
+ ## Documentation
185
+
186
+ API documentation can be found at [rubydoc.info](http://rubydoc.info/github/jimmycuadra/to_lang/master/frames).
187
+
188
+ ## Feedback and Contributions
189
+
190
+ Feedback is greatly appreciated. If you have any problems with **to_lang**, please open a new issue. Make sure you are using the latest version of the gem, or HEAD if you've cloned the Git repository directly. Please include debugging output from using the `:debug` option of `translate`, if relevant to your issue. If you'd like to fix bugs, add features, or improve the library in general, feel free to fork the project and send me a pull request with your changes.
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
3
-
1
+ require 'bundler/gem_tasks'
4
2
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec)
3
+
4
+ RSpec::Core::RakeTask.new
6
5
 
7
6
  task :default => :spec
@@ -1,5 +1,5 @@
1
1
  module ToLang
2
2
  # The current version of the Ruby gem.
3
3
  #
4
- VERSION = "0.3.1"
4
+ VERSION = '1.0.0'
5
5
  end
@@ -1,9 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe ToLang::Connector do
4
- before :all do
5
- @connector = ToLang::Connector.new('apikey')
6
- end
4
+ let(:connector) { ToLang::Connector.new('apikey') }
7
5
 
8
6
  describe "custom query string normalizer" do
9
7
  it "returns a query string with unsorted parameters" do
@@ -13,19 +11,21 @@ describe ToLang::Connector do
13
11
  :target => 'es',
14
12
  :q => ["banana", "apple"]
15
13
  }
16
- ToLang::Connector::UNSORTED_QUERY_STRING_NORMALIZER.call(params).should =~ /q=banana&q=apple/
14
+ expect(
15
+ ToLang::Connector::UNSORTED_QUERY_STRING_NORMALIZER.call(params)
16
+ ).to match(/q=banana&q=apple/)
17
17
  end
18
18
  end
19
19
 
20
20
  it "stores a key when initialized" do
21
- @connector.key.should_not be_nil
21
+ expect(connector.key).not_to be_nil
22
22
  end
23
23
 
24
24
  describe "#request" do
25
25
  # helper methods
26
26
  def stub_response(parsed_response)
27
- mock_response = mock('HTTParty::Response', :parsed_response => parsed_response)
28
- ToLang::Connector.stub(:post).and_return(mock_response)
27
+ mock_response = double('HTTParty::Response', :parsed_response => parsed_response)
28
+ allow(ToLang::Connector).to receive(:post).and_return(mock_response)
29
29
  end
30
30
 
31
31
  def stub_good_response(translated_text)
@@ -51,7 +51,7 @@ describe ToLang::Connector do
51
51
  context "with only a target language" do
52
52
  it "returns the translated string" do
53
53
  stub_good_response "hola mundo"
54
- @connector.request("hello world", "es").should == "hola mundo"
54
+ expect(connector.request("hello world", "es")).to eq("hola mundo")
55
55
  end
56
56
  end
57
57
 
@@ -59,14 +59,14 @@ describe ToLang::Connector do
59
59
  context "and no source language specified" do
60
60
  it "returns the same string" do
61
61
  stub_good_response "a pie"
62
- @connector.request("a pie", "es").should == "a pie"
62
+ expect(connector.request("a pie", "es")).to eq("a pie")
63
63
  end
64
64
  end
65
65
 
66
66
  context "and a source language specified" do
67
67
  it "returns the translated string" do
68
68
  stub_good_response "un pastel"
69
- @connector.request("a pie", "es", :from => "en").should == "un pastel"
69
+ expect(connector.request("a pie", "es", :from => "en")).to eq("un pastel")
70
70
  end
71
71
  end
72
72
  end
@@ -74,28 +74,35 @@ describe ToLang::Connector do
74
74
  context "with a bad language pair" do
75
75
  it "raises an exception" do
76
76
  stub_bad_response "Bad language pair: en|en"
77
- expect { @connector.request("a pie", "en", :from => "en") }.to raise_error(RuntimeError, "Bad language pair: en|en")
77
+ expect { connector.request("a pie", "en", :from => "en") }.to raise_error(RuntimeError, "Bad language pair: en|en")
78
78
  end
79
79
  end
80
80
 
81
81
  context "when debugging the request" do
82
82
  it "returns the request URL" do
83
- @connector.request("hello world", "es", :from => "en", :debug => :request).should == { :key=> "apikey", :q => "hello world", :target => "es", :source => "en" }
83
+ expect(connector.request("hello world", "es", :from => "en", :debug => :request)).to eq({
84
+ :key=> "apikey", :q => "hello world", :target => "es", :source => "en"
85
+ })
84
86
  end
85
87
  end
86
88
 
87
89
  context "when debugging the response" do
88
90
  it "returns the full parsed response" do
89
91
  expected_response = stub_good_response("hola mundo")
90
- @connector.request("hello world", "es", :from => "en", :debug => :response).should == expected_response
92
+ expect(
93
+ connector.request("hello world", "es", :from => "en", :debug => :response)
94
+ ).to eq(expected_response)
91
95
  end
92
96
  end
93
97
 
94
98
  context "when debugging the request and the response" do
95
99
  it "returns a hash with the request URL and the full parsed response" do
96
100
  expected_response = stub_good_response("hola mundo")
97
- output = @connector.request("hello world", "es", :from => "en", :debug => :all)
98
- output.should == { :request => { :key=> "apikey", :q => "hello world", :target => "es", :source => "en" }, :response => expected_response }
101
+ output = connector.request("hello world", "es", :from => "en", :debug => :all)
102
+ expect(output).to eq({
103
+ :request => { :key=> "apikey", :q => "hello world", :target => "es", :source => "en" },
104
+ :response => expected_response
105
+ })
99
106
  end
100
107
  end
101
108
  end
@@ -103,7 +110,7 @@ describe ToLang::Connector do
103
110
  context "given an array of strings" do
104
111
  it "returns an array of translated strings" do
105
112
  stub_good_array_response ["hola", "mundo"]
106
- @connector.request(["hello", "world"], "es").should == ["hola", "mundo"]
113
+ expect(connector.request(["hello", "world"], "es")).to eq(["hola", "mundo"])
107
114
  end
108
115
  end
109
116
  end
@@ -12,33 +12,33 @@ describe Hash do
12
12
 
13
13
  test_hashes.each do |hash, params|
14
14
  it "converts hash: #{hash.inspect} to params: #{params.inspect}" do
15
- hash.to_params.split('&').sort.should == params.split('&').sort
15
+ expect(hash.to_params.split('&').sort).to eq(params.split('&').sort)
16
16
  end
17
17
  end
18
18
 
19
19
  it "doesn't leave a trailing &" do
20
- {
20
+ expect({
21
21
  :name => 'Bob',
22
22
  :address => {
23
23
  :street => '111 Ruby Ave.',
24
24
  :city => 'Ruby Central',
25
25
  :phones => ['111-111-1111', '222-222-2222']
26
26
  }
27
- }.to_params.should_not =~ /&$/
27
+ }.to_params).not_to match(/&$/)
28
28
  end
29
29
 
30
30
  it "URL encodes unsafe characters" do
31
- { :q => "?&\" +" }.to_params.should == "q=%3F%26%22%20%2B"
31
+ expect({ :q => "?&\" +" }.to_params).to eq("q=%3F%26%22%20%2B")
32
32
  end
33
33
 
34
34
  it "converts deeply nested hashes" do
35
- {
35
+ expect({
36
36
  :one => {
37
37
  :two => {
38
38
  :three => true
39
39
  }
40
40
  }
41
- }.to_params.should == "one[two][three]=true"
41
+ }.to_params).to eq("one[two][three]=true")
42
42
  end
43
43
  end
44
44
  end
@@ -7,44 +7,40 @@ describe "A translatable class" do
7
7
 
8
8
  describe "#translate" do
9
9
  it "calls ToLang::Connector#request" do
10
- ToLang.connector.stub(:request)
11
- ToLang.connector.should_receive(:request).with("hello world", "es")
10
+ expect(ToLang.connector).to receive(:request).with("hello world", "es")
12
11
  "hello world".translate("es")
13
12
  end
14
13
  end
15
14
 
16
15
  it "will respond to :to_<language>" do
17
- "hello world".should respond_to :to_spanish
16
+ expect("hello world").to respond_to(:to_spanish)
18
17
  end
19
18
 
20
19
  it "will respond to :to_<target>_from_<source>" do
21
- "hello world".should respond_to :to_spanish_from_english
20
+ expect("hello world").to respond_to(:to_spanish_from_english)
22
21
  end
23
22
 
24
23
  it "will respond to :from_<source>_to_<target>" do
25
- "hello world".should respond_to :from_english_to_spanish
24
+ expect("hello world").to respond_to(:from_english_to_spanish)
26
25
  end
27
26
 
28
27
  it "translates to <language> when sent :to_<language>" do
29
- ToLang.connector.stub(:request)
30
- ToLang.connector.should_receive(:request).with("hello world", 'es')
28
+ expect(ToLang.connector).to receive(:request).with("hello world", 'es')
31
29
  "hello world".send(:to_spanish)
32
30
  end
33
31
 
34
32
  it "translates to <target> from <source> when sent :to_<target>_from_<source>" do
35
- ToLang.connector.stub(:request)
36
- ToLang.connector.should_receive(:request).with("hello world", 'es', :from => 'en')
33
+ expect(ToLang.connector).to receive(:request).with("hello world", 'es', :from => 'en')
37
34
  "hello world".send(:to_spanish_from_english)
38
35
  end
39
36
 
40
37
  it "translates to <target> from <source> when sent :from_<source>_to_<target>" do
41
- ToLang.connector.stub(:request)
42
- ToLang.connector.should_receive(:request).with("hello world", 'es', :from => 'en')
38
+ expect(ToLang.connector).to receive(:request).with("hello world", 'es', :from => 'en')
43
39
  "hello world".send(:from_english_to_spanish)
44
40
  end
45
41
 
46
42
  it "defines magic methods when first called and doesn't call :method_missing after that" do
47
- ToLang.connector.stub(:request)
43
+ allow(ToLang.connector).to receive(:request)
48
44
  string = "hello world"
49
45
  magic_methods = lambda do
50
46
  string.to_spanish
@@ -52,7 +48,7 @@ describe "A translatable class" do
52
48
  string.from_english_to_spanish
53
49
  end
54
50
  magic_methods.call
55
- string.should_not_receive(:method_missing)
51
+ expect(string).not_to receive(:method_missing)
56
52
  magic_methods.call
57
53
  end
58
54
 
@@ -7,19 +7,19 @@ describe ToLang do
7
7
  end
8
8
 
9
9
  it "returns false if :start was already called" do
10
- ToLang.start('apikey').should == false
10
+ expect(ToLang.start('apikey')).to be_falsy
11
11
  end
12
12
 
13
13
  it "stores a ToLang::Connector object" do
14
- ToLang.connector.should be_an_instance_of ToLang::Connector
14
+ expect(ToLang.connector).to be_an_instance_of(ToLang::Connector)
15
15
  end
16
16
 
17
17
  it "mixes Translatable into String" do
18
- String.should include ToLang::Translatable
18
+ expect(String).to include(ToLang::Translatable)
19
19
  end
20
20
 
21
21
  it "mixes Translatable into Array" do
22
- Array.should include ToLang::Translatable
22
+ expect(Array).to include(ToLang::Translatable)
23
23
  end
24
24
  end
25
25
  end
@@ -1,5 +1,7 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/to_lang/version", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "to_lang/version"
3
5
 
4
6
  Gem::Specification.new do |s|
5
7
  s.name = "to_lang"
@@ -16,12 +18,8 @@ Gem::Specification.new do |s|
16
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
19
  s.require_paths = ["lib"]
18
20
 
19
- s.add_dependency "httparty", "~> 0.8.0"
20
- s.add_development_dependency "rake", "~> 0.9.2"
21
- s.add_development_dependency "rspec", "~> 2.6.0"
22
- s.add_development_dependency "simplecov", "~> 0.5.3"
23
- s.add_development_dependency "RedCloth", "~> 4.2.8"
24
- s.add_development_dependency "guard-rspec", "~> 0.4.5"
25
- s.add_development_dependency "rb-fsevent", "~> 0.4.3" if RUBY_PLATFORM[/darwin/]
26
- s.add_development_dependency "growl_notify", "~> 0.0.1" if RUBY_PLATFORM[/darwin/]
21
+ s.add_dependency "httparty", ">= 0.8.0"
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rspec", ">= 3.1.0"
24
+ s.add_development_dependency "simplecov", ">= 0.5.3"
27
25
  end
metadata CHANGED
@@ -1,104 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jimmy Cuadra
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
11
+ date: 2015-01-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
- requirement: &70175836589280 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.8.0
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70175836589280
25
- - !ruby/object:Gem::Dependency
26
- name: rake
27
- requirement: &70175836588020 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ~>
24
+ - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 0.9.2
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70175836588020
26
+ version: 0.8.0
36
27
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70175836585300 !ruby/object:Gem::Requirement
39
- none: false
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
40
30
  requirements:
41
- - - ~>
31
+ - - ">="
42
32
  - !ruby/object:Gem::Version
43
- version: 2.6.0
33
+ version: '0'
44
34
  type: :development
45
35
  prerelease: false
46
- version_requirements: *70175836585300
47
- - !ruby/object:Gem::Dependency
48
- name: simplecov
49
- requirement: &70175836583680 !ruby/object:Gem::Requirement
50
- none: false
36
+ version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ~>
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: 0.5.3
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70175836583680
40
+ version: '0'
58
41
  - !ruby/object:Gem::Dependency
59
- name: RedCloth
60
- requirement: &70175836582060 !ruby/object:Gem::Requirement
61
- none: false
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
62
44
  requirements:
63
- - - ~>
45
+ - - ">="
64
46
  - !ruby/object:Gem::Version
65
- version: 4.2.8
47
+ version: 3.1.0
66
48
  type: :development
67
49
  prerelease: false
68
- version_requirements: *70175836582060
69
- - !ruby/object:Gem::Dependency
70
- name: guard-rspec
71
- requirement: &70175836580900 !ruby/object:Gem::Requirement
72
- none: false
50
+ version_requirements: !ruby/object:Gem::Requirement
73
51
  requirements:
74
- - - ~>
52
+ - - ">="
75
53
  - !ruby/object:Gem::Version
76
- version: 0.4.5
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70175836580900
54
+ version: 3.1.0
80
55
  - !ruby/object:Gem::Dependency
81
- name: rb-fsevent
82
- requirement: &70175836579720 !ruby/object:Gem::Requirement
83
- none: false
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
84
58
  requirements:
85
- - - ~>
59
+ - - ">="
86
60
  - !ruby/object:Gem::Version
87
- version: 0.4.3
61
+ version: 0.5.3
88
62
  type: :development
89
63
  prerelease: false
90
- version_requirements: *70175836579720
91
- - !ruby/object:Gem::Dependency
92
- name: growl_notify
93
- requirement: &70175836578060 !ruby/object:Gem::Requirement
94
- none: false
64
+ version_requirements: !ruby/object:Gem::Requirement
95
65
  requirements:
96
- - - ~>
66
+ - - ">="
97
67
  - !ruby/object:Gem::Version
98
- version: 0.0.1
99
- type: :development
100
- prerelease: false
101
- version_requirements: *70175836578060
68
+ version: 0.5.3
102
69
  description: Adds language translation methods to strings and arrays, backed by the
103
70
  Google Translate API
104
71
  email:
@@ -108,14 +75,13 @@ executables:
108
75
  extensions: []
109
76
  extra_rdoc_files: []
110
77
  files:
111
- - .gitignore
112
- - .rspec
113
- - .travis.yml
114
- - .yardopts
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - ".yardopts"
115
82
  - Gemfile
116
- - Guardfile
117
83
  - LICENSE
118
- - README.textile
84
+ - README.md
119
85
  - Rakefile
120
86
  - bin/to_lang
121
87
  - lib/to_lang.rb
@@ -132,33 +98,26 @@ files:
132
98
  - to_lang.gemspec
133
99
  homepage: https://github.com/jimmycuadra/to_lang
134
100
  licenses: []
101
+ metadata: {}
135
102
  post_install_message:
136
103
  rdoc_options: []
137
104
  require_paths:
138
105
  - lib
139
106
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
107
  requirements:
142
- - - ! '>='
108
+ - - ">="
143
109
  - !ruby/object:Gem::Version
144
110
  version: '0'
145
- segments:
146
- - 0
147
- hash: -2363449024598261982
148
111
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
112
  requirements:
151
- - - ! '>='
113
+ - - ">="
152
114
  - !ruby/object:Gem::Version
153
115
  version: '0'
154
- segments:
155
- - 0
156
- hash: -2363449024598261982
157
116
  requirements: []
158
117
  rubyforge_project: to_lang
159
- rubygems_version: 1.8.10
118
+ rubygems_version: 2.4.5
160
119
  signing_key:
161
- specification_version: 3
120
+ specification_version: 4
162
121
  summary: Translate strings with Google Translate
163
122
  test_files:
164
123
  - spec/spec_helper.rb
data/Guardfile DELETED
@@ -1,5 +0,0 @@
1
- guard 'rspec', :cli => '--format nested' do
2
- watch(%r{^spec/.+_spec\.rb})
3
- watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
@@ -1,178 +0,0 @@
1
- h1. to_lang
2
-
3
- *to_lang* is a Ruby library that adds language translation methods to strings and arrays, backed by the Google Translate API.
4
-
5
- h2. Build Status
6
-
7
- "!https://travis-ci.org/jimmycuadra/to_lang.png!":http://travis-ci.org/jimmycuadra/to_lang
8
-
9
- h2. Installation
10
-
11
- Simply run @gem install to_lang@.
12
-
13
- h2. Usage
14
-
15
- To use *to_lang*, require the library, then call @ToLang.start@ with your Google Translate API key. At this point you will have access to all the new translation methods, which take the form @to_language@, where "language" is the language you wish to translate to.
16
-
17
- Google Translate attempts to detect the source language, but you can specify it explicitly by calling methods in the form @to_target_language_from_source_language@, where "target language" is the language you are translating to and "source_language" is the language you are starting with. An inverted form with equivalent functionality, @from_source_language_to_target_language@ is also available. These methods are generated dynamically and will not appear in a calls to @String.instance_methods@ or @Array.instance_methods@ until they have been called once. Strings and arrays will, however, @respond_to?@ these methods prior to their dynamic definition.
18
-
19
- The dynamic methods are simply syntactic sugar for @String#translate@ and @Array#translate@, which you can use directly as well.
20
-
21
- *to_lang* also comes with a command line utility for quick translations from the shell.
22
-
23
- h2. String Examples
24
-
25
- Load and initialize *to_lang*:
26
-
27
- <pre><code>require 'to_lang'
28
- ToLang.start('YOUR_GOOGLE_TRANSLATE_API_KEY')
29
- </code></pre>
30
-
31
- Translate some text to Spanish:
32
-
33
- <pre><code>"Very cool gem!".to_spanish
34
- => "Muy fresco joya!"
35
- </code></pre>
36
-
37
- A case where the source language is ambiguous:
38
-
39
- <pre><code>"a pie".to_spanish
40
- => "a pie"
41
- "a pie".to_spanish_from_english
42
- => "un pastel"
43
- </code></pre>
44
-
45
- Or equivalently:
46
-
47
- <pre><code>"a pie".from_english_to_spanish
48
- => "un pastel"
49
- </code></pre>
50
-
51
- Using @String#translate@ directly:
52
-
53
- <pre><code>"hello world".translate('es')
54
- => "hola mundo"
55
- "a pie".translate('es', :from => 'en')
56
- => "un pastel"
57
- </code></pre>
58
-
59
- h2. Array Examples
60
-
61
- Arrays can be used to translate a batch of strings in a single method call and a single HTTP request. The exact same methods shown above work for arrays as well. For example, to translate an array of strings to Spanish:
62
-
63
- <pre><code>["One", "Two", "Three"].to_spanish
64
- => ["Uno", "Dos", "Tres"]
65
- </code></pre>
66
-
67
- h2. Debugging
68
-
69
- @translate@ also has the advantage of allowing you to get debug output for a translation. @translate@ accepts a @:debug@ option with three possible values: @:request@, @:response@, and @:all@. @:request@ will cause the method to return a hash of the parameters that will be sent to the Google Translate API. @:response@ will cause the method to return the full response from the API call as a hash. @:all@ will cause the method to return a hash which contains both the request hash and the full response.
70
-
71
- <pre><code>"hello world".translate('es', :debug => :request)
72
- => {:key=>"my_key", :q=>"hello world", :target=>"es"}
73
- </code></pre>
74
-
75
- <pre><code>"hello world".translate('es', :debug => :response)
76
- => {"data"=>{"translations"=>[{"translatedText"=>"hola mundo", "detectedSourceLanguage"=>"en"}]}}
77
- </code></pre>
78
-
79
- <pre><code>"hello world".translate('es', :debug => :all)
80
- => {:request=>{:key=>"my_key", :q=>"hello world", :target=>"es"},
81
- :response=>{"data"=>{"translations"=>[{"translatedText"=>"hola mundo",
82
- "detectedSourceLanguage"=>"en"}]}}}
83
- </code></pre>
84
-
85
- h2. Command Line Interface
86
-
87
- The command line utility @to_lang@ has the following interface:
88
-
89
- @to_lang [--key API_KEY] [--from SOURCE_LANGUAGE] --to DESTINATION_LANGUAGE STRING [STRING, ...]@
90
-
91
- @to_lang@ accepts a space separated list of strings to translate. At least one string is required, as is the @--to@ option, which accepts a language code (e.g. "es"). @to_lang@ will attempt to load a Google Translate API key from the @GOOGLE_TRANSLATE_API_KEY@ environment variable. If one is not available, it must be passed in from the command line with the @--key@ option. For complete usage instructions, invoke the utility with the @--help@ option.
92
-
93
- Examples:
94
-
95
- A simple translation with the key being passed in directly from the command line:
96
-
97
- <pre><code>$ to_lang --key YOUR_GOOGLE_TRANSLATE_API_KEY --to es "hello world"
98
- hola mundo
99
- </code></pre>
100
-
101
- With the key in an environment variable and multiple strings:
102
-
103
- <pre><code>$ to_lang --to es "hello world" "a pie"
104
- hola mundo
105
- a pie
106
- </code></pre>
107
-
108
- Specifying the source language:
109
-
110
- <pre><code>$ to_lang --from en --to es "hello world" "a pie"
111
- hola mundo
112
- un pastel
113
- </code></pre>
114
-
115
- h2. Supported Languages
116
-
117
- *to_lang* adds the following methods to strings and arrays. Each of these methods can be called with an explicit source language by appending @_from_source_language@ or prepending @from_source_language_@ to the method name.
118
-
119
- * to_afrikaans
120
- * to_albanian
121
- * to_arabic
122
- * to_belarusian
123
- * to_bulgarian
124
- * to_catalan
125
- * to_simplified_chinese
126
- * to_traditional_chinese
127
- * to_croatian
128
- * to_czech
129
- * to_danish
130
- * to_dutch
131
- * to_english
132
- * to_estonian
133
- * to_filipino
134
- * to_finnish
135
- * to_french
136
- * to_galician
137
- * to_german
138
- * to_greek
139
- * to_haitian_creole
140
- * to_hebrew
141
- * to_hindi
142
- * to_hungarian
143
- * to_icelandic
144
- * to_indonesian
145
- * to_irish
146
- * to_italian
147
- * to_japanese
148
- * to_latvian
149
- * to_lithuanian
150
- * to_macedonian
151
- * to_malay
152
- * to_maltese
153
- * to_norwegian
154
- * to_persian
155
- * to_polish
156
- * to_portuguese
157
- * to_romanian
158
- * to_russian
159
- * to_serbian
160
- * to_slovak
161
- * to_slovenian
162
- * to_spanish
163
- * to_swahili
164
- * to_swedish
165
- * to_thai
166
- * to_turkish
167
- * to_ukrainian
168
- * to_vietnamese
169
- * to_welsh
170
- * to_yiddish
171
-
172
- h2. Documentation
173
-
174
- API documentation can be found at "rubydoc.info":http://rubydoc.info/github/jimmycuadra/to_lang/master/frames.
175
-
176
- h2. Feedback and Contributions
177
-
178
- Feedback is greatly appreciated. If you have any problems with *to_lang*, please open a new issue. Make sure you are using the latest version of the gem, or HEAD if you've cloned the Git repository directly. Please include debugging output from using the @:debug@ option of @translate@, if relevant to your issue. If you'd like to fix bugs, add features, or improve the library in general, feel free to fork the project and send me a pull request with your changes.