grosser-fast_gettext 0.2.0 → 0.2.1
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/VERSION.yml +1 -1
- data/vendor/README.rdoc +236 -0
- data/vendor/iconv.rb +99 -0
- data/vendor/mofile.rb +290 -0
- data/vendor/string.rb +35 -0
- metadata +7 -3
data/VERSION.yml
CHANGED
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,99 @@
|
|
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
|
+
begin
|
19
|
+
require 'iconv.so'
|
20
|
+
rescue LoadError
|
21
|
+
# Pseudo Iconv class
|
22
|
+
#
|
23
|
+
# Provides Iconv.iconv which uses Ruby/GLib(1) functions. This library also required from 'gettext'.
|
24
|
+
# If you require 'gettext/iconv', Iconv.iconv try to call Ruby/GLib function
|
25
|
+
# when it doesn't find original Iconv class(iconv.so).
|
26
|
+
#
|
27
|
+
# (1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
|
28
|
+
# You can get binaries for Win32(One-Click Ruby Installer).
|
29
|
+
# <URL: http://ruby-gnome2.sourceforge.jp/>
|
30
|
+
class Iconv
|
31
|
+
module Failure; end
|
32
|
+
class InvalidEncoding < ArgumentError; include Failure; end
|
33
|
+
class IllegalSequence < ArgumentError; include Failure; end
|
34
|
+
class InvalidCharacter < ArgumentError; include Failure; end
|
35
|
+
|
36
|
+
if RUBY_PLATFORM =~ /java/
|
37
|
+
def self.conv(to, from, str)
|
38
|
+
raise InvalidCharacter, "the 3rd argument is nil" unless str
|
39
|
+
begin
|
40
|
+
str = java.lang.String.new(str.unpack("C*").to_java(:byte), from)
|
41
|
+
str.getBytes(to).to_ary.pack("C*")
|
42
|
+
rescue java.io.UnsupportedEncodingException
|
43
|
+
raise InvalidEncoding
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
begin
|
48
|
+
require 'glib2'
|
49
|
+
|
50
|
+
def self.check_glib_version?(major, minor, micro) # :nodoc:
|
51
|
+
(GLib::BINDING_VERSION[0] > major ||
|
52
|
+
(GLib::BINDING_VERSION[0] == major &&
|
53
|
+
GLib::BINDING_VERSION[1] > minor) ||
|
54
|
+
(GLib::BINDING_VERSION[0] == major &&
|
55
|
+
GLib::BINDING_VERSION[1] == minor &&
|
56
|
+
GLib::BINDING_VERSION[2] >= micro))
|
57
|
+
end
|
58
|
+
|
59
|
+
if check_glib_version?(0, 11, 0)
|
60
|
+
# This is a function equivalent of Iconv.iconv.
|
61
|
+
# * to: encoding name for destination
|
62
|
+
# * from: encoding name for source
|
63
|
+
# * str: strings to be converted
|
64
|
+
# * Returns: Returns an Array of converted strings.
|
65
|
+
def self.conv(to, from, str)
|
66
|
+
begin
|
67
|
+
GLib.convert(str, to, from)
|
68
|
+
rescue GLib::ConvertError => e
|
69
|
+
case e.code
|
70
|
+
when GLib::ConvertError::NO_CONVERSION
|
71
|
+
raise InvalidEncoding.new(str)
|
72
|
+
when GLib::ConvertError::ILLEGAL_SEQUENCE
|
73
|
+
raise IllegalSequence.new(str)
|
74
|
+
else
|
75
|
+
raise InvalidCharacter.new(str)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
else
|
80
|
+
def self.conv(to, from, str) # :nodoc:
|
81
|
+
begin
|
82
|
+
GLib.convert(str, to, from)
|
83
|
+
rescue
|
84
|
+
raise IllegalSequence.new(str)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
rescue LoadError
|
89
|
+
def self.conv(to, from, str) # :nodoc:
|
90
|
+
warn "Iconv was not found." if $DEBUG
|
91
|
+
str
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
def self.iconv(to, from, str)
|
96
|
+
conv(to, from, str).split(//)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/vendor/mofile.rb
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
=begin
|
2
|
+
mofile.rb - A simple class for operating GNU MO file.
|
3
|
+
|
4
|
+
Copyright (C) 2003-2008 Masao Mutoh
|
5
|
+
Copyright (C) 2002 Masahiro Sakai, Masao Mutoh
|
6
|
+
Copyright (C) 2001 Masahiro Sakai
|
7
|
+
|
8
|
+
Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
|
9
|
+
Masao Mutoh <mutoh at highway.ne.jp>
|
10
|
+
|
11
|
+
You can redistribute this file and/or modify it under the same term
|
12
|
+
of Ruby. License of Ruby is included with Ruby distribution in
|
13
|
+
the file "README".
|
14
|
+
|
15
|
+
$Id: mo.rb,v 1.10 2008/06/17 16:40:52 mutoh Exp $
|
16
|
+
=end
|
17
|
+
|
18
|
+
require 'iconv'
|
19
|
+
require 'stringio'
|
20
|
+
|
21
|
+
module GetText
|
22
|
+
class MOFile < Hash
|
23
|
+
class InvalidFormat < RuntimeError; end;
|
24
|
+
|
25
|
+
attr_reader :filename
|
26
|
+
|
27
|
+
Header = Struct.new(:magic,
|
28
|
+
:revision,
|
29
|
+
:nstrings,
|
30
|
+
:orig_table_offset,
|
31
|
+
:translated_table_offset,
|
32
|
+
:hash_table_size,
|
33
|
+
:hash_table_offset)
|
34
|
+
|
35
|
+
# The following are only used in .mo files
|
36
|
+
# with minor revision >= 1.
|
37
|
+
class HeaderRev1 < Header
|
38
|
+
attr_accessor :n_sysdep_segments,
|
39
|
+
:sysdep_segments_offset,
|
40
|
+
:n_sysdep_strings,
|
41
|
+
:orig_sysdep_tab_offset,
|
42
|
+
:trans_sysdep_tab_offset
|
43
|
+
end
|
44
|
+
|
45
|
+
MAGIC_BIG_ENDIAN = "\x95\x04\x12\xde"
|
46
|
+
MAGIC_LITTLE_ENDIAN = "\xde\x12\x04\x95"
|
47
|
+
|
48
|
+
def self.open(arg = nil, output_charset = nil)
|
49
|
+
result = self.new(output_charset)
|
50
|
+
result.load(arg)
|
51
|
+
end
|
52
|
+
|
53
|
+
def initialize(output_charset = nil)
|
54
|
+
@filename = nil
|
55
|
+
@last_modified = nil
|
56
|
+
@little_endian = true
|
57
|
+
@output_charset = output_charset
|
58
|
+
super()
|
59
|
+
end
|
60
|
+
|
61
|
+
def update!
|
62
|
+
if FileTest.exist?(@filename)
|
63
|
+
st = File.stat(@filename)
|
64
|
+
load(@filename) unless (@last_modified == [st.ctime, st.mtime])
|
65
|
+
else
|
66
|
+
warn "#{@filename} was lost." if $DEBUG
|
67
|
+
clear
|
68
|
+
end
|
69
|
+
self
|
70
|
+
end
|
71
|
+
|
72
|
+
def load(arg)
|
73
|
+
if arg.kind_of? String
|
74
|
+
begin
|
75
|
+
st = File.stat(arg)
|
76
|
+
@last_modified = [st.ctime, st.mtime]
|
77
|
+
rescue Exception
|
78
|
+
end
|
79
|
+
load_from_file(arg)
|
80
|
+
else
|
81
|
+
load_from_stream(arg)
|
82
|
+
end
|
83
|
+
@filename = arg
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def load_from_stream(io)
|
88
|
+
magic = io.read(4)
|
89
|
+
case magic
|
90
|
+
when MAGIC_BIG_ENDIAN
|
91
|
+
@little_endian = false
|
92
|
+
when MAGIC_LITTLE_ENDIAN
|
93
|
+
@little_endian = true
|
94
|
+
else
|
95
|
+
raise InvalidFormat.new(sprintf("Unknown signature %s", magic.dump))
|
96
|
+
end
|
97
|
+
|
98
|
+
endian_type6 = @little_endian ? 'V6' : 'N6'
|
99
|
+
endian_type_astr = @little_endian ? 'V*' : 'N*'
|
100
|
+
|
101
|
+
header = HeaderRev1.new(magic, *(io.read(4 * 6).unpack(endian_type6)))
|
102
|
+
|
103
|
+
if header.revision == 1
|
104
|
+
# FIXME: It doesn't support sysdep correctly.
|
105
|
+
header.n_sysdep_segments = io.read(4).unpack(endian_type6)
|
106
|
+
header.sysdep_segments_offset = io.read(4).unpack(endian_type6)
|
107
|
+
header.n_sysdep_strings = io.read(4).unpack(endian_type6)
|
108
|
+
header.orig_sysdep_tab_offset = io.read(4).unpack(endian_type6)
|
109
|
+
header.trans_sysdep_tab_offset = io.read(4).unpack(endian_type6)
|
110
|
+
elsif header.revision > 1
|
111
|
+
raise InvalidFormat.new(sprintf("file format revision %d isn't supported", header.revision))
|
112
|
+
end
|
113
|
+
io.pos = header.orig_table_offset
|
114
|
+
orig_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr)
|
115
|
+
|
116
|
+
io.pos = header.translated_table_offset
|
117
|
+
trans_table_data = io.read((4 * 2) * header.nstrings).unpack(endian_type_astr)
|
118
|
+
|
119
|
+
original_strings = Array.new(header.nstrings)
|
120
|
+
for i in 0...header.nstrings
|
121
|
+
io.pos = orig_table_data[i * 2 + 1]
|
122
|
+
original_strings[i] = io.read(orig_table_data[i * 2 + 0])
|
123
|
+
end
|
124
|
+
|
125
|
+
clear
|
126
|
+
for i in 0...header.nstrings
|
127
|
+
io.pos = trans_table_data[i * 2 + 1]
|
128
|
+
str = io.read(trans_table_data[i * 2 + 0])
|
129
|
+
|
130
|
+
if (! original_strings[i]) || original_strings[i] == ""
|
131
|
+
if str
|
132
|
+
@charset = nil
|
133
|
+
@nplurals = nil
|
134
|
+
@plural = nil
|
135
|
+
str.each_line{|line|
|
136
|
+
if /^Content-Type:/i =~ line and /charset=((?:\w|-)+)/i =~ line
|
137
|
+
@charset = $1
|
138
|
+
elsif /^Plural-Forms:\s*nplurals\s*\=\s*(\d*);\s*plural\s*\=\s*([^;]*)\n?/ =~ line
|
139
|
+
@nplurals = $1
|
140
|
+
@plural = $2
|
141
|
+
end
|
142
|
+
break if @charset and @nplurals
|
143
|
+
}
|
144
|
+
@nplurals = "1" unless @nplurals
|
145
|
+
@plural = "0" unless @plural
|
146
|
+
end
|
147
|
+
else
|
148
|
+
if @output_charset
|
149
|
+
begin
|
150
|
+
str = Iconv.conv(@output_charset, @charset, str) if @charset
|
151
|
+
rescue Iconv::Failure
|
152
|
+
if $DEBUG
|
153
|
+
warn "@charset = ", @charset
|
154
|
+
warn"@output_charset = ", @output_charset
|
155
|
+
warn "msgid = ", original_strings[i]
|
156
|
+
warn "msgstr = ", str
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
self[original_strings[i]] = str.freeze
|
162
|
+
end
|
163
|
+
self
|
164
|
+
end
|
165
|
+
|
166
|
+
# Is this number a prime number ?
|
167
|
+
# http://apidock.com/ruby/Prime
|
168
|
+
def prime?(number)
|
169
|
+
('1' * number) !~ /^1?$|^(11+?)\1+$/
|
170
|
+
end
|
171
|
+
|
172
|
+
def next_prime(seed)
|
173
|
+
require 'mathn'
|
174
|
+
prime = Prime.new
|
175
|
+
while current = prime.succ
|
176
|
+
return current if current > seed
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# From gettext-0.12.1/gettext-runtime/intl/hash-string.h
|
181
|
+
# Defines the so called `hashpjw' function by P.J. Weinberger
|
182
|
+
# [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools,
|
183
|
+
# 1986, 1987 Bell Telephone Laboratories, Inc.]
|
184
|
+
HASHWORDBITS = 32
|
185
|
+
def hash_string(str)
|
186
|
+
hval = 0
|
187
|
+
i = 0
|
188
|
+
str.each_byte do |b|
|
189
|
+
break if b == '\0'
|
190
|
+
hval <<= 4
|
191
|
+
hval += b.to_i
|
192
|
+
g = hval & (0xf << (HASHWORDBITS - 4))
|
193
|
+
if (g != 0)
|
194
|
+
hval ^= g >> (HASHWORDBITS - 8)
|
195
|
+
hval ^= g
|
196
|
+
end
|
197
|
+
end
|
198
|
+
hval
|
199
|
+
end
|
200
|
+
|
201
|
+
def save_to_stream(io)
|
202
|
+
#Save data as little endian format.
|
203
|
+
header_size = 4 * 7
|
204
|
+
table_size = 4 * 2 * size
|
205
|
+
|
206
|
+
hash_table_size = next_prime((size * 4) / 3)
|
207
|
+
hash_table_size = 3 if hash_table_size <= 2
|
208
|
+
header = Header.new(
|
209
|
+
MAGIC_LITTLE_ENDIAN, # magic
|
210
|
+
0, # revision
|
211
|
+
size, # nstrings
|
212
|
+
header_size, # orig_table_offset
|
213
|
+
header_size + table_size, # translated_table_offset
|
214
|
+
hash_table_size, # hash_table_size
|
215
|
+
header_size + table_size * 2 # hash_table_offset
|
216
|
+
)
|
217
|
+
io.write(header.to_a.pack('a4V*'))
|
218
|
+
|
219
|
+
ary = to_a
|
220
|
+
ary.sort!{|a, b| a[0] <=> b[0]} # sort by original string
|
221
|
+
|
222
|
+
pos = header.hash_table_size * 4 + header.hash_table_offset
|
223
|
+
|
224
|
+
orig_table_data = Array.new()
|
225
|
+
ary.each{|item, _|
|
226
|
+
orig_table_data.push(item.size)
|
227
|
+
orig_table_data.push(pos)
|
228
|
+
pos += item.size + 1 # +1 is <NUL>
|
229
|
+
}
|
230
|
+
io.write(orig_table_data.pack('V*'))
|
231
|
+
|
232
|
+
trans_table_data = Array.new()
|
233
|
+
ary.each{|_, item|
|
234
|
+
trans_table_data.push(item.size)
|
235
|
+
trans_table_data.push(pos)
|
236
|
+
pos += item.size + 1 # +1 is <NUL>
|
237
|
+
}
|
238
|
+
io.write(trans_table_data.pack('V*'))
|
239
|
+
|
240
|
+
hash_tab = Array.new(hash_table_size)
|
241
|
+
j = 0
|
242
|
+
ary[0...size].each {|key, _|
|
243
|
+
hash_val = hash_string(key)
|
244
|
+
idx = hash_val % hash_table_size
|
245
|
+
if hash_tab[idx] != nil
|
246
|
+
incr = 1 + (hash_val % (hash_table_size - 2))
|
247
|
+
begin
|
248
|
+
if (idx >= hash_table_size - incr)
|
249
|
+
idx -= hash_table_size - incr
|
250
|
+
else
|
251
|
+
idx += incr
|
252
|
+
end
|
253
|
+
end until (hash_tab[idx] == nil)
|
254
|
+
end
|
255
|
+
hash_tab[idx] = j + 1
|
256
|
+
j += 1
|
257
|
+
}
|
258
|
+
hash_tab.collect!{|i| i ? i : 0}
|
259
|
+
|
260
|
+
io.write(hash_tab.pack('V*'))
|
261
|
+
|
262
|
+
ary.each{|item, _| io.write(item); io.write("\0") }
|
263
|
+
ary.each{|_, item| io.write(item); io.write("\0") }
|
264
|
+
|
265
|
+
self
|
266
|
+
end
|
267
|
+
|
268
|
+
def load_from_file(filename)
|
269
|
+
@filename = filename
|
270
|
+
begin
|
271
|
+
File.open(filename, 'rb'){|f| load_from_stream(f)}
|
272
|
+
rescue => e
|
273
|
+
e.set_backtrace("File: #{@filename}")
|
274
|
+
raise e
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def save_to_file(filename)
|
279
|
+
File.open(filename, 'wb'){|f| save_to_stream(f)}
|
280
|
+
end
|
281
|
+
|
282
|
+
def set_comment(msgid_or_sym, comment)
|
283
|
+
#Do nothing
|
284
|
+
end
|
285
|
+
|
286
|
+
|
287
|
+
attr_accessor :little_endian, :path, :last_modified
|
288
|
+
attr_reader :charset, :nplurals, :plural
|
289
|
+
end
|
290
|
+
end
|
data/vendor/string.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
=begin
|
3
|
+
string.rb - Extension for String.
|
4
|
+
|
5
|
+
Copyright (C) 2005,2006 Masao Mutoh
|
6
|
+
|
7
|
+
You may redistribute it and/or modify it under the same
|
8
|
+
license terms as Ruby.
|
9
|
+
=end
|
10
|
+
|
11
|
+
# Extension for String class. This feature is included in Ruby 1.9 or later.
|
12
|
+
if RUBY_VERSION < "1.9.0"
|
13
|
+
class String
|
14
|
+
alias :_old_format_m :% # :nodoc:
|
15
|
+
|
16
|
+
# call-seq:
|
17
|
+
# %(hash)
|
18
|
+
#
|
19
|
+
# Default: "%s, %s" % ["Masao", "Mutoh"]
|
20
|
+
# Extended: "%{firstname}, %{lastname}" % {:firstname=>"Masao",:lastname=>"Mutoh"}
|
21
|
+
#
|
22
|
+
# This is the recommanded way for Ruby-GetText
|
23
|
+
# because the translators can understand the meanings of the msgids easily.
|
24
|
+
def %(args)
|
25
|
+
if args.kind_of?(Hash)
|
26
|
+
ret = dup
|
27
|
+
args.each {|key, value| ret.gsub!(/\%\{#{key}\}/, value.to_s)}
|
28
|
+
ret
|
29
|
+
else
|
30
|
+
ret = gsub(/%\{/, '%%{')
|
31
|
+
ret._old_format_m(args)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grosser-fast_gettext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
@@ -22,8 +22,10 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
-
-
|
26
|
-
-
|
25
|
+
- vendor/iconv.rb
|
26
|
+
- vendor/string.rb
|
27
|
+
- vendor/mofile.rb
|
28
|
+
- vendor/README.rdoc
|
27
29
|
- lib/fast_gettext.rb
|
28
30
|
- lib/fast_gettext
|
29
31
|
- lib/fast_gettext/storage.rb
|
@@ -42,6 +44,8 @@ files:
|
|
42
44
|
- spec/fast_gettext/mo_file_spec.rb
|
43
45
|
- spec/vendor
|
44
46
|
- spec/vendor/string_spec.rb
|
47
|
+
- VERSION.yml
|
48
|
+
- README.markdown
|
45
49
|
has_rdoc: true
|
46
50
|
homepage: http://github.com/grosser/fast_gettext
|
47
51
|
post_install_message:
|