grosser-get_pomo 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ include GetPomo
4
+ describe GetPomo::PoFile do
5
+ describe :parse do
6
+ it "parses nothing" do
7
+ PoFile.parse("").should be_empty
8
+ end
9
+
10
+ it "parses a simple msgid and msgstr" do
11
+ t = PoFile.parse(%Q(msgid "xxx"\nmsgstr "yyy"))
12
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
13
+ end
14
+
15
+ it "parses a simple msgid and msg with additional whitespace" do
16
+ t = PoFile.parse(%Q( msgid "xxx" \n msgstr "yyy" ))
17
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy'}
18
+ end
19
+
20
+ it "parses an empty msgid with text (gettext meta data)" do
21
+ t = PoFile.parse(%Q(msgid ""\nmsgstr "PLURAL FORMS"))
22
+ t[0].to_hash.should == {:msgid=>'',:msgstr=>'PLURAL FORMS'}
23
+ end
24
+
25
+ it "parses a multiline msgid/msgstr" do
26
+ t = PoFile.parse(%Q(msgid "xxx"\n"aaa"\n\n\nmsgstr ""\n"bbb"))
27
+ t[0].to_hash.should == {:msgid=>'xxxaaa',:msgstr=>'bbb'}
28
+ end
29
+
30
+ it "parses simple comments" do
31
+ t = PoFile.parse(%Q(#test\nmsgid "xxx"\nmsgstr "yyy"))
32
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"test\n"}
33
+ end
34
+
35
+ it "parses comments above msgstr" do
36
+ t = PoFile.parse(%Q(#test\nmsgid "xxx"\n#another\nmsgstr "yyy"))
37
+ t[0].to_hash.should == {:msgid=>'xxx',:msgstr=>'yyy',:comment=>"test\nanother\n"}
38
+ end
39
+ end
40
+
41
+ describe "instance interface" do
42
+ it "adds two different translations" do
43
+ p = PoFile.new
44
+ p.add_translations_from_text(%Q(msgid "xxx"\nmsgstr "yyy"))
45
+ p.add_translations_from_text(%Q(msgid "aaa"\nmsgstr "yyy"))
46
+ p.translations[1].to_hash.should == {:msgid=>'aaa',:msgstr=>'yyy'}
47
+ end
48
+
49
+ it "can be initialized with translations" do
50
+ p = PoFile.new(:translations=>['xxx'])
51
+ p.translations[0].should == 'xxx'
52
+ end
53
+
54
+ it "can be converted to text" do
55
+ text = %Q(msgid "xxx"\nmsgstr "aaa")
56
+ p = PoFile.new
57
+ p.add_translations_from_text(text)
58
+ p.to_text.should == text
59
+ end
60
+
61
+ it "keeps uniqueness when converting to_text" do
62
+ text = %Q(msgid "xxx"\nmsgstr "aaa")
63
+ p = PoFile.new
64
+ p.add_translations_from_text(%Q(msgid "xxx"\nmsgstr "yyy"))
65
+ p.add_translations_from_text(text)
66
+ p.to_text.should == text
67
+ end
68
+ end
69
+
70
+ it "adds plural translations" do
71
+ t = PoFile.parse(%Q(msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "one"\nmsgstr[1] "many"))
72
+ t[0].to_hash.should == {:msgid=>['singular','plural'],:msgstr=>['one','many']}
73
+ end
74
+
75
+ it "does not fail on empty string" do
76
+ PoFile.parse(%Q(\n\n\n\n\n))
77
+ end
78
+
79
+ it "shows line number for invalid strings" do
80
+ begin
81
+ PoFile.parse(%Q(\n\n\n\n\nmsgstr "))
82
+ flunk
83
+ rescue Exception => e
84
+ e.to_s.should =~ /line 5/
85
+ end
86
+ end
87
+
88
+ describe :to_text do
89
+ it "is empty when not translations where added" do
90
+ PoFile.to_text([]).should == ""
91
+ end
92
+
93
+ it "preserves simple syntax" do
94
+ text = %Q(msgid "x"\nmsgstr "y")
95
+ PoFile.to_text(PoFile.parse(text)).should == text
96
+ end
97
+
98
+ it "adds comments" do
99
+ t = GetPomo::Translation.new
100
+ t.msgid = 'a'
101
+ t.msgstr = 'b'
102
+ t.add_text("c\n",:to=>:comment)
103
+ t.add_text("d\n",:to=>:comment)
104
+ PoFile.to_text([t]).should == %Q(#c\n#d\nmsgid "a"\nmsgstr "b")
105
+ end
106
+
107
+ it "uses plural notation" do
108
+ text = %Q(#awesome\nmsgid "one"\nmsgid_plural "many"\nmsgstr[0] "1"\nmsgstr[1] "n")
109
+ PoFile.to_text(PoFile.parse(text)).should == text
110
+ end
111
+
112
+ it "only uses the latest of identicals msgids" do
113
+ text = %Q(msgid "one"\nmsgstr "1"\nmsgid "one"\nmsgstr "001")
114
+ PoFile.to_text(PoFile.parse(text)).should == %Q(msgid "one"\nmsgstr "001")
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,119 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+
3
+ require 'get_pomo/translation'
4
+
5
+ describe GetPomo::Translation do
6
+ describe :complete? do
7
+ it{should_not be_complete}
8
+
9
+ it "is complete if it has a msgid and a msgstr" do
10
+ subject.msgid="x"
11
+ subject.msgstr = "y"
12
+ should be_complete
13
+ end
14
+
15
+ it "is not complete if it has an complete msgid" do
16
+ subject.msgid=""
17
+ should_not be_complete
18
+ end
19
+
20
+ it "is not complete if it has a nil msgstr" do
21
+ subject.msgid="x"
22
+ should_not be_complete
23
+ end
24
+
25
+ it "is complete if it has an complete msgstr" do
26
+ subject.msgid = "x"
27
+ subject.msgstr = ""
28
+ should be_complete
29
+ end
30
+ end
31
+
32
+ describe :add_text do
33
+ it "adds a simple msgid" do
34
+ subject.add_text("x",:to=>:msgid)
35
+ subject.msgid.should == "x"
36
+ end
37
+
38
+ it "converts msgid to plural when msgid_plural is added" do
39
+ subject.add_text("x",:to=>:msgid)
40
+ subject.add_text("y",:to=>:msgid_plural)
41
+ subject.msgid.should == ["x",'y']
42
+ end
43
+
44
+ it "can add additional text to msgid plurals" do
45
+ subject.add_text("y",:to=>:msgid_plural)
46
+ subject.add_text("a",:to=>:msgid_plural)
47
+ subject.msgid.should == [nil,'ya']
48
+ end
49
+
50
+ it "can add plural msggstr" do
51
+ subject.add_text("x",:to=>'msgstr[0]')
52
+ subject.msgstr.should == ['x']
53
+ end
54
+
55
+ it "can add multiple plural msggstr" do
56
+ subject.add_text("x",:to=>'msgstr[0]')
57
+ subject.add_text("a",:to=>'msgstr[1]')
58
+ subject.add_text("y",:to=>'msgstr[1]')
59
+ subject.msgstr.should == ['x','ay']
60
+ end
61
+ end
62
+
63
+ describe :plural? do
64
+ it{should_not be_plural}
65
+
66
+ it "is plural if msgid is plural" do
67
+ subject.add_text("x",:to=>:msgid_plural)
68
+ should be_plural
69
+ end
70
+
71
+ it "is plural if msgstr is plural" do
72
+ subject.add_text("x",:to=>"msgstr[0]")
73
+ should be_plural
74
+ end
75
+
76
+ it "is not plural if simple strings where added" do
77
+ subject.msgid = "a"
78
+ subject.msgstr = "a"
79
+ should_not be_plural
80
+ end
81
+ end
82
+
83
+ describe :fuzzy? do
84
+ it{should_not be_fuzzy}
85
+
86
+ it "is fuzzy if a fuzzy comment was added" do
87
+ subject.add_text("fuzzy",:to=>:comment)
88
+ should be_fuzzy
89
+ end
90
+
91
+ it "can be made fuzzy by using fuzzy=" do
92
+ subject.fuzzy = true
93
+ should be_fuzzy
94
+ end
95
+
96
+ it "can be made unfuzzy by using fuzzy=" do
97
+ subject.fuzzy = false
98
+ should_not be_fuzzy
99
+ end
100
+
101
+ it "changes comment when made fuzzy through fuzzy=" do
102
+ subject.comment = "hello"
103
+ subject.fuzzy = true
104
+ subject.comment.should == "hello\nfuzzy"
105
+ end
106
+
107
+ it "changes empty comment when made fuzzy through fuzzy=" do
108
+ subject.fuzzy = true
109
+ subject.comment.should == "\nfuzzy"
110
+ end
111
+
112
+ it "preserves comments when making fuzzy/unfuzzy" do
113
+ subject.comment = "hello"
114
+ subject.fuzzy = true
115
+ subject.fuzzy = false
116
+ subject.comment.should == "hello"
117
+ end
118
+ end
119
+ end
data/spec/pomo_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe GetPomo do
4
+ it "has a VERSION" do
5
+ GetPomo::VERSION.should =~ /^\d+\.\d+\.\d+$/
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # ---- requirements
2
+ $LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
3
+ require 'get_pomo'
4
+
5
+ # ---- Helpers
6
+ def pending_it(text,&block)
7
+ it text do
8
+ pending(&block)
9
+ end
10
+ end
@@ -0,0 +1,236 @@
1
+ = Ruby-GetText-Package
2
+
3
+ Ruby-GetText-Package is a Localization(L10n) library and tool
4
+ which is modeled after the GNU gettext package.
5
+
6
+ This library translates original messages to localized
7
+ messages using client-side locale information(environment
8
+ variable or CGI variable).
9
+
10
+ The tools for developers support creating, useing, and modifying
11
+ localized message files(message catalogs).
12
+
13
+ ((*Rails*))
14
+ Rails support has been removed.
15
+ Rails / ActiveRecord specific code now lives in gettext_rails and gettext_activerecord.
16
+
17
+ == Website
18
+ * homepage[http://www.yotabanana.com/hiki/ruby-gettext.html]
19
+ * on rubyforge[http://gettext/rubyforge.org/]
20
+ * on github[http://github.com/gettext/]
21
+
22
+ == Features
23
+ * Simple APIs(similar to GNU gettext)
24
+
25
+ * rgettext creates po-files from
26
+ * ruby scripts
27
+ * glade-2 XML file(.glade)
28
+ * ERB file(.rhtml, .erb)
29
+ * Anything (with your own parsers)
30
+ * The po-files are compatible to GNU gettext.
31
+
32
+ * rmsgfmt creates a mo-file from a po-file.
33
+ The mo-file is compatible to GNU gettext(msgfmt).
34
+
35
+ * textdomain's scope is adapt to ruby class/module mechanism.
36
+ * A class/module can have plural textdomains.
37
+ * a message is looked up in its class/module and ancestors.
38
+
39
+ * CGI support (gettext/cgi)
40
+ * Locale is retrieved from client informations
41
+ (HTTP_ACCEPT_LANGUAGE, HTTP_ACCEPT_CHARSET, QUERY_STRING(lang), Cookies(lang)).
42
+
43
+ * String%() is extended to use named argument such as <tt>%{foo}" %{:foo => 1}</tt>.
44
+ Notes that Ruby-1.9.x supports this format by itself.
45
+
46
+ == Requirements
47
+ * {Ruby 1.8.3 or later}[http://www.ruby-lang.org]
48
+ * {Rubygems}[http://www.rubygems.org/]
49
+ * {locale gem}[http://rubyforge.org/projects/locale/]
50
+ * $ gem install locale
51
+ * (for development only)
52
+ * {GNU gettext 0.10.35 or later}[http://www.gnu.org/software/gettext/gettext.html]
53
+ * {Racc-1.4.3 or later}[http://www.ruby-lang.org/raa/list.rhtml?name=racc]
54
+ * (for compiling src/rmsgfmt.ry only)
55
+
56
+ == Install
57
+ * Uninstall old gettext if exists.
58
+ (sudo/su on POSIX system)
59
+ gem uninstall gettext
60
+
61
+ * gem
62
+ #from github (edge/unstable)
63
+ (sudo/su on POSIX system)
64
+ gem install locale
65
+ gem install mutoh-gettext -s http://gems.github.com/
66
+
67
+ #from rubyforge (stable)
68
+ (sudo/su on POSIX system)
69
+ gem install locale
70
+ gem install gettext
71
+
72
+ * download tar-ball
73
+ # De-Compress archive and enter its top directory.
74
+ (sudo/su on POSIX system)
75
+ ruby setup.rb
76
+
77
+ You can also install files in your favorite directory by
78
+ supplying setup.rb some options. Try <tt>ruby setup.rb --help</tt>.
79
+
80
+ == Usage
81
+ ===Translation
82
+ - _: Basic translation method
83
+ Translates the message.
84
+ _("Hello")
85
+
86
+ The gettext methods comes in 3 combinable flavors
87
+ - n: Pluralized
88
+ Returns singular or plural form, depending on how many you have.
89
+ n_("Apple", "%{num} Apples", 3)
90
+ n_(["Apple", "%{num} Apples"], 3)
91
+
92
+ - p: context aware
93
+ A context is a prefix to your translation, usefull when one word has different meanings, depending on its context.
94
+ p_("Printer","Open") <=> p_("File","Open")
95
+ is the same as s_("Printer|Open") <=> s_("File|Open")
96
+
97
+ - s: without context
98
+ If a translation could not be found, return the msgid without context.
99
+ s_("Printer|Open") => "Öffnen" #translation found
100
+ s_("Printer|Open") => "Open" #translation not found
101
+
102
+ - combinations
103
+ np_("Fruit", "Apple", "%{num} Apples", 3)
104
+ ns_("Fruit|Apple","%{num} Apples", 3)
105
+
106
+ np_(["Fruit","Apple","%{num} Apples"], 3)
107
+ ns_(["Fruit|Apple","%{num} Apples"], 3)
108
+
109
+ - N_, Nn_: Makes dynamic translation messages readable for the gettext parser.
110
+ <tt>_(fruit)</tt> cannot be understood by the gettext parser. To help the parser find all your translations,
111
+ you can add <tt>fruit = N_("Apple")</tt> which does not translate, but tells the parser: "Apple" needs translation.
112
+
113
+ fruit = N_("Apple") # same as fruit = "Apple"
114
+ _(fruit) # does a normal translation
115
+
116
+ fruits = Nn_("Apple", "%{num} Apples")
117
+ n_(fruits, 3)
118
+
119
+ === Locale / Domain
120
+ GetText stores the locale your are using
121
+ GetText.locale = "en_US" # translate into english from now on
122
+ GetText.locale # => en_US
123
+ Or
124
+ include GetText
125
+ set_locale "en_US"
126
+
127
+ Each locale can have different sets of translations (text domains) (e.g. Financial terms + Human-resource terms)
128
+ GetText.bindtextdomain('financial')
129
+ Or
130
+ include GetText
131
+ bindtextdomain('financial')
132
+
133
+ For more details and options, have a look at the samples folder or
134
+ consult the tutorial[http://www.yotabanana.com/hiki/ruby-gettext-howto.html].
135
+
136
+
137
+ == License
138
+ This program is licenced under the same licence as Ruby.
139
+ (See the file 'COPYING'.)
140
+
141
+ * mofile.rb
142
+ * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
143
+ * Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
144
+
145
+ * gettext.rb
146
+ * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
147
+ * Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
148
+
149
+ * rgettext
150
+ * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
151
+ * Copyright (C) 2001,2002 Yasushi Shoji <yashi at atmark-techno.com>
152
+
153
+ * setup.rb
154
+ * Copyright (C) 2000-2005 Minero Aoki <aamine at loveruby.net>
155
+ * This file is released under LGPL. See the top of the install.rb.
156
+
157
+ * Others
158
+ * Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
159
+
160
+
161
+ == Translators
162
+ * Bosnian(bs) - Sanjin Sehic <saserr at gmail.com>
163
+ * Bulgarian(bg) - Sava Chankov <sava.chankov at gmail.com>
164
+ * Catalan(ca) - Ramon Salvadó <rsalvado at gnuine.com>
165
+ * Chinese(Simplified)(zh_CN)
166
+ * Yang Bob <bob.yang.dev at gmail.com> (current)
167
+ * Yingfeng <blogyingfeng at gmail.com>
168
+ * Chinese(Traditional)(zh_TW)
169
+ * Yang Bob <bob.yang.dev at gmail.com> (current)
170
+ * LIN CHUNG-YI <xmarsh at gmail.com>
171
+ * Croatian(hr) - Sanjin Sehic <saserr at gmail.com>
172
+ * Czech(cs) - Karel Miarka <kajism at yahoo.com>
173
+ * Dutch(nl) - Menno Jonkers <ruby-gettext at jonkers.com>
174
+ * Esperanto(eo) - Malte Milatz <malte at gmx-topmail.de>
175
+ * Estonian(et) - Erkki Eilonen <erkki at itech.ee>
176
+ * French(fr)
177
+ * Vincent Isambart <vincent.isambart at gmail.com> (current)
178
+ * David Sulc <davidsulc at gmail.com>
179
+ * Laurent Sansonetti <laurent.sansonetti at gmail.com>
180
+ * German(de)
181
+ * Patrick Lenz <patrick at limited-overload.de> (current)
182
+ * Detlef Reichl <detlef.reichl at gmx.org>
183
+ * Sven Herzberg <herzi at abi02.de>
184
+ * Sascha Ebach <se at digitale-wertschoepfung.de>
185
+ * Greek(el) - Vassilis Rizopoulos <damphyr at gmx.net>
186
+ * Hungarian(hu) - Tamás Tompa <tompata at gmail.com>
187
+ * Italian(it)
188
+ * Marco Lazzeri <marco.lazzeri at gmail.com>
189
+ * Gabriele Renzi <surrender_it at yahoo.it>
190
+ * Japanese(ja) - Masao Mutoh <mutoh at highway.ne.jp>
191
+ * Korean(ko) - Gyoung-Yoon Noh <nohmad at gmail.com>
192
+ * Latvian(lv) - Aivars Akots <aivars.akots at gmail.com>
193
+ * Norwegian(nb) - Runar Ingebrigtsen <runar at mopo.no>
194
+ * Portuguese(Brazil)(pt_BR)
195
+ * Antonio S. de A. Terceiro <terceiro at softwarelivre.org> (current)
196
+ * Joao Pedrosa <joaopedrosa at gmail.com>
197
+ * Russian(ru) - Yuri Kozlov <kozlov.y at gmail.com>
198
+ * Serbian(sr) - Slobodan Paunović" <slobodan.paunovic at gmail.com>
199
+ * Spanish(es)
200
+ * David Espada <davinci at escomposlinux.org> (current)
201
+ * David Moreno Garza <damog at damog.net>
202
+ * Swedish(sv) - Nikolai Weibull <mailing-lists.ruby-talk at rawuncut.elitemail.org>
203
+ * Ukrainian(ua) - Alex Rootoff <rootoff at pisem.net>
204
+ * Vietnamese(vi) - Ngoc Dao Thanh <ngocdaothanh at gmail.com>
205
+
206
+ == Status of translations
207
+ * Bosnian(bs) - 1.90.0 (old)
208
+ * Bulgarian(bg) - 2.0.0pre1 (new)
209
+ * Catalan(ca) - 2.0.0pre1
210
+ * Croatian(hr) - 1.90.0 (old)
211
+ * Chinese(zh_CN) - 2.0.0pre1
212
+ * Chinese(zh_TW) - 2.0.0pre1
213
+ * Czech(cs) - 1.9.0 (old)
214
+ * Dutch(nl) - 1.90.0 (old)
215
+ * English(default) - 1.90.0 (old)
216
+ * Esperanto(eo) - 2.0.0pre1
217
+ * Estonian(et) - 2.0.0pre1
218
+ * French(fr) - 2.0.0pre1
219
+ * German(de) - 2.0.0pre1
220
+ * Greek(el) - 2.0.0pre1
221
+ * Hungarian(hu) - 2.0.0pre1
222
+ * Italian(it) - 1.6.0 (old)
223
+ * Japanese(ja) - 2.0.0pre1
224
+ * Korean(ko) - 1.9.0 (old)
225
+ * Latvian(lv) - 2.0.0pre1 (new)
226
+ * Norwegian(nb) - 2.0.0pre1
227
+ * Portuguese(Brazil)(pt_BR) - 2.0.0pre1
228
+ * Russian(ru) - 2.0.0pre1
229
+ * Serbian(sr) - 1.91.0 (old)
230
+ * Spanish(es) - 2.0.0pre1
231
+ * Swedish(sv) - 0.8.0 (too much old)
232
+ * Ukrainian(ua) - 2.0.0pre1
233
+ * Vietnamese(vi) - 2.0.0pre1
234
+
235
+ == Maintainer
236
+ Masao Mutoh <mutoh at highway.ne.jp>