Module: PoHelper
Instance Method Summary collapse
-
#encoding ⇒ Object
charset encoding of the PO file.
-
#parse_content_type(content_type) ⇒ Object
parse content_type and return charset encoding “text/plain; charset=ISO-8859-2” => ‘ISO-8859-2’.
Instance Method Details
#encoding ⇒ Object
charset encoding of the PO file. defaults to utf-8 if it is not defined in the PO header
11 12 13 14 15 16 |
# File 'lib/ri18n/pohelper.rb', line 11 def encoding # return if there is was no PO header to get an encoding from return 'utf-8' unless header return 'utf-8' unless ct = header['Content-Type'] parse_content_type(ct) end |
#parse_content_type(content_type) ⇒ Object
parse content_type and return charset encoding
"text/plain; charset=ISO-8859-2" => 'ISO-8859-2'
6 7 8 |
# File 'lib/ri18n/pohelper.rb', line 6 def parse_content_type(content_type) %r{(?:\w|\d|[-/])+;\s+charset=((?:\w|\d|-)+)\z}.match(content_type)[1] end |