File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ - Add ` GettextPO::File#each_message ` method.
6+
57## CRuby version 0.2.1 - 2026-03-16
68
79- CRuby: Fix to work with gettext 0.23.
Original file line number Diff line number Diff line change @@ -803,6 +803,11 @@ gettextpo_po_file_m_domains (VALUE self)
803803
804804/**
805805 * call-seq: message_iterator (domain = nil) -> GettextPO::MessageIterator
806+ *
807+ * You may find it handy to use the #each_message method instead of
808+ * this to iterate over the messages. This method is for more
809+ * versatile manipulation; the returned iterator can insert messages,
810+ * for example.
806811 */
807812VALUE
808813gettextpo_po_file_m_message_iterator (int argc , VALUE * argv , VALUE self )
Original file line number Diff line number Diff line change @@ -78,6 +78,19 @@ def file_positions
7878 end
7979 end
8080
81+ class File
82+ def each_message ( domain = nil ) # yields: message
83+ iter = message_iterator ( domain )
84+ while true
85+ begin
86+ yield iter . next
87+ rescue StopIteration
88+ return
89+ end
90+ end
91+ end
92+ end
93+
8194 # This class doesn't provide the +new+ class method. See also
8295 # GettextPO::Message#filepos.
8396 class FilePos
Original file line number Diff line number Diff line change 6666 true
6767end
6868
69+ assert 'each message' do
70+ path = File . expand_path ( File . join ( __FILE__ , "../../test.cruby/resources/ok.po" ) )
71+ messages = [ ]
72+ GettextPO ::File . read ( path ) . each_message { |message | messages << message . msgid }
73+ assert_equal [ '' , 'msgid1' ] , messages
74+ true
75+ end
76+
6977assert 'header field' do
7078 assert_nil GettextPO ::File . new . domain_header
7179
You can’t perform that action at this time.
0 commit comments