get_pomo 0.6.3 → 0.7.0
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.
- checksums.yaml +4 -4
- data/lib/get_pomo/po_file.rb +9 -13
- data/lib/get_pomo/translation.rb +11 -1
- data/lib/get_pomo/version.rb +1 -1
- data/vendor/mofile.rb +6 -2
- metadata +5 -22
- data/.gitignore +0 -1
- data/.travis.yml +0 -4
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -28
- data/Rakefile +0 -7
- data/Readme.md +0 -47
- data/get_pomo.gemspec +0 -12
- data/spec/files/complex.mo +0 -0
- data/spec/files/empty.mo +0 -0
- data/spec/files/plural.mo +0 -0
- data/spec/files/singular.mo +0 -0
- data/spec/files/singular_2.mo +0 -0
- data/spec/pomo/mo_file_spec.rb +0 -58
- data/spec/pomo/po_file_spec.rb +0 -148
- data/spec/pomo/translation_spec.rb +0 -152
- data/spec/pomo_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cd9dd2c09caf9db6ca69651e9524293555726d6
|
4
|
+
data.tar.gz: 108d14f1f7905c087a53d01e8625594245af9d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 840f9278ea6cec9cef976e187e7d24b44abeb0aec9b80c12218efc6d7ecb4af7fea1a7257ef14c7ecbc3f1f12d230c72d8640035a08a35857abe6f12ddb6475e
|
7
|
+
data.tar.gz: 770b580530ebe517389d9c6b07cf4e417854628010e56b82b4a75dd2ebcc50624b303bfd7c73825ad868ad1d90ab0e2a91ace3b18de47603fd157435d653ebf8
|
data/lib/get_pomo/po_file.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
require 'get_pomo/translation'
|
2
3
|
|
3
4
|
module GetPomo
|
@@ -50,18 +51,18 @@ module GetPomo
|
|
50
51
|
|
51
52
|
msgid_and_msgstr = if translation.plural?
|
52
53
|
msgids =
|
53
|
-
%Q(msgid "#{
|
54
|
-
%Q(msgid_plural "#{
|
54
|
+
%Q(msgid "#{translation.msgid[0]}"\n)+
|
55
|
+
%Q(msgid_plural "#{translation.msgid[1]}"\n)
|
55
56
|
|
56
57
|
msgstrs = []
|
57
58
|
translation.msgstr.each_with_index do |msgstr,index|
|
58
|
-
msgstrs << %Q(msgstr[#{index}] "#{
|
59
|
+
msgstrs << %Q(msgstr[#{index}] "#{msgstr}")
|
59
60
|
end
|
60
61
|
|
61
62
|
msgids + (msgstrs*"\n")
|
62
63
|
else
|
63
|
-
%Q(msgid "#{
|
64
|
-
%Q(msgstr "#{
|
64
|
+
%Q(msgid "#{translation.msgid}"\n)+
|
65
|
+
%Q(msgstr "#{translation.msgstr}")
|
65
66
|
end
|
66
67
|
|
67
68
|
comment + msgctxt + msgid_and_msgstr
|
@@ -70,11 +71,6 @@ module GetPomo
|
|
70
71
|
|
71
72
|
private
|
72
73
|
|
73
|
-
def escape_quotes(txt)
|
74
|
-
txt.gsub /"/, '\"'
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
74
|
#e.g. # fuzzy
|
79
75
|
def comment?(line)
|
80
76
|
line =~ /^\s*#/
|
@@ -105,7 +101,7 @@ module GetPomo
|
|
105
101
|
string = string.strip
|
106
102
|
return if string.empty?
|
107
103
|
raise "not string format: #{string.inspect} on line #{@line_number}" unless string =~ /^['"](.*)['"]$/
|
108
|
-
string_content =
|
104
|
+
string_content = string[1..-2] #remove leading and trailing quotes from content
|
109
105
|
@current_translation.add_text(string_content, :to=>@last_method)
|
110
106
|
end
|
111
107
|
|
@@ -113,7 +109,7 @@ module GetPomo
|
|
113
109
|
return false unless @current_translation
|
114
110
|
@current_translation.complete?
|
115
111
|
end
|
116
|
-
|
112
|
+
|
117
113
|
def store_translation
|
118
114
|
@translations += [@current_translation] if @current_translation.complete?
|
119
115
|
end
|
@@ -123,4 +119,4 @@ module GetPomo
|
|
123
119
|
@current_translation = Translation.new
|
124
120
|
end
|
125
121
|
end
|
126
|
-
end
|
122
|
+
end
|
data/lib/get_pomo/translation.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module GetPomo
|
2
2
|
class Translation
|
3
3
|
FUZZY_REGEX = /^#,\s*fuzzy/
|
4
|
+
OBSOLETE_REGEX = /^#~\s*msgstr/
|
4
5
|
attr_accessor :msgid, :msgstr, :msgctxt, :comment
|
5
6
|
|
6
7
|
def add_text(text,options)
|
@@ -22,13 +23,22 @@ module GetPomo
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def complete?
|
25
|
-
not msgid.nil? and not msgstr.nil?
|
26
|
+
(not msgid.nil? and not msgstr.nil?) or obsolete?
|
26
27
|
end
|
27
28
|
|
28
29
|
def fuzzy?
|
29
30
|
!!(comment =~ FUZZY_REGEX)
|
30
31
|
end
|
31
32
|
|
33
|
+
def obsolete?
|
34
|
+
obs = if !!(comment =~ OBSOLETE_REGEX)
|
35
|
+
#prevent nullpointer in obsolete msgs
|
36
|
+
self.msgid = '' if msgid.nil?
|
37
|
+
self.msgstr = '' if msgstr.nil?
|
38
|
+
end
|
39
|
+
obs
|
40
|
+
end
|
41
|
+
|
32
42
|
def fuzzy=(value)
|
33
43
|
if value and not fuzzy?
|
34
44
|
add_text "\n#, fuzzy", :to=>:comment
|
data/lib/get_pomo/version.rb
CHANGED
data/vendor/mofile.rb
CHANGED
@@ -176,7 +176,11 @@ module GetPomo
|
|
176
176
|
|
177
177
|
def next_prime(seed)
|
178
178
|
require 'mathn'
|
179
|
-
prime =
|
179
|
+
prime = if RUBY_VERSION > "1.9.0"
|
180
|
+
Prime::EratosthenesGenerator.new
|
181
|
+
else
|
182
|
+
Prime.new
|
183
|
+
end
|
180
184
|
while current = prime.succ
|
181
185
|
return current if current > seed
|
182
186
|
end
|
@@ -293,4 +297,4 @@ module GetPomo
|
|
293
297
|
attr_reader :charset, :nplurals, :plural
|
294
298
|
end
|
295
299
|
end
|
296
|
-
end
|
300
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: get_pomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -16,28 +16,11 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
-
- .gitignore
|
20
|
-
- .travis.yml
|
21
|
-
- Gemfile
|
22
|
-
- Gemfile.lock
|
23
|
-
- Rakefile
|
24
|
-
- Readme.md
|
25
|
-
- get_pomo.gemspec
|
26
19
|
- lib/get_pomo.rb
|
27
20
|
- lib/get_pomo/mo_file.rb
|
28
21
|
- lib/get_pomo/po_file.rb
|
29
22
|
- lib/get_pomo/translation.rb
|
30
23
|
- lib/get_pomo/version.rb
|
31
|
-
- spec/files/complex.mo
|
32
|
-
- spec/files/empty.mo
|
33
|
-
- spec/files/plural.mo
|
34
|
-
- spec/files/singular.mo
|
35
|
-
- spec/files/singular_2.mo
|
36
|
-
- spec/pomo/mo_file_spec.rb
|
37
|
-
- spec/pomo/po_file_spec.rb
|
38
|
-
- spec/pomo/translation_spec.rb
|
39
|
-
- spec/pomo_spec.rb
|
40
|
-
- spec/spec_helper.rb
|
41
24
|
- vendor/README.rdoc
|
42
25
|
- vendor/iconv.rb
|
43
26
|
- vendor/mofile.rb
|
@@ -51,17 +34,17 @@ require_paths:
|
|
51
34
|
- lib
|
52
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
36
|
requirements:
|
54
|
-
- -
|
37
|
+
- - ">="
|
55
38
|
- !ruby/object:Gem::Version
|
56
39
|
version: '0'
|
57
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
41
|
requirements:
|
59
|
-
- -
|
42
|
+
- - ">="
|
60
43
|
- !ruby/object:Gem::Version
|
61
44
|
version: '0'
|
62
45
|
requirements: []
|
63
46
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.
|
47
|
+
rubygems_version: 2.2.2
|
65
48
|
signing_key:
|
66
49
|
specification_version: 4
|
67
50
|
summary: 'Ruby/Gettext: A .po and .mo file parser/generator'
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
pkg
|
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
get_pomo (0.6.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
bump (0.3.9)
|
10
|
-
diff-lcs (1.1.3)
|
11
|
-
rake (10.0.3)
|
12
|
-
rspec (2.12.0)
|
13
|
-
rspec-core (~> 2.12.0)
|
14
|
-
rspec-expectations (~> 2.12.0)
|
15
|
-
rspec-mocks (~> 2.12.0)
|
16
|
-
rspec-core (2.12.2)
|
17
|
-
rspec-expectations (2.12.1)
|
18
|
-
diff-lcs (~> 1.1.3)
|
19
|
-
rspec-mocks (2.12.2)
|
20
|
-
|
21
|
-
PLATFORMS
|
22
|
-
ruby
|
23
|
-
|
24
|
-
DEPENDENCIES
|
25
|
-
bump
|
26
|
-
get_pomo!
|
27
|
-
rake
|
28
|
-
rspec (~> 2)
|
data/Rakefile
DELETED
data/Readme.md
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
A simple and extendable .mo and .po file parser/generator.
|
2
|
-
|
3
|
-
Advanteges over original [mo](http://github.com/mutoh/gettext/blob/abf96713327cc4c5d35f0a772f3b75ff4819450c/lib/gettext/mofile.rb) / [po](http://github.com/mutoh/gettext/blob/abf96713327cc4c5d35f0a772f3b75ff4819450c/lib/gettext/poparser.rb)-parser:
|
4
|
-
|
5
|
-
- simple architecture + easy to extend/modify
|
6
|
-
- emtpy msgstr translations are read
|
7
|
-
- comments are included
|
8
|
-
- fuzzy can be set/unset
|
9
|
-
- multiple translations can be combined in a new po file(with comments and fuzzy and ...)
|
10
|
-
- po files can be written from any kind of input
|
11
|
-
- easy mo-file handling/merging
|
12
|
-
- po/mo file handling is identical, if you know one, you know both
|
13
|
-
|
14
|
-
Setup
|
15
|
-
=====
|
16
|
-
sudo gem install get_pomo
|
17
|
-
|
18
|
-
###Static interface
|
19
|
-
#parse po files
|
20
|
-
translations = GetPomo::PoFile.parse(File.read('xxx.po')) + GetPomo::PoFile.parse(File.read('yyy.po'))
|
21
|
-
|
22
|
-
#and use the data...
|
23
|
-
msgids = translations.reject{|t|t.plural? or t.fuzzy?}.map(&:msgid)
|
24
|
-
|
25
|
-
#or write a new po file (unique by msgid)...
|
26
|
-
File.open('xxx.po','w){|f|f.print(GetPomo::PoFile.to_text(translations))}
|
27
|
-
|
28
|
-
|
29
|
-
###Instance interface
|
30
|
-
p = GetPomo::PoFile.new
|
31
|
-
p.add_translations_from_text(File.read('...'))
|
32
|
-
...
|
33
|
-
p.translations
|
34
|
-
p.to_text
|
35
|
-
|
36
|
-
`GetPomo::MoFile` behaves identical.
|
37
|
-
|
38
|
-
TODO
|
39
|
-
====
|
40
|
-
- extracting of version/pluralisation_rule/plurals/translator... (from msgid "")
|
41
|
-
- the vendor/mofile is really complex, maybe it can be refactored (also some parts are not needed)
|
42
|
-
|
43
|
-
Author
|
44
|
-
======
|
45
|
-
[Michael Grosser](http://pragmatig.wordpress.com)
|
46
|
-
grosser.michael@gmail.com
|
47
|
-
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
data/get_pomo.gemspec
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
-
name = "get_pomo"
|
3
|
-
require "#{name}/version"
|
4
|
-
|
5
|
-
Gem::Specification.new name, GetPomo::VERSION do |s|
|
6
|
-
s.summary = "Ruby/Gettext: A .po and .mo file parser/generator"
|
7
|
-
s.authors = ["Michael Grosser"]
|
8
|
-
s.email = "michael@grosser.it"
|
9
|
-
s.homepage = "https://github.com/grosser/#{name}"
|
10
|
-
s.files = `git ls-files`.split("\n")
|
11
|
-
s.license = "MIT"
|
12
|
-
end
|
data/spec/files/complex.mo
DELETED
Binary file
|
data/spec/files/empty.mo
DELETED
Binary file
|
data/spec/files/plural.mo
DELETED
Binary file
|
data/spec/files/singular.mo
DELETED
Binary file
|
data/spec/files/singular_2.mo
DELETED
Binary file
|
data/spec/pomo/mo_file_spec.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'get_pomo/mo_file'
|
4
|
-
|
5
|
-
describe GetPomo::MoFile do
|
6
|
-
it "parses empty mo file" do
|
7
|
-
GetPomo::MoFile.parse(File.read('spec/files/empty.mo')).should == []
|
8
|
-
end
|
9
|
-
|
10
|
-
it "parses empty strings" do
|
11
|
-
GetPomo::MoFile.parse(File.read('spec/files/empty.mo')).should == []
|
12
|
-
end
|
13
|
-
|
14
|
-
it "reads singulars" do
|
15
|
-
t = GetPomo::MoFile.parse(File.read('spec/files/singular.mo'))[0]
|
16
|
-
t.to_hash.should == {:msgid=>'Back',:msgstr=>'Zurück'}
|
17
|
-
end
|
18
|
-
|
19
|
-
it "reads plurals" do
|
20
|
-
t = GetPomo::MoFile.parse(File.read('spec/files/plural.mo'))[0]
|
21
|
-
t.to_hash.should == {:msgid=>['Axis','Axis'],:msgstr=>['Achse','Achsen']}
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'instance methods' do
|
25
|
-
it "combines multiple translations" do
|
26
|
-
m = GetPomo::MoFile.new
|
27
|
-
m.add_translations_from_text(File.read('spec/files/plural.mo'))
|
28
|
-
m.add_translations_from_text(File.read('spec/files/singular.mo'))
|
29
|
-
m.should have(2).translations
|
30
|
-
m.translations[0].msgid.should_not == m.translations[1].msgid
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can be initialized with translations" do
|
34
|
-
m = GetPomo::MoFile.new(:translations=>['x'])
|
35
|
-
m.translations.should == ['x']
|
36
|
-
end
|
37
|
-
|
38
|
-
it "does not generate duplicate translations" do
|
39
|
-
second_version = File.read('spec/files/singular_2.mo')
|
40
|
-
m = GetPomo::MoFile.new
|
41
|
-
m.add_translations_from_text(File.read('spec/files/singular.mo'))
|
42
|
-
m.add_translations_from_text(second_version)
|
43
|
-
m.to_text.should == second_version
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
it "reads metadata" do
|
48
|
-
meta = GetPomo::MoFile.parse(File.read('spec/files/complex.mo')).detect {|t|t.msgid == ''}
|
49
|
-
meta.msgstr.should_not be_empty
|
50
|
-
end
|
51
|
-
|
52
|
-
describe :to_text do
|
53
|
-
it "writes singulars" do
|
54
|
-
text = File.read('spec/files/singular.mo')
|
55
|
-
GetPomo::MoFile.to_text(GetPomo::MoFile.parse(text)).should == text
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/spec/pomo/po_file_spec.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "get_pomo/po_file"
|
3
|
-
|
4
|
-
describe GetPomo::PoFile do
|
5
|
-
describe :parse do
|
6
|
-
it "parses nothing" do
|
7
|
-
GetPomo::PoFile.parse("").should be_empty
|
8
|
-
end
|
9
|
-
|
10
|
-
it "parses a simple msgid and msgstr" do
|
11
|
-
t = GetPomo::PoFile.parse(%Q(msgid "xxx"\nmsgstr "yyy"))
|
12
|
-
t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
|
13
|
-
end
|
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
|
-
|
20
|
-
it "parses a simple msgid and msg with additional whitespace" do
|
21
|
-
t = GetPomo::PoFile.parse(%Q( msgid "xxx" \n msgstr "yyy" ))
|
22
|
-
t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
|
23
|
-
end
|
24
|
-
|
25
|
-
it "parses an empty msgid with text (gettext meta data)" do
|
26
|
-
t = GetPomo::PoFile.parse(%Q(msgid ""\nmsgstr "PLURAL FORMS"))
|
27
|
-
t[0].to_hash.should == {:msgid=>'',:msgstr=>'PLURAL FORMS'}
|
28
|
-
end
|
29
|
-
|
30
|
-
it "parses a multiline msgid/msgstr" do
|
31
|
-
t = GetPomo::PoFile.parse(%Q(msgid "xxx"\n"aaa"\n\n\nmsgstr ""\n"bbb"))
|
32
|
-
t[0].to_hash.should == {:msgid=>'xxxaaa',:msgstr=>'bbb'}
|
33
|
-
end
|
34
|
-
|
35
|
-
it "parses simple comments" do
|
36
|
-
t = GetPomo::PoFile.parse(%Q(#test\nmsgid "xxx"\nmsgstr "yyy"))
|
37
|
-
t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"#test\n"}
|
38
|
-
end
|
39
|
-
|
40
|
-
it "parses comments above msgstr" do
|
41
|
-
t = GetPomo::PoFile.parse(%Q(#test\nmsgid "xxx"\n#another\nmsgstr "yyy"))
|
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'}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "instance interface" do
|
52
|
-
it "adds two different translations" do
|
53
|
-
p = GetPomo::PoFile.new
|
54
|
-
p.add_translations_from_text(%Q(msgid "xxx"\nmsgstr "yyy"))
|
55
|
-
p.add_translations_from_text(%Q(msgid "aaa"\nmsgstr "yyy"))
|
56
|
-
p.translations[1].to_hash.should == {:msgid=>'aaa',:msgstr=>'yyy'}
|
57
|
-
end
|
58
|
-
|
59
|
-
it "can be initialized with translations" do
|
60
|
-
p = GetPomo::PoFile.new(:translations=>['xxx'])
|
61
|
-
p.translations[0].should == 'xxx'
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can be converted to text" do
|
65
|
-
text = %Q(msgid "xxx"\nmsgstr "aaa")
|
66
|
-
p = GetPomo::PoFile.new
|
67
|
-
p.add_translations_from_text(text)
|
68
|
-
p.to_text.should == text
|
69
|
-
end
|
70
|
-
|
71
|
-
it "keeps uniqueness when converting to_text" do
|
72
|
-
text = %Q(msgid "xxx"\nmsgstr "aaa")
|
73
|
-
p = GetPomo::PoFile.new
|
74
|
-
p.add_translations_from_text(%Q(msgid "xxx"\nmsgstr "yyy"))
|
75
|
-
p.add_translations_from_text(text)
|
76
|
-
p.to_text.should == text
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it "adds plural translations" do
|
81
|
-
t = GetPomo::PoFile.parse(%Q(msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "one"\nmsgstr[1] "many"))
|
82
|
-
t[0].to_hash.should == {:msgid=>['singular','plural'],:msgstr=>['one','many']}
|
83
|
-
end
|
84
|
-
|
85
|
-
it "does not fail on empty string" do
|
86
|
-
GetPomo::PoFile.parse(%Q(\n\n\n\n\n))
|
87
|
-
end
|
88
|
-
|
89
|
-
it "shows line number for invalid strings" do
|
90
|
-
begin
|
91
|
-
GetPomo::PoFile.parse(%Q(\n\n\n\n\nmsgstr "))
|
92
|
-
flunk
|
93
|
-
rescue Exception => e
|
94
|
-
e.to_s.should =~ /line 5/
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe :to_text do
|
99
|
-
it "is empty when not translations where added" do
|
100
|
-
GetPomo::PoFile.to_text([]).should == ""
|
101
|
-
end
|
102
|
-
|
103
|
-
it "preserves simple syntax" do
|
104
|
-
text = %Q(msgid "x"\nmsgstr "y")
|
105
|
-
GetPomo::PoFile.to_text(GetPomo::PoFile.parse(text)).should == text
|
106
|
-
end
|
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
|
-
|
129
|
-
it "adds comments" do
|
130
|
-
t = GetPomo::Translation.new
|
131
|
-
t.msgid = 'a'
|
132
|
-
t.msgstr = 'b'
|
133
|
-
t.add_text("#c\n",:to=>:comment)
|
134
|
-
t.add_text("#d\n",:to=>:comment)
|
135
|
-
GetPomo::PoFile.to_text([t]).should == %Q(#c\n#d\nmsgid "a"\nmsgstr "b")
|
136
|
-
end
|
137
|
-
|
138
|
-
it "uses plural notation" do
|
139
|
-
text = %Q(#awesome\nmsgid "one"\nmsgid_plural "many"\nmsgstr[0] "1"\nmsgstr[1] "n")
|
140
|
-
GetPomo::PoFile.to_text(GetPomo::PoFile.parse(text)).should == text
|
141
|
-
end
|
142
|
-
|
143
|
-
it "only uses the latest of identicals msgids" do
|
144
|
-
text = %Q(msgid "one"\nmsgstr "1"\nmsgid "one"\nmsgstr "001")
|
145
|
-
GetPomo::PoFile.to_text(GetPomo::PoFile.parse(text)).should == %Q(msgid "one"\nmsgstr "001")
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'get_pomo/translation'
|
3
|
-
|
4
|
-
describe GetPomo::Translation do
|
5
|
-
describe :complete? do
|
6
|
-
it { should_not be_complete }
|
7
|
-
|
8
|
-
it "is complete if it has a msgid and a msgstr" do
|
9
|
-
subject.msgid="x"
|
10
|
-
subject.msgstr = "y"
|
11
|
-
should be_complete
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is not complete if it has an complete msgid" do
|
15
|
-
subject.msgid=""
|
16
|
-
should_not be_complete
|
17
|
-
end
|
18
|
-
|
19
|
-
it "is not complete if it has a nil msgstr" do
|
20
|
-
subject.msgid="x"
|
21
|
-
should_not be_complete
|
22
|
-
end
|
23
|
-
|
24
|
-
it "is complete if it has an complete msgstr" do
|
25
|
-
subject.msgid = "x"
|
26
|
-
subject.msgstr = ""
|
27
|
-
should be_complete
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe :add_text do
|
32
|
-
it "adds a simple msgid" do
|
33
|
-
subject.add_text("x",:to=>:msgid)
|
34
|
-
subject.msgid.should == "x"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "converts msgid to plural when msgid_plural is added" do
|
38
|
-
subject.add_text("x",:to=>:msgid)
|
39
|
-
subject.add_text("y",:to=>:msgid_plural)
|
40
|
-
subject.msgid.should == ["x",'y']
|
41
|
-
end
|
42
|
-
|
43
|
-
it "can add additional text to msgid plurals" do
|
44
|
-
subject.add_text("y",:to=>:msgid_plural)
|
45
|
-
subject.add_text("a",:to=>:msgid_plural)
|
46
|
-
subject.msgid.should == [nil,'ya']
|
47
|
-
end
|
48
|
-
|
49
|
-
it "can add plural msggstr" do
|
50
|
-
subject.add_text("x",:to=>'msgstr[0]')
|
51
|
-
subject.msgstr.should == ['x']
|
52
|
-
end
|
53
|
-
|
54
|
-
it "can add multiple plural msggstr" do
|
55
|
-
subject.add_text("x",:to=>'msgstr[0]')
|
56
|
-
subject.add_text("a",:to=>'msgstr[1]')
|
57
|
-
subject.add_text("y",:to=>'msgstr[1]')
|
58
|
-
subject.msgstr.should == ['x','ay']
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe :plural? do
|
63
|
-
it{should_not be_plural}
|
64
|
-
|
65
|
-
it "is plural if msgid is plural" do
|
66
|
-
subject.add_text("x",:to=>:msgid_plural)
|
67
|
-
should be_plural
|
68
|
-
end
|
69
|
-
|
70
|
-
it "is plural if msgstr is plural" do
|
71
|
-
subject.add_text("x",:to=>"msgstr[0]")
|
72
|
-
should be_plural
|
73
|
-
end
|
74
|
-
|
75
|
-
it "is not plural if simple strings where added" do
|
76
|
-
subject.msgid = "a"
|
77
|
-
subject.msgstr = "a"
|
78
|
-
should_not be_plural
|
79
|
-
end
|
80
|
-
end
|
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
|
-
|
116
|
-
describe :fuzzy? do
|
117
|
-
it{should_not be_fuzzy}
|
118
|
-
|
119
|
-
it "is fuzzy if a fuzzy comment was added" do
|
120
|
-
subject.add_text("#, fuzzy",:to=>:comment)
|
121
|
-
should be_fuzzy
|
122
|
-
end
|
123
|
-
|
124
|
-
it "can be made fuzzy by using fuzzy=" do
|
125
|
-
subject.fuzzy = true
|
126
|
-
should be_fuzzy
|
127
|
-
end
|
128
|
-
|
129
|
-
it "can be made unfuzzy by using fuzzy=" do
|
130
|
-
subject.fuzzy = false
|
131
|
-
should_not be_fuzzy
|
132
|
-
end
|
133
|
-
|
134
|
-
it "changes comment when made fuzzy through fuzzy=" do
|
135
|
-
subject.comment = "# hello"
|
136
|
-
subject.fuzzy = true
|
137
|
-
subject.comment.should == "# hello\n#, fuzzy"
|
138
|
-
end
|
139
|
-
|
140
|
-
it "changes empty comment when made fuzzy through fuzzy=" do
|
141
|
-
subject.fuzzy = true
|
142
|
-
subject.comment.should == "\n#, fuzzy"
|
143
|
-
end
|
144
|
-
|
145
|
-
it "preserves comments when making fuzzy/unfuzzy" do
|
146
|
-
subject.comment = "hello"
|
147
|
-
subject.fuzzy = true
|
148
|
-
subject.fuzzy = false
|
149
|
-
subject.comment.should == "hello"
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
data/spec/pomo_spec.rb
DELETED