konjak 0.0.7 → 0.0.8

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: c2fc4ee1a4ae07170e1d4d0af6fbed84b6ab60e5
4
- data.tar.gz: 93ca5aa335e0b012a9f9f727926ed4918099fa5e
3
+ metadata.gz: cdc98142b5ed2a6814a96cf76c8d9c0f7bd2c5d2
4
+ data.tar.gz: f286772061e56d381e8f4f227e47ae9bfa259362
5
5
  SHA512:
6
- metadata.gz: 9ebaa19e5a5598a4053de05f718bf643776c2611bf2d4006ddae8195806e593f8f35b43471f943e1d46ee8f4dea4f617ccc607f621f4ec5351c30f4110725fe2
7
- data.tar.gz: 30be6bc899940236afe204122fcc916e4441eb2125db0e31a2d0698ec70f2b1fe5aad70a8fa226caa348faf410de2bcef5ea6a26e37f8232233a978c6cc4a0c2
6
+ metadata.gz: ca86d1d1693776a7b3a5e57c687daf199d879cbb2e01c6ad6d806def612d1cc01e1c0938b91cf87b837406cb4bdbeee713a4c5d2043c1319faf3e22fc6798beb
7
+ data.tar.gz: 4339756d7df8a10a218d906cb12b85af05389056ebddef23219f9f6ecdd75f6c12f9010a4b5164faed85ee72a7e2a3f80f44151dde99cb51b7c8438ce3b92888
@@ -10,6 +10,7 @@ module Konjak
10
10
  regexp = regexp.gsub(/\\\{#{n}\\\}/) { "\\k<n#{n}>" }
11
11
  regexp = regexp.gsub(/\\\{\/#{n}\\\}/) { "</\\k<_#{n}>>" }
12
12
  end
13
+ regexp = regexp.gsub(/(\\\s|\n)/m) { '\s+' }
13
14
  Regexp.compile(regexp)
14
15
  end
15
16
 
@@ -15,6 +15,12 @@ module Konjak
15
15
  [Text, BeginPairedTag, EndPairedTag, IsolatedTag, Placeholder, Highlight].any? {|c| c === element }
16
16
  end
17
17
 
18
+ def compile_pattern
19
+ regexp = Regexp.escape(text)
20
+ regexp = regexp.gsub(/(\\\s|\n)/m) { '\s+' }
21
+ Regexp.compile(regexp)
22
+ end
23
+
18
24
  def translation_unit
19
25
  TranslationUnit.new(translation_unit_variant.parent)
20
26
  end
@@ -9,11 +9,11 @@ module Konjak
9
9
 
10
10
  def split(translation_unit, text)
11
11
  segment = translation_unit.variant(@lang).segment
12
- segment_text = segment.text
12
+ pattern = segment.compile_pattern
13
13
 
14
14
  texts = []
15
15
  while true
16
- head, match, tail = text.partition(segment_text)
16
+ head, match, tail = text.partition(pattern)
17
17
  break if match.empty? || text.length < min_segment_length
18
18
  texts << head unless head.empty?
19
19
 
@@ -1,3 +1,3 @@
1
1
  module Konjak
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -8,20 +8,30 @@ this is data (with a non-standard character: ).
8
8
  this is data (with a non-standard character: ).
9
9
  DOC
10
10
 
11
- subject { Konjak.translate(doc, sample_tmx, 'EN', 'FR-CA').join }
12
-
13
- it { is_expected.to eq <<EXPECT }
11
+ let(:expected) { <<EXPECT }
14
12
  this is données (avec un caractère non standard: ).
15
13
  this is données (avec un caractère non standard: ).
16
14
  EXPECT
17
15
 
16
+ subject { Konjak.translate(doc, sample_tmx, 'EN', 'FR-CA').join }
17
+
18
+ it { is_expected.to eq expected }
19
+
20
+ context 'when blanks between words is not exactly match' do
21
+ let(:doc) { <<DOC }
22
+ this is data (with a non-standard
23
+
24
+ character: ).
25
+ this is data (with a non-standard character: ).
26
+ DOC
27
+
28
+ it { is_expected.to eq expected }
29
+ end
30
+
18
31
  context 'when passed Tmx' do
19
32
  subject { Konjak.translate(doc, Konjak.parse(sample_tmx), 'EN', 'FR-CA').join }
20
33
 
21
- it { is_expected.to eq <<EXPECT }
22
- this is données (avec un caractère non standard: ).
23
- this is données (avec un caractère non standard: ).
24
- EXPECT
34
+ it { is_expected.to eq expected }
25
35
  end
26
36
 
27
37
  context 'when format is GTT' do
@@ -32,13 +42,29 @@ This is <a href="http://example.com">example</a>.
32
42
  And This is <b>example</b>. Yey.
33
43
  And This is example.
34
44
  GTT_HTML
35
-
36
- subject { Konjak.translate(doc, gtt_tmx, 'en', 'ja', format: :gtt_html).join }
37
-
38
- it { is_expected.to eq <<EXPECT }
45
+ let(:expected) { <<EXPECT }
39
46
  これは、 <a href="http://example.com">例</a> 。
40
47
  And これは、 <b>例</b> 。 Yey.
41
48
  And This is example.
42
49
  EXPECT
50
+
51
+ subject { Konjak.translate(doc, gtt_tmx, 'en', 'ja', format: :gtt_html).join }
52
+
53
+ it { is_expected.to eq expected }
54
+
55
+ context 'when blanks between words is not exactly match' do
56
+ let(:doc) { <<GTT_HTML }
57
+ This is <a href="http://example.com">example</a>.
58
+ And This
59
+ is
60
+
61
+
62
+ <b>example</b>. Yey.
63
+ And This is example.
64
+ GTT_HTML
65
+
66
+ it { is_expected.to eq expected }
67
+ end
68
+
43
69
  end
44
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konjak
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Higa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mem