diff options
author | DjLegolas <DjLegolas@users.noreply.github.com> | 2018-07-13 21:45:44 +0300 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2018-07-16 16:22:42 +0100 |
commit | b2e1f850d868989a9c674116e7b6dc8a08c32837 (patch) | |
tree | fd2e206c519aa9880140ddc31e142a717011f966 /deluge/ui/web/server.py | |
parent | 8bfa2cacbbcff8d2ca8882c3f9ea15f1891a25e3 (diff) | |
download | deluge-b2e1f850d868989a9c674116e7b6dc8a08c32837.tar.gz deluge-b2e1f850d868989a9c674116e7b6dc8a08c32837.tar.bz2 deluge-b2e1f850d868989a9c674116e7b6dc8a08c32837.zip |
[WebUI] Handle missing gettext.js file
Removed the creation code of `gettext.js` and now it will just mock
the `_` function by being the identity function.
Diffstat (limited to 'deluge/ui/web/server.py')
-rw-r--r-- | deluge/ui/web/server.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/deluge/ui/web/server.py b/deluge/ui/web/server.py index 117b381e9..52dc60140 100644 --- a/deluge/ui/web/server.py +++ b/deluge/ui/web/server.py @@ -83,6 +83,19 @@ class GetText(resource.Resource): return compress(template.render(), request) +class MockGetText(resource.Resource): + """GetText Mocking class + + This class will mock the file `gettext.js` in case it does not exists. + It will be used to define the `_` (underscore) function for translations, + and will return the string to translate, as is. + """ + def render(self, request): + request.setHeader(b'content-type', b'text/javascript; encoding=utf-8') + data = 'function _(string) { return string; }' + return compress(data, request) + + class Upload(resource.Resource): """ Twisted Web resource to handle file uploads @@ -431,8 +444,15 @@ class TopLevel(resource.Resource): def __init__(self): resource.Resource.__init__(self) + self.putChild('css', LookupResource('Css', rpath('css'))) - self.putChild('gettext.js', GetText()) + if os.path.isfile(rpath('js', 'gettext.js')): + self.putChild('gettext.js', GetText()) + else: + log.warning( + 'Cannot find "gettext.js" translation file!' + ' Text will only be available in English.') + self.putChild('gettext.js', MockGetText()) self.putChild('flag', Flag()) self.putChild('icons', LookupResource('Icons', rpath('icons'))) self.putChild('images', LookupResource('Images', rpath('images'))) |