From 7a5340f2d8fc8b16850f8e7561296160851ffefb Mon Sep 17 00:00:00 2001 From: steffen123 Date: Mon, 16 Aug 2010 02:57:03 +0200 Subject: [PATCH] gettextify fpdb_import.py --- pyfpdb/fpdb_import.py | 61 +++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index cbe87684..03fbbe48 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -35,8 +35,19 @@ log = logging.getLogger("importer") import pygtk import gtk -# fpdb/FreePokerTools modules +import locale +lang=locale.getdefaultlocale()[0][0:2] +if lang=="en": + def _(string): return string +else: + import gettext + try: + trans = gettext.translation("fpdb", localedir="locale", languages=[lang]) + trans.install() + except IOError: + def _(string): return string +# fpdb/FreePokerTools modules import Database import Configuration import Exceptions @@ -46,14 +57,14 @@ import Exceptions try: import MySQLdb except ImportError: - log.debug("Import database module: MySQLdb not found") + log.debug(_("Import database module: MySQLdb not found")) else: mysqlLibFound = True try: import psycopg2 except ImportError: - log.debug("Import database module: psycopg2 not found") + log.debug(_("Import database module: psycopg2 not found")) else: import psycopg2.extensions psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) @@ -164,9 +175,9 @@ class Importer: self.siteIds[site] = result[0][0] else: if len(result) == 0: - log.error("Database ID for %s not found" % site) + log.error(_("Database ID for %s not found") % site) else: - log.error("[ERROR] More than 1 Database ID found for %s - Multiple currencies not implemented yet" % site) + log.error(_("[ERROR] More than 1 Database ID found for %s - Multiple currencies not implemented yet") % site) # Called from GuiBulkImport to add a file or directory. @@ -202,7 +213,7 @@ class Importer: #print " adding file ", file self.addImportFile(os.path.join(dir, file), site, filter) else: - log.warning("Attempted to add non-directory: '%s' as an import directory" % str(dir)) + log.warning(_("Attempted to add non-directory: '%s' as an import directory") % str(dir)) def runImport(self): """"Run full import on self.filelist. This is called from GuiBulkImport.py""" @@ -212,7 +223,7 @@ class Importer: # Initial setup start = datetime.datetime.now() starttime = time() - log.info("Started at %s -- %d files to import. indexes: %s" % (start, len(self.filelist), self.settings['dropIndexes'])) + log.info(_("Started at %s -- %d files to import. indexes: %s") % (start, len(self.filelist), self.settings['dropIndexes'])) if self.settings['dropIndexes'] == 'auto': self.settings['dropIndexes'] = self.calculate_auto2(self.database, 12.0, 500.0) if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'auto': @@ -221,7 +232,7 @@ class Importer: if self.settings['dropIndexes'] == 'drop': self.database.prepareBulkImport() else: - log.debug("No need to drop indexes.") + log.debug(_("No need to drop indexes.")) #print "dropInd =", self.settings['dropIndexes'], " dropHudCache =", self.settings['dropHudCache'] if self.settings['threads'] <= 0: @@ -240,10 +251,10 @@ class Importer: (totstored, totdups, totpartial, toterrors) = self.importFiles(self.database, self.writeq) if self.writeq.empty(): - print "writers finished already" + print _("writers finished already") pass else: - print "waiting for writers to finish ..." + print _("waiting for writers to finish ...") #for t in threading.enumerate(): # print " "+str(t) #self.writeq.join() @@ -253,17 +264,17 @@ class Importer: while gtk.events_pending(): # see http://faq.pygtk.org/index.py?req=index for more hints (3.7) gtk.main_iteration(False) sleep(0.5) - print " ... writers finished" + print _(" ... writers finished") # Tidying up after import if self.settings['dropIndexes'] == 'drop': self.database.afterBulkImport() else: - print "No need to rebuild indexes." + print _("No need to rebuild indexes.") if 'dropHudCache' in self.settings and self.settings['dropHudCache'] == 'drop': self.database.rebuild_hudcache() else: - print "No need to rebuild hudcache." + print _("No need to rebuild hudcache.") self.database.analyzeDB() endtime = time() return (totstored, totdups, totpartial, toterrors, endtime-starttime) @@ -288,7 +299,7 @@ class Importer: toterrors += errors for i in xrange( self.settings['threads'] ): - print "sending finish msg qlen =", q.qsize() + print _("sending finish msg qlen ="), q.qsize() db.send_finish_msg(q) return (totstored, totdups, totpartial, toterrors) @@ -414,9 +425,9 @@ class Importer: # Load filter, process file, pass returned filename to import_fpdb_file if self.settings['threads'] > 0 and self.writeq is not None: - log.info("Converting " + file + " (" + str(q.qsize()) + ")") + log.info(_("Converting ") + file + " (" + str(q.qsize()) + ")") else: - log.info("Converting " + file) + log.info(_("Converting ") + file) hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = os.path.expanduser(hhbase) hhdir = os.path.join(hhbase,site) @@ -452,7 +463,7 @@ class Importer: if self.callHud and hand.dbid_hands != 0: to_hud.append(hand.dbid_hands) else: # TODO: Treat empty as an error, or just ignore? - log.error("Hand processed but empty") + log.error(_("Hand processed but empty")) # Call hudcache update if not in bulk import mode # FIXME: Need to test for bulk import that isn't rebuilding the cache @@ -465,10 +476,10 @@ class Importer: #pipe the Hands.id out to the HUD for hid in to_hud: try: - print "fpdb_import: sending hand to hud", hand.dbid_hands, "pipe =", self.caller.pipe_to_hud + print _("fpdb_import: sending hand to hud"), hand.dbid_hands, "pipe =", self.caller.pipe_to_hud self.caller.pipe_to_hud.stdin.write("%s" % (hid) + os.linesep) except IOError, e: - log.error("Failed to send hand to HUD: %s" % e) + log.error(_("Failed to send hand to HUD: %s") % e) errors = getattr(hhc, 'numErrors') stored = getattr(hhc, 'numHands') @@ -479,7 +490,7 @@ class Importer: # TODO: appropriate response? return (0, 0, 0, 1, time() - ttime) else: - log.warning("Unknown filter filter_name:'%s' in filter:'%s'" %(filter_name, filter)) + log.warning(_("Unknown filter filter_name:'%s' in filter:'%s'") %(filter_name, filter)) return (0, 0, 0, 1, time() - ttime) ttime = time() - ttime @@ -490,11 +501,11 @@ class Importer: def printEmailErrorMessage(self, errors, filename, line): traceback.print_exc(file=sys.stderr) - print "Error No.",errors,", please send the hand causing this to fpdb-main@lists.sourceforge.net so we can fix the problem." - print "Filename:", filename - print "Here is the first line of the hand so you can identify it. Please mention that the error was a ValueError:" + print (_("Error No.%s please send the hand causing this to fpdb-main@lists.sourceforge.net so we can fix the problem.") % errors) + print _("Filename:"), filename + print _("Here is the first line of the hand so you can identify it. Please mention that the error was a ValueError:") print self.hand[0] - print "Hand logged to hand-errors.txt" + print _("Hand logged to hand-errors.txt") logfile = open('hand-errors.txt', 'a') for s in self.hand: logfile.write(str(s) + "\n") @@ -502,4 +513,4 @@ class Importer: logfile.close() if __name__ == "__main__": - print "CLI for fpdb_import is now available as CliFpdb.py" + print _("CLI for fpdb_import is now available as CliFpdb.py")