From 66fa7b610bdfb2e07fe99fa656c93a08d2190e29 Mon Sep 17 00:00:00 2001 From: thomasv Date: Wed, 2 Jan 2013 16:03:54 +0100 Subject: [PATCH] option to set gui language from command line --- electrum | 2 ++ lib/__init__.py | 1 + lib/i18n.py | 21 +++++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/electrum b/electrum index 132c5931..c571258c 100755 --- a/electrum +++ b/electrum @@ -138,6 +138,7 @@ def arg_parser(): parser.add_option("-p", "--proxy", dest="proxy", default=None, help="set proxy [type:]host[:port], where type is socks4,socks5 or http") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="show debugging information") parser.add_option("-P", "--portable", action="store_true", dest="portable", default=False, help="portable wallet") + parser.add_option("-L", "--lang", dest="language", default=None, help="defaut language used in GUI") return parser @@ -146,6 +147,7 @@ if __name__ == '__main__': parser = arg_parser() options, args = parser.parse_args() set_verbosity(options.verbose) + set_language(options.language) # config is an object passed to the various constructors (wallet, interface, gui) if 'ANDROID_DATA' in os.environ: diff --git a/lib/__init__.py b/lib/__init__.py index abbc9553..1506f3e7 100644 --- a/lib/__init__.py +++ b/lib/__init__.py @@ -1,5 +1,6 @@ from version import ELECTRUM_VERSION from util import format_satoshis, print_msg, print_error, set_verbosity +from i18n import set_language from wallet import Wallet, WalletSynchronizer from verifier import WalletVerifier from interface import Interface, pick_random_server, DEFAULT_SERVERS diff --git a/lib/i18n.py b/lib/i18n.py index 2c0a6449..c3903167 100644 --- a/lib/i18n.py +++ b/lib/i18n.py @@ -16,10 +16,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import gettext +import gettext, os -LOCALE_DIR = '/usr/share/locale' -#LOCALE_DIR = './locale' +if os.path.exists('./locale'): + LOCALE_DIR = './locale' +else: + LOCALE_DIR = '/usr/share/locale' + +print LOCALE_DIR language = gettext.translation('electrum', LOCALE_DIR, fallback = True) -_ = language.ugettext + +def _(x): + global language + return language.ugettext(x) + +def set_language(x): + global language + if x: language = gettext.translation('electrum', LOCALE_DIR, fallback = True, languages=[x]) + +