lib/gettext/po_entry.rb in gettext-3.0.2 vs lib/gettext/po_entry.rb in gettext-3.0.3
- old
+ new
@@ -163,10 +163,22 @@
# Returns true if the type is kind of plural.
def plural?
[:plural, :msgctxt_plural].include?(@type)
end
+ # @return true if the entry is header entry, false otherwise.
+ # Header entry is normal type and has empty msgid.
+ def header?
+ @type == :normal and @msgid == ""
+ end
+
+ # @return true if the entry is obsolete entry, false otherwise.
+ # Obsolete entry is normal type and has :last msgid.
+ def obsolete?
+ @type == :normal and @msgid == :last
+ end
+
def [](number)
param = @param_type[number]
raise ParseError, 'no more string parameters expected' unless param
send param
end
@@ -218,12 +230,11 @@
@entry = entry
@options = fill_default_option_values(options)
end
def format
- # extracted comments
- if @entry.msgid == :last
+ if @entry.obsolete?
return format_obsolete_comment(@entry.comment)
end
str = ""
str << format_translator_comment
@@ -341,11 +352,11 @@
return "" if comment.nil?
formatted_comment = ""
comment.each_line do |comment_line|
if /\A#[^~]/ =~ comment_line or comment_line.start_with?(mark)
- formatted_comment << comment_line
+ formatted_comment << "#{comment_line.chomp}\n"
elsif comment_line == "\n"
formatted_comment << "\n"
else
formatted_comment << "#{mark} #{comment_line.strip}\n"
end
@@ -371,16 +382,19 @@
def wrap_message(message)
return [message] if message.empty?
max_line_width = @options[:max_line_width]
- return [message] if max_line_width <= 0
chunks = []
message.each_line do |line|
- # TODO: use character width instead of the number of characters
- line.scan(/.{1,#{max_line_width}}/m) do |chunk|
- chunks << chunk
+ if max_line_width <= 0
+ chunks << line
+ else
+ # TODO: use character width instead of the number of characters
+ line.scan(/.{1,#{max_line_width}}/m) do |chunk|
+ chunks << chunk
+ end
end
end
chunks
end