translate_self 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -9
- data/benchmark.rb +8 -2
- data/lib/translate_self.rb +0 -3
- data/lib/translate_self/translatable_string.rb +1 -1
- data/lib/translate_self/translation.rb +3 -2
- data/lib/translate_self/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: 680f027a575420fab6eb29bbdb7a49a0410e8b6e51adb0775c6dc884539d84bc
|
4
|
+
data.tar.gz: 51afe0c1d56642d3a9b0d6b2578de001da729a10f8c05b2f61a8ed04f383d639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ead7740d0183cb4959789c62ebebd6ed2bc5a3f528d1b1a4b1e97e71e3607b30dbf52686878dc5bb60e566be3516bcbdd23cfc7e9237cc2ddf0647ac0405a9f2
|
7
|
+
data.tar.gz: 42b7fa5b9d7c68b98fd6884c24808834287c2b0ec63b252970c43bb3fe4083bd5c3a6c3aff5d474fac478ae7b33d8de59dc735c9ad42c9014d1f11167682e65b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -101,17 +101,22 @@ hello.translate
|
|
101
101
|
Create a string 5000000 times.
|
102
102
|
|
103
103
|
```shell
|
104
|
-
C:\home\sampo\translate_self> ruby benchmark.rb
|
105
|
-
Rehearsal
|
106
|
-
normal string
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
104
|
+
C:\home\sampo\translate_self> ruby benchmark.rb
|
105
|
+
Rehearsal --------------------------------------------------------
|
106
|
+
normal string 0.221517 0.000101 0.221618 ( 0.221677)
|
107
|
+
monkeypatched string 0.267748 0.000000 0.267748 ( 0.267865)
|
108
|
+
translatable string 1.878466 0.000000 1.878466 ( 1.878497)
|
109
|
+
----------------------------------------------- total: 2.367832sec
|
110
|
+
|
111
|
+
user system total real
|
112
|
+
normal string 0.225292 0.000000 0.225292 ( 0.225289)
|
113
|
+
monkeypatched string 0.225690 0.000000 0.225690 ( 0.225740)
|
114
|
+
translatable string 1.886653 0.000000 1.886653 ( 1.886735)
|
115
|
+
|
113
116
|
```
|
114
117
|
So... the overhead might be surprisingly low!
|
118
|
+
If you use the TranslatableString class, there is some overhead.
|
119
|
+
But if you just hack string it's pretty fast! See `benchmark.rb`.
|
115
120
|
|
116
121
|
## Development
|
117
122
|
|
data/benchmark.rb
CHANGED
@@ -2,15 +2,21 @@ require 'benchmark'
|
|
2
2
|
|
3
3
|
n = 5000000
|
4
4
|
Benchmark.bmbm do |x|
|
5
|
-
x.report("string") do
|
5
|
+
x.report("normal string") do
|
6
6
|
n.times do
|
7
7
|
'hello'
|
8
8
|
end
|
9
9
|
end
|
10
|
-
x.report('
|
10
|
+
x.report('monkeypatched string') do
|
11
11
|
require 'translate_self'
|
12
12
|
n.times do
|
13
13
|
'hello'
|
14
14
|
end
|
15
15
|
end
|
16
|
+
x.report('translatable string') do
|
17
|
+
require 'translate_self'
|
18
|
+
n.times do
|
19
|
+
TranslatableString.new('hello')
|
20
|
+
end
|
21
|
+
end
|
16
22
|
end
|
data/lib/translate_self.rb
CHANGED
@@ -6,11 +6,8 @@ require 'deepl'
|
|
6
6
|
|
7
7
|
# Dangerously include translation methods to strings!
|
8
8
|
module TranslateSelf
|
9
|
-
include Translation
|
10
|
-
class Error < StandardError; end
|
11
9
|
DeepL.configure do |config|
|
12
10
|
config.auth_key = ENV['DEEPL_AUTH_KEY']
|
13
11
|
config.host = ENV['DEEPL_HOST'] || 'https://api-free.deepl.com' # Default value is 'https://api.deepl.com'
|
14
12
|
end
|
15
|
-
AVAILABLE_LANGUAGES = %w[bg cs da de el en es et fi fr hu it ja lt lv nl pl pt ro ru sk sl sv zh].freeze
|
16
13
|
end
|
@@ -2,10 +2,11 @@ require 'deepl'
|
|
2
2
|
|
3
3
|
# The part where the actual translation happens.
|
4
4
|
module Translation
|
5
|
+
@@languages = %w[bg cs da de el en es et fi fr hu it ja lt lv nl pl pt ro ru sk sl sv zh].freeze
|
5
6
|
attr_accessor :language, :to_language
|
6
7
|
|
7
8
|
def available_languages
|
8
|
-
|
9
|
+
@@languages
|
9
10
|
end
|
10
11
|
|
11
12
|
# Translates self to the desired language. \
|
@@ -39,7 +40,7 @@ module Translation
|
|
39
40
|
#
|
40
41
|
# @param [String] the language to translate to, e.g. "fi"
|
41
42
|
# @return [String] the contents translated to another language
|
42
|
-
|
43
|
+
@@languages.each do |lan|
|
43
44
|
define_method("translate_to_#{lan}") do |language = lan|
|
44
45
|
call_deepl(self, self.language, language)
|
45
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translate_self
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sampo Kuokkanen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deepl-rb
|