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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd3a02d3ab0cfc30144b48b20726d6db2ee1405e
4
- data.tar.gz: 632ffffe353ae40a164ed57d48eaacc38477ee78
3
+ metadata.gz: c2fc4ee1a4ae07170e1d4d0af6fbed84b6ab60e5
4
+ data.tar.gz: 93ca5aa335e0b012a9f9f727926ed4918099fa5e
5
5
  SHA512:
6
- metadata.gz: ade742ec2ce6ac1f36bd828791918441e8cf6ecf5d0d27d224a7222375c7ee2e47dde7fc891fa1143e3f35cb4b4fb0cce25528d46feea856834907aa6165ccc7
7
- data.tar.gz: d4940fd1b2c62d871e1d047656a487571d0d199663cb9a88ac5f60ce0235061e6aed3464281c22a7d7f7e3b650dddbef11de753c9641e01fcb300e2c679c78cb
6
+ metadata.gz: 9ebaa19e5a5598a4053de05f718bf643776c2611bf2d4006ddae8195806e593f8f35b43471f943e1d46ee8f4dea4f617ccc607f621f4ec5351c30f4110725fe2
7
+ data.tar.gz: 30be6bc899940236afe204122fcc916e4441eb2125db0e31a2d0698ec70f2b1fe5aad70a8fa226caa348faf410de2bcef5ea6a26e37f8232233a978c6cc4a0c2
@@ -14,7 +14,7 @@ module Konjak
14
14
  texts = []
15
15
  while true
16
16
  head, match, tail = text.partition(pattern)
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)
@@ -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)
@@ -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
- target_segment.interpolate_gtt_tags(source_segment.extract_gtt_tags_from(text))
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: options[:format]
42
+ format: format
35
43
  )
36
44
  end
45
+
46
+ def format
47
+ options[:format]
48
+ end
37
49
  end
38
50
  end
@@ -0,0 +1,6 @@
1
+ module Konjak
2
+ class Translator
3
+ class TranslatedString < String
4
+ end
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Konjak
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
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.6
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