tr4n5l4te 1.0.0 → 1.1.0
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 +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +37 -5
- data/lib/tr4n5l4te/configuration.rb +2 -1
- data/lib/tr4n5l4te/runner.rb +27 -4
- data/lib/tr4n5l4te/translator.rb +12 -4
- data/lib/tr4n5l4te/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: de91f2f7be53edf09dac7ac551203443908e35313912974a829214b9171bf470
|
|
4
|
+
data.tar.gz: 6406468eb4da61b7fcb1448a24842b0a8125cb461680f673cbf7a82e5c0024d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd08cbe5857f621d10569ce363e34364c88497b5688025b66790e770602af8e1622cc72b1ee64685544b17b2993cea2643d89e6bb838000611379f971f4d39fc
|
|
7
|
+
data.tar.gz: '0381e45fd11649394d0002c8e648ff1cb2be416e47dc5fdb84425f6f4a3a6fe69dff574b967e13bbf0101e0470e39d050bf15e5dbd4b26bd7bd4beba0e6f2e1f'
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
*1.1.0* (February 17, 2026)
|
|
2
|
+
|
|
3
|
+
* Add proxy support for Net::HTTP requests (host:port or user:pass@host:port)
|
|
4
|
+
* Add -p/--proxy CLI option
|
|
5
|
+
* Add configurable proxy via Tr4n5l4te.configure
|
|
6
|
+
* Update README with proxy documentation
|
|
7
|
+
|
|
1
8
|
*1.0.0* (February 14, 2026)
|
|
2
9
|
|
|
3
10
|
* Replace PhantomJS/Poltergeist with direct HTTP translation via Google's undocumented translate endpoint
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
# Tr4n5l4te
|
|
2
2
|
|
|
3
|
-
**Version:
|
|
3
|
+
**Version: 1.1.0**
|
|
4
4
|
|
|
5
5
|
Use Google Translate without an API key.
|
|
6
6
|
|
|
7
|
-
Like me, maybe you've found that Google makes it a pain to work with their API. Tr4n5l4te gets around all that.
|
|
7
|
+
Like me, maybe you've found that Google makes it a pain to work with their API. Tr4n5l4te gets around all that by using Google's free translation endpoint directly via HTTP — no browser, no API key, no headless dependencies.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
First, install [PhantomJS](http://phantomjs.org/).
|
|
12
|
-
|
|
13
11
|
Add this line to your application's Gemfile:
|
|
14
12
|
|
|
15
13
|
```ruby
|
|
@@ -24,6 +22,8 @@ Or install it yourself as:
|
|
|
24
22
|
|
|
25
23
|
$ gem install tr4n5l4te
|
|
26
24
|
|
|
25
|
+
Requires Ruby >= 3.2.
|
|
26
|
+
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
29
|
In your code:
|
|
@@ -41,6 +41,8 @@ end
|
|
|
41
41
|
# => cómo estás
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
Ruby string interpolation variables (`%{var}`) are preserved through translation.
|
|
45
|
+
|
|
44
46
|
### Command Line
|
|
45
47
|
|
|
46
48
|
➤ ./exe/translate -h
|
|
@@ -49,7 +51,8 @@ end
|
|
|
49
51
|
-l, --lang=<s> Destination language
|
|
50
52
|
-i, --list List known languages
|
|
51
53
|
-s, --sleep-time=<i> Sleep time (default: 2)
|
|
52
|
-
-t, --timeout=<i>
|
|
54
|
+
-t, --timeout=<i> HTTP request timeout (default: 30)
|
|
55
|
+
-p, --proxy=<s> Proxy - host:port or user:pass@host:port
|
|
53
56
|
-v, --verbose Be verbose with output
|
|
54
57
|
-h, --help Show this message
|
|
55
58
|
|
|
@@ -63,10 +66,39 @@ The translator will sleep for 2 seconds, by default, between each string transla
|
|
|
63
66
|
|
|
64
67
|
Warning: If you pass in '0' and translate a large file, it is very likely that Google will ban your IP address.
|
|
65
68
|
|
|
69
|
+
### Proxy Support
|
|
70
|
+
|
|
71
|
+
Route requests through an HTTP proxy to avoid IP bans or to use from behind a firewall:
|
|
72
|
+
|
|
73
|
+
$ ./exe/translate -y config/locales/en.yml -l French -p proxy.example.com:8080
|
|
74
|
+
|
|
75
|
+
With authentication:
|
|
76
|
+
|
|
77
|
+
$ ./exe/translate -y config/locales/en.yml -l French -p user:pass@proxy.example.com:8080
|
|
78
|
+
|
|
79
|
+
You can also configure a proxy programmatically:
|
|
80
|
+
|
|
81
|
+
```ruby
|
|
82
|
+
Tr4n5l4te.configure do |config|
|
|
83
|
+
config.proxy = { addr: 'proxy.example.com', port: 8080 }
|
|
84
|
+
# or with authentication:
|
|
85
|
+
config.proxy = { addr: 'proxy.example.com', port: 8080, user: 'user', pass: 'pass' }
|
|
86
|
+
end
|
|
87
|
+
```
|
|
88
|
+
|
|
66
89
|
To list all known languages
|
|
67
90
|
|
|
68
91
|
$ ./exe/translate --list
|
|
69
92
|
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
Tr4n5l4te.configure do |config|
|
|
97
|
+
config.timeout = 60 # HTTP request timeout in seconds (default: 30)
|
|
98
|
+
config.proxy = { addr: 'proxy.example.com', port: 8080 } # optional HTTP proxy
|
|
99
|
+
end
|
|
100
|
+
```
|
|
101
|
+
|
|
70
102
|
## Development
|
|
71
103
|
|
|
72
104
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/tr4n5l4te/runner.rb
CHANGED
|
@@ -7,6 +7,7 @@ require 'midwire_common/string'
|
|
|
7
7
|
require 'pry' unless ENV.fetch('GEM_ENV', nil).nil?
|
|
8
8
|
|
|
9
9
|
module Tr4n5l4te
|
|
10
|
+
# rubocop:disable Metrics/ClassLength
|
|
10
11
|
class Runner
|
|
11
12
|
attr_accessor :logger, :options, :count
|
|
12
13
|
|
|
@@ -24,10 +25,7 @@ module Tr4n5l4te
|
|
|
24
25
|
log_identifier(start_time)
|
|
25
26
|
@count = 0
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
Tr4n5l4te.configure do |config|
|
|
29
|
-
config.timeout = options[:timeout]
|
|
30
|
-
end
|
|
28
|
+
apply_configuration
|
|
31
29
|
|
|
32
30
|
hash = YAML.load_file(options[:yaml_file])
|
|
33
31
|
translated = process(hash)
|
|
@@ -109,6 +107,11 @@ module Tr4n5l4te
|
|
|
109
107
|
'HTTP request timeout - default 30',
|
|
110
108
|
type: :integer, default: 30, short: 't'
|
|
111
109
|
)
|
|
110
|
+
opt(
|
|
111
|
+
:proxy,
|
|
112
|
+
'Proxy - host:port or user:pass@host:port',
|
|
113
|
+
type: :string, required: false, short: 'p'
|
|
114
|
+
)
|
|
112
115
|
opt(
|
|
113
116
|
:verbose,
|
|
114
117
|
'Be verbose with output',
|
|
@@ -138,9 +141,29 @@ module Tr4n5l4te
|
|
|
138
141
|
end
|
|
139
142
|
# rubocop:enable Metrics/AbcSize
|
|
140
143
|
|
|
144
|
+
def apply_configuration
|
|
145
|
+
Tr4n5l4te.configure do |config|
|
|
146
|
+
config.timeout = options[:timeout]
|
|
147
|
+
config.proxy = parse_proxy(options[:proxy]) if options[:proxy]
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def parse_proxy(proxy_string)
|
|
152
|
+
if proxy_string.include?('@')
|
|
153
|
+
auth, host_port = proxy_string.split('@', 2)
|
|
154
|
+
user, pass = auth.split(':', 2)
|
|
155
|
+
addr, port = host_port.split(':', 2)
|
|
156
|
+
{ addr:, port: port.to_i, user:, pass: }
|
|
157
|
+
else
|
|
158
|
+
addr, port = proxy_string.split(':', 2)
|
|
159
|
+
{ addr:, port: port.to_i }
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
141
163
|
def log_identifier(start_time)
|
|
142
164
|
timestr = start_time.strftime('%H:%M:%S.%3N')
|
|
143
165
|
puts("Starting Tr4n5l4te v#{Tr4n5l4te::VERSION} @#{timestr}".green)
|
|
144
166
|
end
|
|
145
167
|
end
|
|
168
|
+
# rubocop:enable Metrics/ClassLength
|
|
146
169
|
end
|
data/lib/tr4n5l4te/translator.rb
CHANGED
|
@@ -44,14 +44,22 @@ module Tr4n5l4te
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def build_http(uri)
|
|
47
|
-
|
|
48
|
-
http =
|
|
47
|
+
config = Tr4n5l4te.configuration
|
|
48
|
+
http = create_http_client(uri, config.proxy)
|
|
49
49
|
http.use_ssl = true
|
|
50
|
-
http.open_timeout = timeout
|
|
51
|
-
http.read_timeout = timeout
|
|
50
|
+
http.open_timeout = config.timeout
|
|
51
|
+
http.read_timeout = config.timeout
|
|
52
52
|
http
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
+
def create_http_client(uri, proxy)
|
|
56
|
+
if proxy
|
|
57
|
+
Net::HTTP.new(uri.host, uri.port, proxy[:addr], proxy[:port], proxy[:user], proxy[:pass])
|
|
58
|
+
else
|
|
59
|
+
Net::HTTP.new(uri.host, uri.port)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
55
63
|
def extract_translation(body)
|
|
56
64
|
parsed = JSON.parse(body)
|
|
57
65
|
parsed[0].map { |segment| segment[0] }.join
|
data/lib/tr4n5l4te/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tr4n5l4te
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Blackburn
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-02-
|
|
10
|
+
date: 2026-02-17 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: colored
|