diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 21:38:38 +0000 |
commit | 2e2851dc13d73352530dd4495c7e05603b2e520d (patch) | |
tree | 622b9cd8e5d32091c9aa9e4937b533975a40356c /deluge/ui/web/common.py | |
parent | Initial commit. (diff) | |
download | deluge-ba36a3baaa52c6e8dc58a724548d75d3db6e8ef9.tar.xz deluge-ba36a3baaa52c6e8dc58a724548d75d3db6e8ef9.zip |
Adding upstream version 2.1.2~dev0+20240219.upstream/2.1.2_dev0+20240219upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/ui/web/common.py')
-rw-r--r-- | deluge/ui/web/common.py | 43 |
1 files changed, 43 insertions, 0 deletions
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 <damoxc@gmail.com> +# +# 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') |