lib/gettext/po_entry.rb in gettext-3.0.1 vs lib/gettext/po_entry.rb in gettext-3.0.2
- old
+ new
@@ -210,10 +210,12 @@
# Includes reference comments in formatted string if true.
# @option options [Integer] :max_line_width (78)
# Wraps long lines that is longer than the `:max_line_width`.
# Don't break long lines if `:max_line_width` is less than 0
# such as `-1`.
+ # @option options [Encoding] :encoding (nil)
+ # Encodes to the specific encoding.
def initialize(entry, options={})
@entry = entry
@options = fill_default_option_values(options)
end
@@ -265,11 +267,12 @@
end
else
str << "msgstr "
str << format_message(@entry.msgstr)
end
- str
+
+ encode(str)
end
private
def fill_default_option_values(options)
options = options.dup
@@ -378,9 +381,15 @@
line.scan(/.{1,#{max_line_width}}/m) do |chunk|
chunks << chunk
end
end
chunks
+ end
+
+ def encode(string)
+ encoding = @options[:encoding]
+ return string if encoding.nil?
+ string.encode(encoding)
end
end
end
end