From 4f35282511b958cbda6a5a0a2dd33ef7d743f588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Thu, 26 Jun 2014 20:46:29 +0200 Subject: [PATCH 1/4] encode all strings as utf-8 --- onionshare/onionshare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index e8f374d6..616fc92b 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -168,7 +168,7 @@ def load_strings(default="en"): # if a string doesn't exist, fallback to English for key in translated[default]: if key in translated[lang]: - strings[key] = translated[lang][key] + strings[key] = translated[lang][key].encode("utf-8") return strings def file_crunching(filename): From c52fd0915e98d40327245b6d1401edcd357d1e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Thu, 26 Jun 2014 21:51:54 +0200 Subject: [PATCH 2/4] add translated() to return encoded translated strings --- onionshare/onionshare.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py index 616fc92b..a04a29a1 100644 --- a/onionshare/onionshare.py +++ b/onionshare/onionshare.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64 from random import randint from functools import wraps @@ -146,12 +147,12 @@ def is_root(): def tails_open_port(port): if get_platform() == 'Tails': - print strings["punching_a_hole"] + print translated("punching_a_hole") subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'ACCEPT']) def tails_close_port(port): if get_platform() == 'Tails': - print strings["closing_hole"] + print translated("closing_hole") subprocess.call(['/sbin/iptables', '-I', 'OUTPUT', '-o', 'lo', '-p', 'tcp', '--dport', str(port), '-j', 'REJECT']) def load_strings(default="en"): @@ -168,9 +169,12 @@ def load_strings(default="en"): # if a string doesn't exist, fallback to English for key in translated[default]: if key in translated[lang]: - strings[key] = translated[lang][key].encode("utf-8") + strings[key] = translated[lang][key] return strings +def translated(k): + return strings[k].encode("utf-8") + def file_crunching(filename): # calculate filehash, file size BLOCKSIZE = 65536 @@ -213,7 +217,7 @@ def start_hidden_service(port): except SocketError: pass if not controller: - raise NoTor(strings["cant_connect_ctrlport"].format(controlports)) + raise NoTor(translated("cant_connect_ctrlport").format(controlports)) controller.authenticate() # set up hidden service @@ -233,7 +237,7 @@ def main(): # check for root in Tails if get_platform() == 'Tails' and not is_root(): - sys.exit(strings["tails_requires_root"]) + sys.exit(translated("tails_requires_root")) # parse arguments parser = argparse.ArgumentParser() @@ -249,7 +253,7 @@ def main(): stay_open = args.stay_open if not (filename and os.path.isfile(filename)): - sys.exit(strings["not_a_file"].format(filename)) + sys.exit(translated("not_a_file").format(filename)) filename = os.path.abspath(filename) port = choose_port() @@ -257,24 +261,24 @@ def main(): if not local_only: # try starting hidden service - print strings["connecting_ctrlport"].format(port) + print translated("connecting_ctrlport").format(port) try: onion_host = start_hidden_service(port) except NoTor as e: sys.exit(e.args[0]) # startup - print strings["calculating_sha1"] + print translated("calculating_sha1") filehash, filesize = file_crunching(filename) set_file_info(filename, filehash, filesize) tails_open_port(port) - print '\n' + strings["give_this_url"] + print '\n' + translated("give_this_url") if local_only: print 'http://{0}/{1}'.format(local_host, slug) else: print 'http://{0}/{1}'.format(onion_host, slug) print '' - print strings["ctrlc_to_stop"] + print translated("ctrlc_to_stop") # start the web server app.run(port=port) From eb69586b120d271517fccb7a59435edb4621239b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Thu, 26 Jun 2014 22:36:42 +0200 Subject: [PATCH 3/4] New norwegian translations. --- onionshare/strings.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/onionshare/strings.json b/onionshare/strings.json index c044a23c..e08d6f8e 100644 --- a/onionshare/strings.json +++ b/onionshare/strings.json @@ -28,7 +28,16 @@ "ctrlc_to_stop": "Trykk Ctrl+C for å stoppe serveren.", "not_a_file": "{0} er ikke en fil.", "filesize": "Filstørrelse", - "sha1_checksum": "SHA1 sjekksum" + "sha1_checksum": "SHA1 sjekksum", + "copied_url": "Kopierte URL-en til utklippstavlen", + "download_page_loaded": "Nedlastingsside lastet", + "download_started": "Nedlasting startet", + "download_finished": "Nedlasting fullført", + "other_page_loaded": "En annen side har blitt lastet", + "tails_requires_root": "OnionShare kan må kjøres som administrator i Tails", + "close_on_finish": "Lukk automatisk", + "close_countdown": "Lukker om {0} sekunder", + "choose_file": "Velg en fil å dele" }, "es": { "punching_a_hole": "Abriendo un agujero en el cortafuegos.", "closing_hole": "Cerrando el agujero en el cortafuegos.", From 10f8600e540dde3c65841aa0a70df62243d61b62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Thu, 26 Jun 2014 22:37:25 +0200 Subject: [PATCH 4/4] use the translated() function in onionshare_gui --- onionshare_gui/onionshare_gui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index 3516f558..51c60e44 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -13,7 +13,7 @@ try: except ImportError: sys.path.append(os.path.abspath(onionshare_gui_dir+"/..")) import onionshare - +from onionshare import translated import webapp window_icon = None @@ -63,7 +63,7 @@ def select_file(strings): if onionshare.get_platform() == 'Tails': args['directory'] = '/home/amnesia' - filename = QFileDialog.getOpenFileName(caption=strings['choose_file'], options=QFileDialog.ReadOnly, **args) + filename = QFileDialog.getOpenFileName(caption=translated('choose_file'), options=QFileDialog.ReadOnly, **args) if not filename: return False, False @@ -71,7 +71,7 @@ def select_file(strings): # validate filename if not os.path.isfile(filename): - alert(strings["not_a_file"].format(filename), QMessageBox.Warning) + alert(translated("not_a_file").format(filename), QMessageBox.Warning) return False, False filename = os.path.abspath(filename)