konjak 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/konjak/tmx_segmentor/gtt_html_strategy.rb +1 -1
- data/lib/konjak/tmx_segmentor/strategy.rb +12 -1
- data/lib/konjak/tmx_segmentor/text_strategy.rb +1 -1
- data/lib/konjak/translator.rb +14 -2
- data/lib/konjak/translator/translated_string.rb +6 -0
- data/lib/konjak/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2fc4ee1a4ae07170e1d4d0af6fbed84b6ab60e5
|
4
|
+
data.tar.gz: 93ca5aa335e0b012a9f9f727926ed4918099fa5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ebaa19e5a5598a4053de05f718bf643776c2611bf2d4006ddae8195806e593f8f35b43471f943e1d46ee8f4dea4f617ccc607f621f4ec5351c30f4110725fe2
|
7
|
+
data.tar.gz: 30be6bc899940236afe204122fcc916e4441eb2125db0e31a2d0698ec70f2b1fe5aad70a8fa226caa348faf410de2bcef5ea6a26e37f8232233a978c6cc4a0c2
|
@@ -7,9 +7,10 @@ module Konjak
|
|
7
7
|
class Strategy
|
8
8
|
include Mem
|
9
9
|
|
10
|
-
def initialize(tmx, lang)
|
10
|
+
def initialize(tmx, lang, options = {})
|
11
11
|
@tmx = tmx
|
12
12
|
@lang = lang
|
13
|
+
@options = default_options.merge(options)
|
13
14
|
end
|
14
15
|
|
15
16
|
def segmentize(text)
|
@@ -26,9 +27,19 @@ module Konjak
|
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
def default_options
|
31
|
+
{min_segment_length: 10}
|
32
|
+
end
|
33
|
+
|
34
|
+
def min_segment_length
|
35
|
+
@options[:min_segment_length]
|
36
|
+
end
|
37
|
+
|
29
38
|
def translation_units
|
30
39
|
@tmx.body.translation_units.sort_by {|tu|
|
31
40
|
-tu.variant(@lang).segment.text.length
|
41
|
+
}.reject {|tu|
|
42
|
+
tu.variant(@lang).segment.text.length < min_segment_length
|
32
43
|
}
|
33
44
|
end
|
34
45
|
memoize :translation_units
|
@@ -14,7 +14,7 @@ module Konjak
|
|
14
14
|
texts = []
|
15
15
|
while true
|
16
16
|
head, match, tail = text.partition(segment_text)
|
17
|
-
break if match.empty?
|
17
|
+
break if match.empty? || text.length < min_segment_length
|
18
18
|
texts << head unless head.empty?
|
19
19
|
|
20
20
|
texts << SegmentString.new(match, segment)
|
data/lib/konjak/translator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'mem'
|
2
2
|
require 'konjak/tmx_segmentor'
|
3
|
+
require 'konjak/translator/translated_string'
|
3
4
|
|
4
5
|
module Konjak
|
5
6
|
class Translator
|
@@ -20,7 +21,14 @@ module Konjak
|
|
20
21
|
next text unless text.is_a?(TmxSegmentor::SegmentString)
|
21
22
|
source_segment = text.segment
|
22
23
|
target_segment = source_segment.translation_unit.variant(target_lang).segment
|
23
|
-
|
24
|
+
|
25
|
+
if format == :gtt_html
|
26
|
+
gtt_tags = source_segment.extract_gtt_tags_from(text)
|
27
|
+
translated_string = target_segment.interpolate_gtt_tags(gtt_tags)
|
28
|
+
TranslatedString.new(translated_string)
|
29
|
+
else
|
30
|
+
TranslatedString.new(target_segment.text)
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
@@ -31,8 +39,12 @@ module Konjak
|
|
31
39
|
content,
|
32
40
|
tmx: tmx,
|
33
41
|
lang: src_lang,
|
34
|
-
format:
|
42
|
+
format: format
|
35
43
|
)
|
36
44
|
end
|
45
|
+
|
46
|
+
def format
|
47
|
+
options[:format]
|
48
|
+
end
|
37
49
|
end
|
38
50
|
end
|
data/lib/konjak/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: konjak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Seiei Higa
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- lib/konjak/translation_unit.rb
|
172
172
|
- lib/konjak/translation_unit_variant.rb
|
173
173
|
- lib/konjak/translator.rb
|
174
|
+
- lib/konjak/translator/translated_string.rb
|
174
175
|
- lib/konjak/unknown_tag.rb
|
175
176
|
- lib/konjak/user_defined_encoding.rb
|
176
177
|
- lib/konjak/version.rb
|