get_pomo 0.6.1 → 0.6.2

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.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'bump'
data/Gemfile.lock CHANGED
@@ -4,7 +4,7 @@ PATH
4
4
  get_pomo (0.6.1)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  bump (0.3.9)
10
10
  diff-lcs (1.1.3)
@@ -59,4 +59,4 @@ module GetPomo
59
59
  string.split PLURAL_SEPERATOR
60
60
  end
61
61
  end
62
- end
62
+ end
@@ -39,21 +39,21 @@ module GetPomo
39
39
 
40
40
  def to_text
41
41
  GetPomo.unique_translations(translations).map {|translation|
42
- comment = translation.comment.to_s.split(/\n|\r\n/).map{|line|"##{line}\n"}*''
42
+ comment = translation.comment.to_s.split(/\n|\r\n/).map{|line|"#{line}\n"}*''
43
43
  msgid_and_msgstr = if translation.plural?
44
44
  msgids =
45
- %Q(msgid "#{translation.msgid[0]}"\n)+
46
- %Q(msgid_plural "#{translation.msgid[1]}"\n)
45
+ %Q(msgid "#{escape_quotes(translation.msgid[0])}"\n)+
46
+ %Q(msgid_plural "#{escape_quotes(translation.msgid[1])}"\n)
47
47
 
48
48
  msgstrs = []
49
49
  translation.msgstr.each_with_index do |msgstr,index|
50
- msgstrs << %Q(msgstr[#{index}] "#{msgstr}")
50
+ msgstrs << %Q(msgstr[#{index}] "#{escape_quotes(msgstr)}")
51
51
  end
52
52
 
53
53
  msgids + (msgstrs*"\n")
54
54
  else
55
- %Q(msgid "#{translation.msgid}"\n)+
56
- %Q(msgstr "#{translation.msgstr}")
55
+ %Q(msgid "#{escape_quotes(translation.msgid)}"\n)+
56
+ %Q(msgstr "#{escape_quotes(translation.msgstr)}")
57
57
  end
58
58
 
59
59
  comment + msgid_and_msgstr
@@ -62,6 +62,11 @@ module GetPomo
62
62
 
63
63
  private
64
64
 
65
+ def escape_quotes(txt)
66
+ txt.gsub /"/, '\"'
67
+ end
68
+
69
+
65
70
  #e.g. # fuzzy
66
71
  def comment?(line)
67
72
  line =~ /^\s*#/
@@ -69,7 +74,7 @@ module GetPomo
69
74
 
70
75
  def add_comment(line)
71
76
  start_new_translation if translation_complete?
72
- @current_translation.add_text(line.strip.sub('#','')+"\n",:to=>:comment)
77
+ @current_translation.add_text(line.strip+"\n",:to=>:comment)
73
78
  end
74
79
 
75
80
  #msgid "hello"
@@ -82,16 +87,18 @@ module GetPomo
82
87
  method, string = line.match(/^\s*([a-z0-9_\[\]]+)(.*)/)[1..2]
83
88
  raise "no method found" unless method
84
89
 
85
- start_new_translation if method == 'msgid' and translation_complete?
90
+ start_new_translation if %W(msgid msgctxt).include? method and translation_complete?
86
91
  @last_method = method.to_sym
87
92
  add_string(string)
88
93
  end
89
94
 
90
95
  #"hello" -> hello
91
96
  def add_string(string)
92
- return if string.strip.empty?
93
- raise "not string format: #{string.inspect} on line #{@line_number}" unless string.strip =~ /^['"](.*)['"]$/
94
- @current_translation.add_text($1,:to=>@last_method)
97
+ string = string.strip
98
+ return if string.empty?
99
+ raise "not string format: #{string.inspect} on line #{@line_number}" unless string =~ /^['"](.*)['"]$/
100
+ string_content = $1.gsub(/\\"/, '"')
101
+ @current_translation.add_text(string_content, :to=>@last_method)
95
102
  end
96
103
 
97
104
  def translation_complete?
@@ -108,4 +115,4 @@ module GetPomo
108
115
  @current_translation = Translation.new
109
116
  end
110
117
  end
111
- end
118
+ end
@@ -1,7 +1,7 @@
1
1
  module GetPomo
2
2
  class Translation
3
- FUZZY_REGEX = /^\s*fuzzy\s*$/
4
- attr_accessor :msgid, :msgstr, :comment
3
+ FUZZY_REGEX = /^#,\s*fuzzy/
4
+ attr_accessor :msgid, :msgstr, :msgctxt, :comment
5
5
 
6
6
  def add_text(text,options)
7
7
  to = options[:to]
@@ -18,7 +18,7 @@ module GetPomo
18
18
  end
19
19
 
20
20
  def to_hash
21
- {:msgid=>msgid,:msgstr=>msgstr,:comment=>comment}.reject{|k,value|value.nil?}
21
+ {:msgctxt=>msgctxt,:msgid=>msgid,:msgstr=>msgstr,:comment=>comment}.reject{|k,value|value.nil?}
22
22
  end
23
23
 
24
24
  def complete?
@@ -26,12 +26,12 @@ module GetPomo
26
26
  end
27
27
 
28
28
  def fuzzy?
29
- comment =~ FUZZY_REGEX
29
+ !!(comment =~ FUZZY_REGEX)
30
30
  end
31
31
 
32
32
  def fuzzy=(value)
33
33
  if value and not fuzzy?
34
- add_text "\nfuzzy", :to=>:comment
34
+ add_text "\n#, fuzzy", :to=>:comment
35
35
  else
36
36
  self.comment = comment.to_s.split(/$/).reject{|line|line=~FUZZY_REGEX}.join("\n")
37
37
  end
@@ -40,5 +40,13 @@ module GetPomo
40
40
  def plural?
41
41
  msgid.is_a? Array or msgstr.is_a? Array
42
42
  end
43
+
44
+ def singular?
45
+ !plural?
46
+ end
47
+
48
+ def header?
49
+ msgid == ""
50
+ end
43
51
  end
44
- end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module GetPomo
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "get_pomo/po_file"
2
3
 
3
4
  describe GetPomo::PoFile do
4
5
  describe :parse do
@@ -11,6 +12,11 @@ describe GetPomo::PoFile do
11
12
  t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
12
13
  end
13
14
 
15
+ it "parses msgid and msgstr with escaping quote" do
16
+ t = GetPomo::PoFile.parse('msgid "x\"xx"' + "\n" + 'msgstr "y\"yy"')
17
+ t[0].to_hash.should == {:msgid=>'x"xx',:msgstr=>'y"yy'}
18
+ end
19
+
14
20
  it "parses a simple msgid and msg with additional whitespace" do
15
21
  t = GetPomo::PoFile.parse(%Q( msgid "xxx" \n msgstr "yyy" ))
16
22
  t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
@@ -28,12 +34,17 @@ describe GetPomo::PoFile do
28
34
 
29
35
  it "parses simple comments" do
30
36
  t = GetPomo::PoFile.parse(%Q(#test\nmsgid "xxx"\nmsgstr "yyy"))
31
- t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"test\n"}
37
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"#test\n"}
32
38
  end
33
39
 
34
40
  it "parses comments above msgstr" do
35
41
  t = GetPomo::PoFile.parse(%Q(#test\nmsgid "xxx"\n#another\nmsgstr "yyy"))
36
- t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"test\nanother\n"}
42
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"#test\n#another\n"}
43
+ end
44
+
45
+ it "parses a simple string with msgctxt" do
46
+ t = GetPomo::PoFile.parse(%Q(msgctxt "www"\nmsgid "xxx"\nmsgstr "yyy"))
47
+ t[0].to_hash.should == {:msgctxt => 'www', :msgid=>'xxx',:msgstr=>'yyy'}
37
48
  end
38
49
  end
39
50
 
@@ -94,12 +105,33 @@ describe GetPomo::PoFile do
94
105
  GetPomo::PoFile.to_text(GetPomo::PoFile.parse(text)).should == text
95
106
  end
96
107
 
108
+ it "escape double quotes" do
109
+ text = 'msgid "x\"xx"' + "\n" + 'msgstr "y\"yy"'
110
+ po = GetPomo::PoFile.parse(text)
111
+ GetPomo::PoFile.to_text(po).should == text
112
+ end
113
+
114
+ it "does not escape slashes" do
115
+ text = 'msgid "x\\"' + "\n" + 'msgstr "x\\"'
116
+ po = GetPomo::PoFile.parse(text)
117
+ GetPomo::PoFile.to_text(po).should == text
118
+ end
119
+
120
+ it "escape double quotes on plurals" do
121
+ text = 'msgid "x\"xx"' + "\n"
122
+ text += 'msgid_plural "x\"xx"' + "\n"
123
+ text += 'msgstr[0] "y\"yy"' + "\n"
124
+ text += 'msgstr[1] "y\"yy"'
125
+ po = GetPomo::PoFile.parse(text)
126
+ GetPomo::PoFile.to_text(po).should == text
127
+ end
128
+
97
129
  it "adds comments" do
98
130
  t = GetPomo::Translation.new
99
131
  t.msgid = 'a'
100
132
  t.msgstr = 'b'
101
- t.add_text("c\n",:to=>:comment)
102
- t.add_text("d\n",:to=>:comment)
133
+ t.add_text("#c\n",:to=>:comment)
134
+ t.add_text("#d\n",:to=>:comment)
103
135
  GetPomo::PoFile.to_text([t]).should == %Q(#c\n#d\nmsgid "a"\nmsgstr "b")
104
136
  end
105
137
 
@@ -79,11 +79,45 @@ describe GetPomo::Translation do
79
79
  end
80
80
  end
81
81
 
82
+ describe :singular? do
83
+ it{should be_singular}
84
+
85
+ it "is not singular if msgid is plural" do
86
+ subject.add_text("x",:to=>:msgid_plural)
87
+ should_not be_singular
88
+ end
89
+
90
+ it "is not singular if msgstr is plural" do
91
+ subject.add_text("x",:to=>"msgstr[0]")
92
+ should_not be_singular
93
+ end
94
+
95
+ it "is singular if simple strings where added" do
96
+ subject.msgid = "a"
97
+ subject.msgstr = "a"
98
+ should be_singular
99
+ end
100
+ end
101
+
102
+ describe :header? do
103
+ it{should_not be_header}
104
+
105
+ it "is header if msgid is empty" do
106
+ subject.msgid = ""
107
+ should be_header
108
+ end
109
+
110
+ it "is not header if there is something on msgid" do
111
+ subject.msgid = "a"
112
+ should_not be_header
113
+ end
114
+ end
115
+
82
116
  describe :fuzzy? do
83
117
  it{should_not be_fuzzy}
84
118
 
85
119
  it "is fuzzy if a fuzzy comment was added" do
86
- subject.add_text("fuzzy",:to=>:comment)
120
+ subject.add_text("#, fuzzy",:to=>:comment)
87
121
  should be_fuzzy
88
122
  end
89
123
 
@@ -98,14 +132,14 @@ describe GetPomo::Translation do
98
132
  end
99
133
 
100
134
  it "changes comment when made fuzzy through fuzzy=" do
101
- subject.comment = "hello"
135
+ subject.comment = "# hello"
102
136
  subject.fuzzy = true
103
- subject.comment.should == "hello\nfuzzy"
137
+ subject.comment.should == "# hello\n#, fuzzy"
104
138
  end
105
139
 
106
140
  it "changes empty comment when made fuzzy through fuzzy=" do
107
141
  subject.fuzzy = true
108
- subject.comment.should == "\nfuzzy"
142
+ subject.comment.should == "\n#, fuzzy"
109
143
  end
110
144
 
111
145
  it "preserves comments when making fuzzy/unfuzzy" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_pomo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-19 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -29,8 +29,6 @@ files:
29
29
  - lib/get_pomo/po_file.rb
30
30
  - lib/get_pomo/translation.rb
31
31
  - lib/get_pomo/version.rb
32
- - prototype_treetop/po.treetop
33
- - prototype_treetop/test.rb
34
32
  - spec/files/complex.mo
35
33
  - spec/files/empty.mo
36
34
  - spec/files/plural.mo
@@ -57,21 +55,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
55
  - - ! '>='
58
56
  - !ruby/object:Gem::Version
59
57
  version: '0'
60
- segments:
61
- - 0
62
- hash: 3196374221407086229
63
58
  required_rubygems_version: !ruby/object:Gem::Requirement
64
59
  none: false
65
60
  requirements:
66
61
  - - ! '>='
67
62
  - !ruby/object:Gem::Version
68
63
  version: '0'
69
- segments:
70
- - 0
71
- hash: 3196374221407086229
72
64
  requirements: []
73
65
  rubyforge_project:
74
- rubygems_version: 1.8.24
66
+ rubygems_version: 1.8.25
75
67
  signing_key:
76
68
  specification_version: 3
77
69
  summary: ! 'Ruby/Gettext: A .po and .mo file parser/generator'
@@ -1,25 +0,0 @@
1
- grammar Po
2
- rule translation
3
- msgid whitespace string
4
- end
5
-
6
- rule string
7
- string whitespace string
8
- end
9
-
10
- rule quote
11
- '"'
12
- end
13
-
14
- rule text
15
- [^"]*
16
- end
17
-
18
- rule whitespace
19
- [ \t\n\r]+
20
- end
21
-
22
- rule msgid
23
- "msgid"
24
- end
25
- end
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'treetop'
3
-
4
- Treetop.load "po"
5
- parser = PoParser.new
6
- puts parser.parse(%Q(msgid "xxx" "yyy"))