From 2e2851dc13d73352530dd4495c7e05603b2e520d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 23:38:38 +0200 Subject: Adding upstream version 2.1.2~dev0+20240219. Signed-off-by: Daniel Baumann --- deluge/ui/web/common.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 deluge/ui/web/common.py (limited to 'deluge/ui/web/common.py') diff --git a/deluge/ui/web/common.py b/deluge/ui/web/common.py new file mode 100644 index 0000000..32c29c8 --- /dev/null +++ b/deluge/ui/web/common.py @@ -0,0 +1,43 @@ +# +# Copyright (C) 2009 Damien Churchill +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import gettext + +from mako.template import Template as MakoTemplate + +from deluge.common import get_version + + +def _(text): + text_local = gettext.gettext(text) + return text_local + + +def escape(text): + """ + Used by gettext.js template to escape any translated language strings that + might contain newlines or quotes as they would break the script. + """ + text = text.replace("'", "\\'") + text = text.replace('\r\n', '\\n') + text = text.replace('\r', '\\n') + text = text.replace('\n', '\\n') + return text + + +class Template(MakoTemplate): + """ + A template that adds some built-ins to the rendering + """ + + builtins = {'_': _, 'escape': escape, 'version': get_version()} + + def render(self, *args, **data): + data.update(self.builtins) + rendered = MakoTemplate.render_unicode(self, *args, **data) + return rendered.encode('utf-8') -- cgit v1.2.3