def interpolate(locale, string, values = {})
return string unless string.is_a?(String)
if string.respond_to?(:force_encoding)
original_encoding = string.encoding
string.force_encoding(Encoding::BINARY)
end
result = string.gsub(MATCH) do
escaped, pattern, key = $1, $2, $2.to_sym
if escaped
pattern
elsif INTERPOLATION_RESERVED_KEYS.include?(pattern)
raise ReservedInterpolationKey.new(pattern, string)
elsif !values.include?(key)
raise MissingInterpolationArgument.new(pattern, string)
else
values[key].to_s
end
end
result.force_encoding(original_encoding) if original_encoding
result
end