speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] spd-conf - Make spd-conf translatable


From: Luke Yelavich
Subject: [PATCH] spd-conf - Make spd-conf translatable
Date: Wed, 29 Oct 2014 15:34:55 +1100

From: Luke Yelavich <address@hidden>
To: address@hidden

---
 po/POTFILES.in                            |   1 +
 src/api/python/speechd_config/Makefile.am |  18 +-
 src/api/python/speechd_config/config.py   | 263 +++++++++++++++---------------
 src/api/python/speechd_config/i18n.py.in  |   8 +
 4 files changed, 157 insertions(+), 133 deletions(-)
 create mode 100644 src/api/python/speechd_config/i18n.py.in

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 338bcc6..b37de17 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,4 @@
 src/server/options.c
 src/clients/say/options.c
 src/api/python/speechd_config/speechd.desktop.in
+src/api/python/speechd_config/config.py
diff --git a/src/api/python/speechd_config/Makefile.am 
b/src/api/python/speechd_config/Makefile.am
index 1da2c28..0f2afa3 100644
--- a/src/api/python/speechd_config/Makefile.am
+++ b/src/api/python/speechd_config/Makefile.am
@@ -11,7 +11,7 @@ dist_bin_SCRIPTS = spd-conf
 
 speechd_pythondir = $(pyexecdir)/speechd_config
 speechd_python_PYTHON = __init__.py config.py
-nodist_speechd_python_PYTHON = paths.py
+nodist_speechd_python_PYTHON = paths.py i18n.py
 
 paths_edit = sed \
        -e "s:address@hidden@]:$(spdconforigdir):" \
@@ -19,14 +19,26 @@ paths_edit = sed \
        -e "s:address@hidden@]:$(snddatadir):" \
        -e "s:address@hidden@]:$(spddesktopconforigdir):"
 
+i18n_edit = sed \
+       -e "s:address@hidden@]:$(GETTEXT_PACKAGE):" \
+       -e "s:address@hidden@]:$(localedir):"
+
 paths.py: Makefile
        rm -f $@
        srcdir=; \
        test -f ./address@hidden || srcdir=$(srcdir)/; \
        $(paths_edit) address@hidden > $@
 
+i18n.py: Makefile
+       rm -f $@
+       srcdir=; \
+       test -f ./address@hidden || srcdir=$(srcdir)/; \
+       $(i18n_edit) address@hidden > $@
+
 paths.py: $(srcdir)/paths.py.in
 
-CLEANFILES = paths.py speechd.desktop
+i18n.py: $(srcdir)/i18n.py.in
+
+CLEANFILES = paths.py i18n.py speechd.desktop
 
-EXTRA_DIST = paths.py.in speechd.desktop.in
+EXTRA_DIST = paths.py.in speechd.desktop.in i18n.py.in
diff --git a/src/api/python/speechd_config/config.py 
b/src/api/python/speechd_config/config.py
index 1f4d35d..bae08cd 100644
--- a/src/api/python/speechd_config/config.py
+++ b/src/api/python/speechd_config/config.py
@@ -28,6 +28,9 @@ import datetime
 from optparse import OptionParser
 from xdg import BaseDirectory
 
+# Locale/gettext configuration
+from . import i18n
+
 # Configuration and sound data paths
 from . import paths
 
@@ -86,10 +89,10 @@ def question_with_suggested_answers(text, default, suggest):
     
     reply = question(text, default)
     while reply not in suggest:
-        report("""The value you have chosen is not among the suggested values.
-You have chosen '%s'.""" % reply)
-        report("The suggested values are " + str(suggest))
-        correct = question("Do you want to correct your answer?", True)
+        report(_("""The value you have chosen is not among the suggested 
values.
+You have chosen '%s'.""" % reply))
+        report(_("The suggested values are " + str(suggest))))
+        correct = question(_("Do you want to correct your answer?", True))
         if correct == True:
             reply = question(text, default)
         else:
@@ -101,7 +104,7 @@ def question_with_required_answers(text, default, required):
     
     reply = question(text, default)
     while reply not in required:
-        report("You have chosen '%s'. Please choose one of %s" % (reply, 
str(required)))
+        report(_("You have chosen '%s'. Please choose one of %s" % (reply, 
str(required))))
         reply = question(text, default)
     return reply
 
@@ -112,7 +115,7 @@ class Options(object):
         {
         'create_user_configuration':
             {
-            'descr' : "Create Speech Dispatcher configuration for the given 
user",
+            'descr' : _("Create Speech Dispatcher configuration for the given 
user"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -120,7 +123,7 @@ class Options(object):
             },
         'config_basic_settings_user':
             {
-            'descr' : "Configure basic settings in user configuration",
+            'descr' : _("Configure basic settings in user configuration"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -128,7 +131,7 @@ class Options(object):
             },
         'config_basic_settings_system':
             {
-            'descr' : "Configure basic settings in system-wide configuration",
+            'descr' : _("Configure basic settings in system-wide 
configuration"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -136,7 +139,7 @@ class Options(object):
             },
         'diagnostics':
             {
-            'descr' : "Diagnose problems with the current setup",
+            'descr' : _("Diagnose problems with the current setup"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -144,7 +147,7 @@ class Options(object):
             },
         'test_spd_say':
             {
-            'descr' : "Test connection to Speech Dispatcher using spd-say",
+            'descr' : _("Test connection to Speech Dispatcher using spd-say"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -152,7 +155,7 @@ class Options(object):
             },
         'test_festival':
             {
-            'descr' : "Test whether Festival works as a server",
+            'descr' : _("Test whether Festival works as a server"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -160,7 +163,7 @@ class Options(object):
             },
         'test_espeak':
             {
-            'descr' : "Test whether Espeak works as a standalone binary",
+            'descr' : _("Test whether Espeak works as a standalone binary"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -168,7 +171,7 @@ class Options(object):
             },
         'test_alsa':
             {
-            'descr' : "Test ALSA audio",
+            'descr' : _("Test ALSA audio"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -177,7 +180,7 @@ class Options(object):
 
         'test_pulse':
             {
-            'descr' : "Test Pulse Audio",
+            'descr' : _("Test Pulse Audio"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -186,7 +189,7 @@ class Options(object):
 
         'use_espeak_synthesis':
             {
-            'descr' : "Use espeak to synthesize messages",
+            'descr' : _("Use espeak to synthesize messages"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -194,7 +197,7 @@ class Options(object):
             },
         'dont_ask':
             {
-            'descr' : "Do not ask any questions, always use default values",
+            'descr' : _("Do not ask any questions, always use default values"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -202,7 +205,7 @@ class Options(object):
             },
         'debug':
             {
-            'descr' : "Debug a problem and generate a report",
+            'descr' : _("Debug a problem and generate a report"),
             'doc' : None,
             'type' : bool,
             'default' : False,
@@ -211,9 +214,9 @@ class Options(object):
         }
 
     def __init__(self):
-        usage = """%prog [options]
+        usage = _("""%prog [options]
 A simple dialog based tool for basic configuration of Speech Dispatcher
-and problem diagnostics."""
+and problem diagnostics.""")
         self.cmdline_parser = OptionParser(usage)
 
         for option, definition in self._conf_options.items():
@@ -295,12 +298,12 @@ class Tests:
             self.festival_socket.connect((socket.gethostbyname(host), port))
         except socket.error as e:
             (num, reson) = e.args
-            report("""ERROR: It was not possible to connect to Festival on the
+            report(_("""ERROR: It was not possible to connect to Festival on 
the
 given host and port. Connection failed with error %d : %s .""" % (num, reson))
             report("""Hint: Most likely, your Festival server is not running 
now
 or not at the default port %d.
 
-Try /etc/init.d/festival start or run 'festival --server' from the command 
line.""" % port)
+Try /etc/init.d/festival start or run 'festival --server' from the command 
line.""" % port))
             return False
         return True
         
@@ -313,12 +316,12 @@ Try /etc/init.d/festival start or run 'festival --server' 
from the command line.
         self.festival_socket.send(bytes("(require 'speech-dispatcher)\n", 
"ascii"))
         reply = str(self.festival_socket.recv(1024))
         if "LP" in reply:
-            report("Festival contains freebsoft-utils.")
+            report(_("Festival contains freebsoft-utils."))
             return True
         else:
-            report("""ERROR: Your Festival server is working but it doesn't 
seem
+            report(_("""ERROR: Your Festival server is working but it doesn't 
seem
 to load festival-freebsoft-utils. You need to install festival-freebsoft-utils
-to be able to use Festival with Speech Dispatcher.""")
+to be able to use Festival with Speech Dispatcher."""))
             return False
 
     def python_speechd_in_path(self):
@@ -326,10 +329,10 @@ to be able to use Festival with Speech Dispatcher.""")
         try:
             import speechd
         except:
-            report("""Python can't find the Speech Dispatcher library.
+            report(_("""Python can't find the Speech Dispatcher library.
 Is it installed? This won't prevent Speech Dispatcher to work, but no
 Python applications like Orca will be able to use it.
-Search for package like python-speechd, download and install it""")
+Search for package like python-speechd, download and install it"""))
             return False
         return True
 
@@ -348,87 +351,87 @@ Search for package like python-speechd, download and 
install it""")
         try:
             ret = os.system(cmd)
         except:
-            report("""Can't execute the %s command, this audio output might 
not be available
+            report(_("""Can't execute the %s command, this audio output might 
not be available
 on your system, but it might also be a false warning. Please make
-sure your audio is working.""")
-            reply = question("Are you sure that %s audio is working?" % type, 
False)
+sure your audio is working."""))
+            reply = question(_("Are you sure that %s audio is working?" % 
type), False)
             return reply
     
         if ret:
-            report("Can't play audio via\n     %s" % cmd)
-            report("""Your audio doesn't seem to work, please fix audio first 
or choose
-a different method.""")
+            report(_("Can't play audio via\n     %s" % cmd))
+            report(_("""Your audio doesn't seem to work, please fix audio 
first or choose
+a different method."""))
             return False
 
 
-        reply = question("Did you hear the sound?", True)
+        reply = question(_("Did you hear the sound?"), True)
         
         if not reply:
-            report("""Please examine the above output from the sound playback
+            report(_("""Please examine the above output from the sound playback
 utility. If everything seems right, are you sure your audio is loud enough and
 not muted in the mixer? Please fix your audio system first or choose a 
different
-audio output method in configuration.""")
+audio output method in configuration."""))
             return False
         else:
-            report("Audio output '%s' works" % type)
+            report(_("Audio output '%s' works" % type))
             return True
 
     def test_spd_say(self):
         """Test Speech Dispatcher using spd_say"""
 
-        report("Testing Speech Dispatcher using spd_say")
+        report(_("Testing Speech Dispatcher using spd_say"))
         
         while True:
             try:
                 ret = os.system("spd-say -P important \"Speech Dispatcher 
works\"")
             except:
-                report("""Can't execute the spd-say binary,
-it is very likely that Speech Dispatcher is not installed.""")
+                report(_("""Can't execute the spd-say binary,
+it is very likely that Speech Dispatcher is not installed."""))
                 return False
-            hearing_test = question("Did you hear the message about Speech 
Dispatcher working?", True)
+            hearing_test = question(_("Did you hear the message about Speech 
Dispatcher working?"), True)
             if hearing_test:
-                report("Speech Dispatcher is installed and working!")
+                report(_("Speech Dispatcher is installed and working!"))
                 return True
             else:
-                report("Speech Dispatcher is installed but there is some 
problem")
+                report(_("Speech Dispatcher is installed but there is some 
problem"))
                 return False
 
     def test_festival(self):
         """Test whether Festival works as a server"""
-        report("Testing whether Festival works as a server")
+        report(_("Testing whether Festival works as a server"))
 
         ret = self.festival_with_freebsoft_utils()
         if not ret:
-            report("Festival server is not working.")
+            report(_("Festival server is not working."))
             return False
         else:
-            report("Festival server seems to work correctly")
+            report(_("Festival server seems to work correctly"))
             return True
 
     def test_espeak(self):
         """Test the espeak utility"""
 
-        report("Testing whether Espeak works")
+        report(_("Testing whether Espeak works"))
         
         while True:
             try:
                 os.system("espeak \"Espeak seems to work\"")
             except:
-                report("""Can't execute the espeak binary, it is likely that 
espeak
-is not installed.""")
+                report(_("""Can't execute the espeak binary, it is likely that 
espeak
+is not installed."""))
                 return False
 
-            report("Espeak is installed")
+            report(_("Espeak is installed"))
             return True
 
     def test_alsa(self):
         """Test ALSA sound output"""
-        report("Testing ALSA sound output")
+        report(_("Testing ALSA sound output"))
         return self.audio_try_play(type='alsa')
 
     def test_pulse(self):
         """Test Pulse Audio sound output"""
-        report("Testing PULSE sound output")
+        report(_("Testing PULSE sound output"))
         return self.audio_try_play(type='pulse')
 
     def diagnostics(self, speechd_running = True, output_modules=[], 
audio_output=[]):
@@ -441,7 +444,7 @@ is not installed.""")
             # Test whether Speech Dispatcher works
             if self.test_spd_say():
                 spd_say_working = True
-                skip = question("Speech Dispatcher works. Do you want to skip 
other tests?",
+                skip = question(_("Speech Dispatcher works. Do you want to 
skip other tests?",)
                                 True)
                 if skip:
                     return {'spd_say_working': True}
@@ -451,17 +454,17 @@ is not installed.""")
             spd_say_working = False
 
         if not spd_say_working:
-            if not question("""
+            if not question(_("""
 Speech Dispatcher isn't running or we can't connect to it (see above),
 do you want to proceed with other tests? (They can help to determine
-what is wrong)""", True):
+what is wrong)"""), True):
                 return {'spd_say_working': False}
 
         def decide_to_test(identifier, name, listing):
             """"Ask the user whether to test a specific capability"""
             if ((identifier in listing)
                 or (not len(listing)
-                    and question("Do you want to test the %s now?" % name, 
True))):
+                    and question(_("Do you want to test the %s now?" % name), 
True))):
                 return True
             else:
                 return False
@@ -482,7 +485,7 @@ what is wrong)""", True):
             if self.test_pulse():
                 working_audio += ["pulse"]
 
-        report("Testing whether Python Speech Dispatcher library is in path 
and importable")
+        report(_("Testing whether Python Speech Dispatcher library is in path 
and importable"))
         python_speechd_working = test.python_speechd_in_path()
         
         return  {'spd_say_working': spd_say_working,
@@ -493,27 +496,27 @@ what is wrong)""", True):
     def write_diagnostics_results(self, results):
         """Write out diagnostics results using report()"""
 
-        report("""
+        report(_("""
 
-Diagnostics results:""")
+Diagnostics results:"""))
         if 'spd_say_working' in results:
             if results['spd_say_working']:
-                report("Speech Dispatcher is working")
+                report(_("Speech Dispatcher is working"))
             else:
-                report("Speech Dispatcher not working through spd-say")
+                report(_("Speech Dispatcher not working through spd-say"))
         if 'synthesizers' in results:
-            report("Synthesizers that were tested and seem to work: %s" %
+            report(_("Synthesizers that were tested and seem to work: %s" %)
                    str(results['synthesizers']))
         if 'audio' in results:
-            report("Audio systems that were tested and seem to work: %s" %
+            report(_("Audio systems that were tested and seem to work: %s" %)
                    str(results['audio']))
         if 'python_speechd' in results:
             if(results['python_speechd']):
-                report("Python Speech Dispatcher module is importable")
+                report(_("Python Speech Dispatcher module is importable"))
             else:
-                report("""Python Speech Dispatcher module not importable.
-Either not installed or not in path.""")
-        report("End of diagnostics results")
+                report(_("""Python Speech Dispatcher module not importable.
+Either not installed or not in path."""))
+        report(_("End of diagnostics results"))
 
     def user_configuration_seems_complete(self):
         """Decide if the user configuration seems reasonably complete"""
@@ -535,27 +538,27 @@ Either not installed or not in path.""")
         """Start Speech Dispatcher in debugging mode, collect the debugging 
output
         and offer to send it to the developers"""
 
-        report("Starting collecting debugging output, configuration and 
logfiles")
+        report(_("Starting collecting debugging output, configuration and 
logfiles"))
 
         if not type:
-            type = question_with_required_answers("""
-Do you want to debug 'system' or  'user' Speech Dispatcher?""",
+            type = question_with_required_answers(_("""
+Do you want to debug 'system' or  'user' Speech Dispatcher?"""),
                                                   'user', ['user', 'system'])
 
         # Try to kill running Speech Dispatcher
-        reply = question("""It is necessary to kill the currently running 
Speech Dispatcher
-processes. Do you want to do it now?""", True)
+        reply = question(_("""It is necessary to kill the currently running 
Speech Dispatcher
+processes. Do you want to do it now?"""), True)
         if reply:
             os.system("killall speech-dispatcher")
             # Attempt to workaround the psmisc 22.15 bug with 16 char max 
process names
             os.system("killall speech-dispatch")
         else:
-            report("""
+            report(_("""
 You decided not to kill running Speech Dispatcher processes.
-Please make sure your Speech Dispatcher is not running now.""")
-            reply = question("Is your Speech Dispatcher not running now?", 
True)
+Please make sure your Speech Dispatcher is not running now."""))
+            reply = question(_("Is your Speech Dispatcher not running now?"), 
True)
             if not reply:
-                report("Can't continue, please stop your Speech Dispatcher and 
try again")
+                report(_("Can't continue, please stop your Speech Dispatcher 
and try again"))
 
         time.sleep(2)
 
@@ -571,36 +574,36 @@ Please make sure your Speech Dispatcher is not running 
now.""")
 
         # Start Speech Dispatcher with debugging enabled
         if type == 'user':
-            report("Speech Dispatcher will be started now in debugging mode")
+            report(_("Speech Dispatcher will be started now in debugging 
mode"))
             speechd_started = not os.system("speech-dispatcher -D")
             configure_directory = test.user_conf_dir()
         else:
-            report("Warning: You must be root or under sudo to do this.")      
  
-            report("""
-Please start your system Speech Dispatcher now with parameter '-D'""")
-            reply = question("Is your Speech Dispatcher running now?", True)
+            report(_("Warning: You must be root or under sudo to do this.")    
    )
+            report(_("""
+Please start your system Speech Dispatcher now with parameter '-D'"""))
+            reply = question(_("Is your Speech Dispatcher running now?"), True)
             if reply:
                 speechd_started = True
             else:
-                report("Can't continue")
+                report(_("Can't continue"))
             configure_directory = test.system_conf_dir()
         time.sleep(2)
 
         if not speechd_started:
             reply = question("Speech Dispatcher failed to start, continuing 
anyway")
 
-        report("Trying to speak some messages")
+        report(_("Trying to speak some messages"))
         ret = os.system("spd-say \"Speech Dispatcher debugging 1\"")
         if not ret:
             os.system("spd-say \"Speech Dispatcher debugging 2\"")
             os.system("spd-say \"Speech Dispatcher debugging 3\"")
         else:
-            report("Can't test Speech Dispatcher connection, can't connect")
+            report(_("Can't test Speech Dispatcher connection, can't connect"))
 
-        report("Please wait (about 5 seconds)")
+        report(_("Please wait (about 5 seconds)"))
         time.sleep(5)
 
-        report("Collecting debugging output and your configuration 
information") 
+        report(_("Collecting debugging output and your configuration 
information") )
 
         os.system("umask 077")
         os.system("tar -cz %s %s > %s" % 
@@ -610,10 +613,10 @@ Please start your system Speech Dispatcher now with 
parameter '-D'""")
         os.system("killall speech-dispatch")
         os.system("rm -rf %s" % debugdir_path)
 
-        report("""
+        report(_("""
 Please send %s to speechd at bugs.freebsoft.org with
 a short description of what you did. We will get in touch with you soon
-and suggest a solution.""" % debugarchive_path)
+and suggest a solution.""" % debugarchive_path))
         
 test = Tests()
 
@@ -684,36 +687,36 @@ class Configure:
         if test.user_conf_dir_exists():
             if test.user_configuration_seems_complete():
                 reply = question(
-                    "User configuration already exists."
-                    "Do you want to rewrite it with a new one?", False)
+                    _("User configuration already exists.")
+                    _("Do you want to rewrite it with a new one?"), False)
                 if reply == False:
-                    report("Keeping configuration intact and continuing with 
settings.")
+                    report(_("Keeping configuration intact and continuing with 
settings."))
                     return
                 else:
                     self.remove_user_configuration()
             else:
                 reply = question(
-                    "User configuration already exists, but it seems to be 
incomplete."
-                    "Do you want to keep it?", False)
+                    _("User configuration already exists, but it seems to be 
incomplete.")
+                    _("Do you want to keep it?"), False)
                 if reply == False:
                     self.remove_user_configuration()
                 else:
-                    report("Keeping configuration intact and aborting.")
+                    report(_("Keeping configuration intact and aborting."))
                     return
         # Copy the original intact configuration files
         # creating a conf/ subdirectory
         shutil.copytree(paths.SPD_CONF_ORIG_PATH, test.user_conf_dir())
         
-        report("User configuration created in %s" % test.user_conf_dir())
+        report(_("User configuration created in %s" % test.user_conf_dir()))
 
     def configure_basic_settings(self, type='user'):
         """Ask for basic settings and rewrite them in the configuration file"""
 
         if type == 'user':
-            report("Configuring user settings for Speech Dispatcher")
+            report(_("Configuring user settings for Speech Dispatcher"))
         elif type == 'system':
-            report("Warning: You must be root or under sudo to do this.")
-            report("Configuring system settings for Speech Dispatcher")
+            report(_("Warning: You must be root or under sudo to do this."))
+            report(_("Configuring system settings for Speech Dispatcher"))
         else:
             raise ValueError("Invalid configuration type")
 
@@ -733,15 +736,15 @@ class Configure:
             ["pulse", "libao", "alsa", "oss", "pulse,alsa"])
 
         self.default_speech_rate = question(
-            "Default speech rate (on the scale of -100..100, 0 is default, 50 
is faster, -50 is slower)",
+            _("Default speech rate (on the scale of -100..100, 0 is default, 
50 is faster, -50 is slower)"),
             "0")
 
         self.default_speech_pitch = question(
-            "Default speech pitch (on the scale of -100..100, 0 is default, 50 
is higher, -50 is lower)",
+            _("Default speech pitch (on the scale of -100..100, 0 is default, 
50 is higher, -50 is lower)"),
             "0")
     
         self.default_speech_pitch_range = question(
-            "Default speech pitch range (on the scale of -100..100, 0 is 
default, 50 is higher, -50 is lower)",
+            _("Default speech pitch range (on the scale of -100..100, 0 is 
default, 50 is higher, -50 is lower)"),
             "0")
     
         # Substitute given configuration options
@@ -761,36 +764,36 @@ class Configure:
                                  })
         if type == 'user':
             self.setup_autostart = question(
-                """Do you want to have Speech Dispatcher automatically started 
from ~/.config/autostart ?
-This is usually not necessary, most applications will start Speech Dispatcher 
automatically.""",
+                _("""Do you want to have Speech Dispatcher automatically 
started from ~/.config/autostart ?
+This is usually not necessary, most applications will start Speech Dispatcher 
automatically."""),
                 False)
             if self.setup_autostart:
                 os.system("""cp %s ~/.config/autostart/""" % 
os.path.join(paths.SPD_DESKTOP_CONF_PATH,
                                                                           
"speechd.desktop")) 
                          
-                report("""
+                report(_("""
 Configuration written to %s
 Basic configuration now complete. You might still need to fine tune it by
 manually editing the configuration file above. Especially if you need to
-use special audio settings, non-standard synthesizer ports etc.""" % 
configfile)
+use special audio settings, non-standard synthesizer ports etc.""" % 
configfile))
 
     def speechd_start_user(self):
         """Start Speech Dispatcher in user-mode"""
 
-        report("Starting Speech Dispatcher in user-mode")
+        report(_("Starting Speech Dispatcher in user-mode"))
 
         err = os.system("speech-dispatcher")
         if err:
-            report("Can't start Speech Dispatcher. Exited with status %d" % 
err)
-            reply = question("""Perhaps this is because your Speech Dispatcher 
is already running.
-Do you want to kill all running Speech Dispatchers and try again?""", True)
+            report(_("Can't start Speech Dispatcher. Exited with status %d" % 
err))
+            reply = question(_("""Perhaps this is because your Speech 
Dispatcher is already running.
+Do you want to kill all running Speech Dispatchers and try again?"""), True)
             if reply:
                 os.system("killall speech-dispatcher")
                 # Attempt to workaround the psmisc 22.15 bug with 16 char max 
process names
                 os.system("killall speech-dispatch")
                 err = os.system("speech-dispatcher")
                 if err:
-                    report("Can't start Speech Dispatcher")
+                    report(_("Can't start Speech Dispatcher"))
                     return False
             else:
                 return False
@@ -799,25 +802,25 @@ Do you want to kill all running Speech Dispatchers and 
try again?""", True)
     def speechd_start_system(self):
         """Start Speech Dispatcher in system-mode"""
 
-        report("Warning: You must be root or under sudo to do this.")        
-        report("Starting Speech Dispatcher in system-mode")
+        report(_("Warning: You must be root or under sudo to do this.")        
)
+        report(_("Starting Speech Dispatcher in system-mode"))
         
-        reply = question("Is your system using an 
/etc/init.d/speech-dispatcher script?",
+        reply = question(_("Is your system using an 
/etc/init.d/speech-dispatcher script?"),
                          True)
         if reply:
-            report("Stopping Speech Dispatcher in case any is running already")
+            report(_("Stopping Speech Dispatcher in case any is running 
already"))
             os.system("/etc/init.d/speech-dispatcher stop") 
-            report("Starting Speech Dispatcher via 
/etc/init.d/speech-dispatcher")
+            report(_("Starting Speech Dispatcher via 
/etc/init.d/speech-dispatcher"))
             ret = os.system("/etc/init.d/speech-dispatcher start")
             if ret:
-                report("Can't start Speech Dispatcher. Exited with status %d" 
% ret)
+                report(_("Can't start Speech Dispatcher. Exited with status 
%d" % ret))
                 return False
         else:
-            report("""Do not know how to start system Speech Dispatcher,
-you have to start it manually to continue.""")
-            reply = question("Have you started Speech Dispatcher now?", True)
+            report(_("""Do not know how to start system Speech Dispatcher,
+you have to start it manually to continue."""))
+            reply = question(_("Have you started Speech Dispatcher now?"), 
True)
             if not reply:
-                report("Can't continue")
+                report(_("Can't continue"))
                 return False
         return True
 
@@ -825,7 +828,7 @@ you have to start it manually to continue.""")
         """Create a complete configuration, run diagnosis and if necessary, 
debugging"""
 
         speechd_type = question_with_required_answers(
-            "Do you want to create/setup a 'user' or 'system' configuration",
+            _("Do you want to create/setup a 'user' or 'system' 
configuration"),
             'user', ['user', 'system'])
 
         if speechd_type == 'user':
@@ -836,9 +839,9 @@ you have to start it manually to continue.""")
         else:
             raise ValueError("Invalid configuration type")
 
-        reply = question("Do you want to start/restart Speech Dispatcher now 
and run some tests?", True)
+        reply = question(_("Do you want to start/restart Speech Dispatcher now 
and run some tests?"), True)
         if not reply:
-            report("Your configuration is now done but not tested")
+            report(_("Your configuration is now done but not tested"))
             return
         else:
             if speechd_type == 'user':
@@ -847,7 +850,7 @@ you have to start it manually to continue.""")
                 started = self.speechd_start_system()
 
         if not started:
-            report("Your Speech Dispatcher is not running")
+            report(_("Your Speech Dispatcher is not running"))
             
         result = test.diagnostics(speechd_running = started,
                                   audio_output=[self.default_audio_method],
@@ -855,7 +858,7 @@ you have to start it manually to continue.""")
         test.write_diagnostics_results(result)
 
         if not started:
-            reply = question("Do you want to run debugging now and send a 
request for help to the developers?",
+            reply = question(_("Do you want to run debugging now and send a 
request for help to the developers?"),
                              False)
             if reply:
                 test.debug_and_report(type=speechd_type)
@@ -869,12 +872,12 @@ test = Tests()
 
 def main():
 
-    report("\nSpeech Dispatcher configuration tool\n")
+    report(-("\nSpeech Dispatcher configuration tool\n"))
     
     if options.create_user_configuration:
         # Check for and/or create basic user configuration
         configure.create_user_configuration()
-        reply = question("Do you want to continue with basic settings?", True)
+        reply = question(_("Do you want to continue with basic settings?"), 
True)
         if reply:
             configure.configure_basic_settings(type='user')
     elif options.config_basic_settings_user:
@@ -906,17 +909,17 @@ def main():
         test.debug_and_report()
 
     else:
-        reply = question("Do you want to setup a completely new 
configuration?", True)
+        reply = question(_("Do you want to setup a completely new 
configuration?"), True)
         if reply:
             configure.complete_config()
         else:
-            reply = question("Do you want to run diagnosis of problems?", True)
+            reply = question(_("Do you want to run diagnosis of problems?"), 
True)
             if reply:
                 ret=test.diagnostics()
                 test.write_diagnostics_results(ret)
             else:
-                report("""Please run this command again and select what you 
want to do
-or read the quick help available through '-h' or '--help'.""")
+                report(_("""Please run this command again and select what you 
want to do
+or read the quick help available through '-h' or '--help'."""))
 
 if __name__ == "__main__":
     sys.exit(main())
diff --git a/src/api/python/speechd_config/i18n.py.in 
b/src/api/python/speechd_config/i18n.py.in
new file mode 100644
index 0000000..b6fc2b4
--- /dev/null
+++ b/src/api/python/speechd_config/i18n.py.in
@@ -0,0 +1,8 @@
+import gettext
+import locale
+
+_ = gettext.gettext
+
+locale.setlocale(locale.LC_ALL, '')
+gettext.bindtextdomain ("@GETTEXT_PACKAGE@", "@localedir@")
+gettext.textdomain("@GETTEXT_PACKAGE@")
-- 
2.1.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]