@@ -84,7 +84,7 @@ def to_h
8484 object = instance_variable_get ( label )
8585 next if object . nil?
8686
87- # If it's a plural msgstr
87+ # If it's a multiline message/comment
8888 if object . value . is_a? ( Array )
8989 hash [ object . type ] = object . value . compact
9090 else
@@ -120,9 +120,8 @@ def set_instance_variable(name, value)
120120 elsif ENTRIES_LABELS . include? name
121121 instance_variable_set "@#{ name } " . to_sym , Message . new ( name , value )
122122 elsif /^msgstr\[ [0-9]\] / . match? ( name . to_s )
123- # If it's a plural msgstr
124- @msgstr ||= [ ]
125- @msgstr << Message . new ( name , value )
123+ # If it's a plural msgstr, change instance variable name to @msgstr_n as @msgstr[n] is not a valid variable name
124+ instance_variable_set "@msgstr_#{ plural_form ( name ) } " . to_sym , Message . new ( name , value )
126125 end
127126 end
128127
@@ -142,6 +141,10 @@ def define_writer_method(type, object)
142141 klass = instance_variable_get "@#{ type } " . to_sym
143142 klass . type = type
144143 klass . value = val
144+ elsif type . match ( /^msgstr_\d / )
145+ plural_form = type . to_s . scan ( /^msgstr_(\d )/ ) . last . first . to_i
146+ object_type = "msgstr[#{ plural_form } ]" . to_sym
147+ instance_variable_set "@#{ type } " . to_sym , object . new ( object_type , val )
145148 else
146149 instance_variable_set "@#{ type } " . to_sym , object . new ( type , val )
147150 end
@@ -199,5 +202,9 @@ def define_aliases
199202 self . class . send ( :alias_method , :refrence , :reference )
200203 self . class . send ( :alias_method , :refrence= , :reference= )
201204 end
205+
206+ def plural_form ( name )
207+ name . to_s . scan ( /^msgstr\[ ([0-9])\] / ) . last . first . to_i
208+ end
202209 end
203210end
0 commit comments