From 0f31f1d34a21af7e0e226c10350c358e566eeff6 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Fri, 18 Nov 2016 20:09:51 +0100 Subject: [PATCH] Make UiWebsocket messages translatable --- src/Ui/UiWebsocket.py | 78 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py index 14232ee8..180b1bef 100644 --- a/src/Ui/UiWebsocket.py +++ b/src/Ui/UiWebsocket.py @@ -13,6 +13,7 @@ from Site import SiteManager from Debug import Debug from util import QueryJson, RateLimit from Plugin import PluginManager +from Translate import translate as _ @PluginManager.acceptPlugins @@ -44,44 +45,43 @@ class UiWebsocket(object): elif file_server.port_opened is True: self.site.notifications.append([ "done", - "Congratulation, your port %s is opened.
You are full member of ZeroNet network!" % - config.fileserver_port, + _["Congratulation, your port {0} is opened.
You are full member of ZeroNet network!"].format(config.fileserver_port), 10000 ]) elif config.tor == "always" and file_server.tor_manager.start_onions: self.site.notifications.append([ "done", - """ - Tor mode active, every connection using Onion route.
- Successfully started Tor onion hidden services. - """, + _(u""" + {_[Tor mode active, every connection using Onion route.]}
+ {_[Successfully started Tor onion hidden services.]} + """), 10000 ]) elif config.tor == "always" and file_server.tor_manager.start_onions is not False: self.site.notifications.append([ "error", - """ - Tor mode active, every connection using Onion route.
- Unable to start hidden services, please check your config. - """, + _(u""" + {_[Tor mode active, every connection using Onion route.]}
+ {_[Unable to start hidden services, please check your config.]} + """), 0 ]) elif file_server.port_opened is False and file_server.tor_manager.start_onions: self.site.notifications.append([ "done", - """ - Successfully started Tor onion hidden services.
- For faster connections open %s port on your router. - """ % config.fileserver_port, + _(u""" + {_[Successfully started Tor onion hidden services.]}
+ {_[For faster connections open {0} port on your router.]} + """).format(config.fileserver_port), 10000 ]) else: self.site.notifications.append([ "error", - """ - Your connection is restricted. Please, open %s port on your router
- or configure Tor to become full member of ZeroNet network. - """ % config.fileserver_port, + _(u""" + {_[Your connection is restricted. Please, open {0} port on your router]}
+ {_[or configure Tor to become full member of ZeroNet network.]} + """).format(config.fileserver_port), 0 ]) @@ -312,7 +312,7 @@ class UiWebsocket(object): # Sign using private key sent by user signed = site.content_manager.sign(inner_path, privatekey, extend=extend, update_changed_files=update_changed_files) if not signed: - self.cmd("notification", ["error", "Content sign failed: invalid private key."]) + self.cmd("notification", ["error", _["Content signing failed"]]) self.response(to, {"error": "Site sign failed"}) return @@ -349,7 +349,7 @@ class UiWebsocket(object): else: self.cmd( "notification", - ["info", "Content publish queued for %.0f seconds." % RateLimit.delayLeft(event_name, 30), 5000] + ["info", _["Content publish queued for {0:.0f} seconds."].format(RateLimit.delayLeft(event_name, 30)), 5000] ) self.response(to, "ok") # At the end display notification @@ -364,7 +364,7 @@ class UiWebsocket(object): published = thread.value if published > 0: # Successfully published if notification: - self.cmd("notification", ["done", "Content published to %s peers." % published, 5000]) + self.cmd("notification", ["done", _["Content published to {0} peers."].format(published), 5000]) site.updateWebsocket() # Send updated site data to local websocket clients if callback: self.response(to, "ok") @@ -372,22 +372,22 @@ class UiWebsocket(object): if len(site.peers) == 0: if sys.modules["main"].file_server.port_opened or sys.modules["main"].file_server.tor_manager.start_onions: if notification: - self.cmd("notification", ["info", "No peers found, but your content is ready to access.", 5000]) + self.cmd("notification", ["info", _["No peers found, but your content is ready to access."], 5000]) if callback: self.response(to, "ok") else: if notification: self.cmd("notification", [ "info", - """Your network connection is restricted. Please, open %s port
- on your router to make your site accessible for everyone.""" % config.fileserver_port + _("""{_[Your network connection is restricted. Please, open {0} port]}
+ {_[on your router to make your site accessible for everyone.]}""").format(config.fileserver_port) ]) if callback: self.response(to, {"error": "Port not opened."}) else: if notification: - self.cmd("notification", ["error", "Content publish failed."]) + self.cmd("notification", ["error", _["Content publish failed."]]) self.response(to, {"error": "Content publish failed."}) # Write a file to disk @@ -405,7 +405,7 @@ class UiWebsocket(object): if not found: self.cmd( "confirm", - ["This file still in sync, if you write it now, then the previous content may be lost.", "Write content anyway"], + [_["This file still in sync, if you write it now, then the previous content may be lost."], _["Write content anyway"]], lambda (res): self.actionFileWrite(to, inner_path, content_base64, ignore_bad_files=True) ) return False @@ -512,16 +512,16 @@ class UiWebsocket(object): if res is True: self.cmd( "notification", - ["done", "New certificate added: %s/%s@%s." % (auth_type, auth_user_name, domain)] + ["done", _("{_[New certificate added:]} {auth_type}/{auth_user_name}@{domain}.")] ) self.response(to, "ok") elif res is False: # Display confirmation of change cert_current = self.user.certs[domain] - body = "You current certificate: %s/%s@%s" % (cert_current["auth_type"], cert_current["auth_user_name"], domain) + body = _("{_[You current certificate:]} {cert_current[auth_type]}/{cert_current[auth_user_name]}@{domain}") self.cmd( "confirm", - [body, "Change it to %s/%s@%s" % (auth_type, auth_user_name, domain)], + [body, _("Change it to {auth_type}/{auth_user_name}@{domain}")], lambda (res): self.cbCertAddConfirm(to, domain, auth_type, auth_user_name, cert) ) else: @@ -534,14 +534,14 @@ class UiWebsocket(object): self.user.addCert(self.user.getAuthAddress(self.site.address), domain, auth_type, auth_user_name, cert) self.cmd( "notification", - ["done", "Certificate changed to: %s/%s@%s." % (auth_type, auth_user_name, domain)] + ["done", _("Certificate changed to: {auth_type}/{auth_user_name}@{domain}.")] ) self.response(to, "ok") # Select certificate for site def actionCertSelect(self, to, accepted_domains=[], accept_any=False): accounts = [] - accounts.append(["", "Unique to site", ""]) # Default option + accounts.append(["", _["Unique to site"], ""]) # Default option active = "" # Make it active if no other option found # Add my certs @@ -556,12 +556,12 @@ class UiWebsocket(object): accounts.append([domain, title, "disabled"]) # Render the html - body = "Select account you want to use in this site:" + body = "" + _["Select account you want to use in this site:"] + "" # Accounts for domain, account, css_class in accounts: if domain == active: css_class += " active" # Currently selected option - title = "%s (currently selected)" % account + title = _(u"%s ({_[currently selected]})") % account else: title = "%s" % account body += "%s" % (css_class, domain, title) @@ -571,11 +571,11 @@ class UiWebsocket(object): # body+= "Accepted authorization providers by the site:" body += "
" for domain in more_domains: - body += """ - - Register »%s + body += _(u""" + + {_[Register]} »{domain} - """ % (domain, domain) + """) body += "
" body += """ @@ -687,13 +687,13 @@ class UiWebsocket(object): new_site = site.clone(new_address, new_site_data["privatekey"], address_index=new_address_index) new_site.settings["own"] = True new_site.saveSettings() - self.cmd("notification", ["done", "Site cloned" % new_address]) + self.cmd("notification", ["done", _["Site cloned"] + "" % new_address]) gevent.spawn(new_site.announce) def actionSiteSetLimit(self, to, size_limit): self.site.settings["size_limit"] = int(size_limit) self.site.saveSettings() - self.response(to, "Site size limit changed to %sMB" % size_limit) + self.response(to, _["Site size limit changed to {0}MB"].format(size_limit)) self.site.download(blind_includes=True) def actionServerUpdate(self, to):