tr4n5l4te 0.1.2 → 0.1.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: baf43689ac0bdb8454bf5f0d17075b43de3adce8
4
- data.tar.gz: dd0db7f6b12a6593487768e2383af0b063bbc2af
3
+ metadata.gz: 2b4177a4047cbccd5f83335dae72a39945ba4bee
4
+ data.tar.gz: a11c1373ef983181b6a73bee55797ff43d196b9b
5
5
  SHA512:
6
- metadata.gz: 2a31f3386128e42588df190dce4375e2d2cda12a70ce0ad27a2b9b6686cf37a760e48fb2f8d30c0ddf362a547ce4fb0f56f348a784e7808af9f0a54b9cd9f8b6
7
- data.tar.gz: 8cbe2bfeb0da12bf7008e5beef5caa6c338fc6496e38faa11aa5cfff69cfaf95bf378994c62bd837b2c5837e9600bbac4d9681b8494ba76e6b92f8f6e0e52655
6
+ metadata.gz: 2c7bf02c1d0193dab810c7fee10762de2a9ebdfe89d2cb53bb6903e39e4e39f1a48129b8ff7fb68a1601de0671b6629f0e571bf8fe85ee594a8ed656f1c1ae43
7
+ data.tar.gz: 8a946e815184707c392521322e61829c86703f2992634fa286527debaa4aef51e6c8ba2991394fcf361cc0a2835ed32ea87f9c50e6434b97a97d73a681735ce2
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *0.1.3* (March 16, 2016)
2
+
3
+ * Warn when passing in a non-string to the Translator.
4
+ * Update README to include PhantomJS dependency and sleep_time override for command line translator.
5
+
1
6
  *0.1.2* (March 15, 2016)
2
7
 
3
8
  * Don't attempt to translate empty or nil strings.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tr4n5l4te
2
2
 
3
- **Version: 0.1.2**
3
+ **Version: 0.1.3**
4
4
 
5
5
  Use Google Translate without an API key.
6
6
 
@@ -8,6 +8,8 @@ Like me, maybe you've found that Google makes it a pain to work with their API.
8
8
 
9
9
  ## Installation
10
10
 
11
+ First, install [PhantomJS](http://phantomjs.org/).
12
+
11
13
  Add this line to your application's Gemfile:
12
14
 
13
15
  ```ruby
@@ -39,10 +41,18 @@ end
39
41
  # => cómo estás
40
42
  ```
41
43
 
44
+ ### Command Line
45
+
42
46
  To translate a YAML file:
43
47
 
44
48
  $ ./exe/translate -y /path/to/yml/file -l "destination-language"
45
49
 
50
+ The translator will sleep for 2 seconds, by default, between each string translation. You can override that by passing in the amount of time, in seconds, you want it to sleep:
51
+
52
+ $ ./exe/translate -y config/locales/en.yml -l French -s 3
53
+
54
+ Warning: If you pass in '0' and translate a large file, it is very likely that Google will ban your IP address.
55
+
46
56
  To list all known languages
47
57
 
48
58
  $ ./exe/translate -t
@@ -12,20 +12,32 @@ module Tr4n5l4te
12
12
  end
13
13
 
14
14
  def translate(text, from_lang, to_lang)
15
- return '' if text.nil? || text == ''
15
+ encoded_text = validate_and_encode(text)
16
+ return '' if encoded_text == ''
17
+ smart_visit(translator_url(encoded_text, from_lang, to_lang))
18
+ result_box = browser.find('#result_box')
19
+ result_box.text
20
+ end
21
+
22
+ private
23
+
24
+ def validate_and_encode(text)
25
+ return '' if text.nil?
26
+ fail "Cannot translate a [#{text.class}]: '#{text}'" unless text.respond_to?(:gsub)
16
27
  text.strip!
17
- return '' if text == ''
18
- encoded_text = URI.encode(text)
19
- url = "#{START_PAGE}/##{from_lang}/#{to_lang}/#{encoded_text}"
28
+ URI.encode(text)
29
+ end
30
+
31
+ def smart_visit(url)
20
32
  load_cookies
21
33
  agent.visit(url)
22
34
  store_cookies
23
35
  sleep_default
24
- result_box = browser.find('#result_box')
25
- result_box.text
26
36
  end
27
37
 
28
- private
38
+ def translator_url(encoded_text, from_lang, to_lang)
39
+ "#{START_PAGE}/##{from_lang}/#{to_lang}/#{encoded_text}"
40
+ end
29
41
 
30
42
  def store_cookies
31
43
  agent.store_cookies(Tr4n5l4te.cookie_file)
@@ -1,3 +1,3 @@
1
1
  module Tr4n5l4te
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr4n5l4te
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler