tr4n5l4te 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/README.md +11 -1
- data/lib/tr4n5l4te/translator.rb +19 -7
- data/lib/tr4n5l4te/version.rb +1 -1
- 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: 2b4177a4047cbccd5f83335dae72a39945ba4bee
|
|
4
|
+
data.tar.gz: a11c1373ef983181b6a73bee55797ff43d196b9b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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
|
data/lib/tr4n5l4te/translator.rb
CHANGED
|
@@ -12,20 +12,32 @@ module Tr4n5l4te
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def translate(text, from_lang, to_lang)
|
|
15
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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)
|
data/lib/tr4n5l4te/version.rb
CHANGED
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.
|
|
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-
|
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|