]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/application_helper.rb
Escape non-ascii characters in exported HTML. Closes #2075.
[rails.git] / app / helpers / application_helper.rb
index 7dcbe369b4eca7868f3b93084be921e5307f617e..ab0ba82a830f0440dee2273edb2bf2bf9f34febc 100644 (file)
@@ -3,6 +3,14 @@ module ApplicationHelper
     return sanitize(auto_link(simple_format(text), :urls))
   end
 
+  def html_escape_unicode(text)
+    chars = ActiveSupport::Multibyte::Chars.u_unpack(text).map do |c|
+      c < 127 ? c.chr : "&##{c.to_s};"
+    end
+
+    return chars.join("")
+  end
+
   def rss_link_to(*args)
     return link_to(image_tag("RSS.gif", :size => "16x16", :border => 0), Hash[*args], { :class => "rsssmall" });
   end
@@ -26,10 +34,10 @@ private
 
   def javascript_strings_for_key(key)
     js = ""
-    value = t(key)
+    value = t(key, :locale => "en")
 
     if value.is_a?(String)
-      js << "i18n_strings['#{key}'] = '" << escape_javascript(value) << "';\n"
+      js << "i18n_strings['#{key}'] = '" << escape_javascript(t(key)) << "';\n"
     else
       value.each_key do |k|
         js << javascript_strings_for_key("#{key}.#{k}")