Skip to content

Commit 586c56b

Browse files
author
Haruka Yoshihara
committed
mofile: don't include untranlated messages in a .mo file from .po files
refs mutoh#11
1 parent 465d6ef commit 586c56b

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

lib/gettext/runtime/mofile.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ def hash_string(str)
203203

204204
#Save data as little endian format.
205205
def save_to_stream(io)
206+
# remove untranslated message
207+
mo = self.delete_if do |msgid, msgstr|
208+
msgstr.nil?
209+
end
210+
211+
size = mo.size
206212
header_size = 4 * 7
207213
table_size = 4 * 2 * size
208214

@@ -219,11 +225,7 @@ def save_to_stream(io)
219225
)
220226
io.write(header.to_a.pack('a4V*'))
221227

222-
ary = to_a
223-
ary = ary.collect do |msgid, msgstr|
224-
msgstr ||= ""
225-
[msgid, msgstr]
226-
end
228+
ary = mo.to_a
227229
ary.sort!{|a, b| a[0] <=> b[0]} # sort by original string
228230

229231
pos = header.hash_table_size * 4 + header.hash_table_offset

test/test_mofile.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def test_not_exist_msgid
1010

1111
def test_untranslated
1212
mo = load_mo("untranslated.mo")
13+
assert_false(mo.has_key?("untranslated"))
1314
assert_equal(nil, mo["untranslated"])
1415
end
1516

0 commit comments

Comments
 (0)