Skip to content

Instantly share code, notes, and snippets.

@bendikro
Created April 23, 2016 15:36
Show Gist options
  • Save bendikro/cfe8168829ce54ea8f69269b328f0d6a to your computer and use it in GitHub Desktop.
Save bendikro/cfe8168829ce54ea8f69269b328f0d6a to your computer and use it in GitHub Desktop.
25 def escape(text):
26 """
27 Used by the gettext.js template to escape translated strings
28 so they don't break the script.
29 """
30 t = text
31 text = text.replace("'", "\\'")
32 text = text.replace('\r\n', '\\n')
33 text = text.replace('\r', '\\n')
34 text = text.replace('\n', '\\n')
35 if t != text:
36 print "web.common.escape('%s') -> '%s'" % (t, text)
37 return text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment