get_pomo 0.6.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.
- data/.gitignore +1 -0
- data/README.markdown +47 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/get_pomo.gemspec +66 -0
- data/lib/get_pomo/mo_file.rb +62 -0
- data/lib/get_pomo/po_file.rb +111 -0
- data/lib/get_pomo/translation.rb +44 -0
- data/lib/get_pomo.rb +12 -0
- data/prototype_treetop/po.treetop +25 -0
- data/prototype_treetop/test.rb +6 -0
- 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 +58 -0
- data/spec/pomo/po_file_spec.rb +117 -0
- data/spec/pomo/translation_spec.rb +119 -0
- data/spec/pomo_spec.rb +7 -0
- data/spec/spec_helper.rb +10 -0
- data/vendor/README.rdoc +236 -0
- data/vendor/iconv.rb +107 -0
- data/vendor/mofile.rb +296 -0
- metadata +82 -0
@@ -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
data/spec/spec_helper.rb
ADDED
data/vendor/README.rdoc
ADDED
@@ -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>
|
data/vendor/iconv.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
=begin
|
2
|
+
iconv.rb - Pseudo Iconv class. Supports Iconv.iconv, Iconv.conv.
|
3
|
+
|
4
|
+
For Matz Ruby:
|
5
|
+
If you don't have iconv but glib2, this library uses glib2 iconv functions.
|
6
|
+
|
7
|
+
For JRuby:
|
8
|
+
Use Java String class to convert strings.
|
9
|
+
|
10
|
+
Copyright (C) 2004-2007 Masao Mutoh
|
11
|
+
|
12
|
+
You may redistribute it and/or modify it under the same
|
13
|
+
license terms as Ruby.
|
14
|
+
|
15
|
+
$Id: iconv.rb,v 1.6 2007/11/08 14:21:22 mutoh Exp $
|
16
|
+
=end
|
17
|
+
|
18
|
+
#Modifications
|
19
|
+
#wrapped inside FastGettext namespace to reduce conflic
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'iconv'
|
23
|
+
rescue LoadError
|
24
|
+
# Provides Iconv.iconv which normally is provided through Ruby/GLib(1) functions.
|
25
|
+
# This library is required for 'gettext'.
|
26
|
+
# If you require 'gettext/iconv', it tries to call Ruby/GLib function
|
27
|
+
# when it doesn't find original Iconv class(iconv.so) it adds a pseudo class.
|
28
|
+
#
|
29
|
+
# One-click Ruby Installer for Win32 hadn’t had iconv and there hadn’t been a way to install iconv.so itself for Win32.
|
30
|
+
# And JRuby hadn’t had Iconv.
|
31
|
+
# I’ve not checked them currently, but if they’ve supported iconv now, we don’t need this anymore...
|
32
|
+
#
|
33
|
+
# (1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
|
34
|
+
# You can get binaries for Win32(One-Click Ruby Installer).
|
35
|
+
# <URL: http://ruby-gnome2.sourceforge.jp/>
|
36
|
+
module GetPomo
|
37
|
+
class Iconv2
|
38
|
+
module Failure; end
|
39
|
+
class InvalidEncoding < ArgumentError; include Failure; end
|
40
|
+
class IllegalSequence < ArgumentError; include Failure; end
|
41
|
+
class InvalidCharacter < ArgumentError; include Failure; end
|
42
|
+
|
43
|
+
if RUBY_PLATFORM =~ /java/
|
44
|
+
def self.conv(to, from, str)
|
45
|
+
raise InvalidCharacter, "the 3rd argument is nil" unless str
|
46
|
+
begin
|
47
|
+
str = java.lang.String.new(str.unpack("C*").to_java(:byte), from)
|
48
|
+
str.getBytes(to).to_ary.pack("C*")
|
49
|
+
rescue java.io.UnsupportedEncodingException
|
50
|
+
raise InvalidEncoding
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
begin
|
55
|
+
require 'glib2'
|
56
|
+
|
57
|
+
def self.check_glib_version?(major, minor, micro) # :nodoc:
|
58
|
+
(GLib::BINDING_VERSION[0] > major ||
|
59
|
+
(GLib::BINDING_VERSION[0] == major &&
|
60
|
+
GLib::BINDING_VERSION[1] > minor) ||
|
61
|
+
(GLib::BINDING_VERSION[0] == major &&
|
62
|
+
GLib::BINDING_VERSION[1] == minor &&
|
63
|
+
GLib::BINDING_VERSION[2] >= micro))
|
64
|
+
end
|
65
|
+
|
66
|
+
if check_glib_version?(0, 11, 0)
|
67
|
+
# This is a function equivalent of Iconv.iconv.
|
68
|
+
# * to: encoding name for destination
|
69
|
+
# * from: encoding name for source
|
70
|
+
# * str: strings to be converted
|
71
|
+
# * Returns: Returns an Array of converted strings.
|
72
|
+
def self.conv(to, from, str)
|
73
|
+
begin
|
74
|
+
GLib.convert(str, to, from)
|
75
|
+
rescue GLib::ConvertError => e
|
76
|
+
case e.code
|
77
|
+
when GLib::ConvertError::NO_CONVERSION
|
78
|
+
raise InvalidEncoding.new(str)
|
79
|
+
when GLib::ConvertError::ILLEGAL_SEQUENCE
|
80
|
+
raise IllegalSequence.new(str)
|
81
|
+
else
|
82
|
+
raise InvalidCharacter.new(str)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
else
|
87
|
+
def self.conv(to, from, str) # :nodoc:
|
88
|
+
begin
|
89
|
+
GLib.convert(str, to, from)
|
90
|
+
rescue
|
91
|
+
raise IllegalSequence.new(str)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rescue LoadError
|
96
|
+
def self.conv(to, from, str) # :nodoc:
|
97
|
+
warn "Iconv was not found." if $DEBUG
|
98
|
+
str
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def self.iconv(to, from, str)
|
103
|
+
conv(to, from, str).split(//)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|