Skip to content

Commit

Permalink
mofile: don't include untranlated messages in a .mo file from .po files
Browse files Browse the repository at this point in the history
  • Loading branch information
Haruka Yoshihara committed Sep 20, 2012
1 parent 465d6ef commit 586c56b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/gettext/runtime/mofile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ def hash_string(str)

#Save data as little endian format.
def save_to_stream(io)
# remove untranslated message
mo = self.delete_if do |msgid, msgstr|
msgstr.nil?
end

size = mo.size
header_size = 4 * 7
table_size = 4 * 2 * size

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

ary = to_a
ary = ary.collect do |msgid, msgstr|
msgstr ||= ""
[msgid, msgstr]
end
ary = mo.to_a
ary.sort!{|a, b| a[0] <=> b[0]} # sort by original string

pos = header.hash_table_size * 4 + header.hash_table_offset
Expand Down
1 change: 1 addition & 0 deletions test/test_mofile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_not_exist_msgid

def test_untranslated
mo = load_mo("untranslated.mo")
assert_false(mo.has_key?("untranslated"))
assert_equal(nil, mo["untranslated"])
end

Expand Down

0 comments on commit 586c56b

Please sign in to comment.