From b4317bba2ad2a216d4b82739ff9e799e0aa26cfe Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sun, 15 Aug 2010 20:50:49 +0200 Subject: [PATCH 1/2] auto-detect language --- pyfpdb/Anonymise.py | 15 ++++++++++++--- pyfpdb/BetfairToFpdb.py | 15 ++++++++++++--- pyfpdb/Card.py | 15 ++++++++++++--- pyfpdb/GuiBulkImport.py | 15 ++++++++++++--- pyfpdb/GuiDatabase.py | 15 ++++++++++++--- pyfpdb/GuiLogView.py | 15 ++++++++++++--- pyfpdb/HUD_main.pyw | 15 ++++++++++++--- pyfpdb/HandHistoryConverter.py | 15 ++++++++++++--- pyfpdb/ImapFetcher.py | 15 ++++++++++++--- pyfpdb/Options.py | 15 ++++++++++++--- pyfpdb/Tables_Demo.py | 15 ++++++++++++--- pyfpdb/fpdb.pyw | 15 ++++++++++++--- pyfpdb/locale/{de_DE => de}/LC_MESSAGES/fpdb.mo | Bin pyfpdb/windows_make_bats.py | 15 ++++++++++++--- 14 files changed, 156 insertions(+), 39 deletions(-) rename pyfpdb/locale/{de_DE => de}/LC_MESSAGES/fpdb.mo (100%) diff --git a/pyfpdb/Anonymise.py b/pyfpdb/Anonymise.py index a4d72339..32878900 100755 --- a/pyfpdb/Anonymise.py +++ b/pyfpdb/Anonymise.py @@ -23,9 +23,18 @@ import HandHistoryConverter import Configuration import sys -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 (options, argv) = Options.fpdb_options() config = Configuration.Config() diff --git a/pyfpdb/BetfairToFpdb.py b/pyfpdb/BetfairToFpdb.py index 34316de2..4a5f8b5c 100755 --- a/pyfpdb/BetfairToFpdb.py +++ b/pyfpdb/BetfairToFpdb.py @@ -22,9 +22,18 @@ import sys import logging from HandHistoryConverter import * -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 # Betfair HH format diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 81edfb9c..6bdf3e8b 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -15,9 +15,18 @@ #along with this program. If not, see . #In the "official" distribution you can find the license in agpl-3.0.txt. -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 # From fpdb_simple card_map = { "0": 0, "2": 2, "3" : 3, "4" : 4, "5" : 5, "6" : 6, "7" : 7, "8" : 8, diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index a40f8929..e7132018 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -33,9 +33,18 @@ import fpdb_import import Configuration import Exceptions -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 class GuiBulkImport(): diff --git a/pyfpdb/GuiDatabase.py b/pyfpdb/GuiDatabase.py index 2529643b..c6cf926e 100755 --- a/pyfpdb/GuiDatabase.py +++ b/pyfpdb/GuiDatabase.py @@ -35,9 +35,18 @@ import Exceptions import Database import SQL -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 class GuiDatabase: diff --git a/pyfpdb/GuiLogView.py b/pyfpdb/GuiLogView.py index af8c3d34..cd901eef 100755 --- a/pyfpdb/GuiLogView.py +++ b/pyfpdb/GuiLogView.py @@ -30,9 +30,18 @@ import logging # logging has been set up in fpdb.py or HUD_main.py, use their settings: log = logging.getLogger("logview") -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 MAX_LINES = 100000 # max lines to display in window EST_CHARS_PER_LINE = 150 # used to guesstimate number of lines in log file diff --git a/pyfpdb/HUD_main.pyw b/pyfpdb/HUD_main.pyw index cc90a641..590f9291 100755 --- a/pyfpdb/HUD_main.pyw +++ b/pyfpdb/HUD_main.pyw @@ -60,9 +60,18 @@ elif os.name == 'nt': #import Tables import Hud -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 # get config and set up logger c = Configuration.Config(file=options.config, dbname=options.dbname) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 8265dbfd..91ac373d 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -41,9 +41,18 @@ import Hand from Exceptions import FpdbParseError import Configuration -#import gettext -#trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -#trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 import pygtk import gtk diff --git a/pyfpdb/ImapFetcher.py b/pyfpdb/ImapFetcher.py index ee267cf9..e43f799b 100755 --- a/pyfpdb/ImapFetcher.py +++ b/pyfpdb/ImapFetcher.py @@ -22,9 +22,18 @@ from imaplib import IMAP4, IMAP4_SSL import PokerStarsSummary -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 def splitPokerStarsSummaries(emailText): splitSummaries=emailText.split("\nPokerStars Tournament #")[1:] diff --git a/pyfpdb/Options.py b/pyfpdb/Options.py index 23656ff2..268009c1 100644 --- a/pyfpdb/Options.py +++ b/pyfpdb/Options.py @@ -19,9 +19,18 @@ import sys from optparse import OptionParser # http://docs.python.org/library/optparse.html -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 def fpdb_options(): diff --git a/pyfpdb/Tables_Demo.py b/pyfpdb/Tables_Demo.py index 33a586aa..45013120 100755 --- a/pyfpdb/Tables_Demo.py +++ b/pyfpdb/Tables_Demo.py @@ -36,9 +36,18 @@ import gobject import Configuration from HandHistoryConverter import getTableTitleRe -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 # get the correct module for the current os if os.name == 'posix': diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index 4860dee1..e04d6af6 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -20,9 +20,18 @@ import sys import re import Queue -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 # if path is set to use an old version of python look for a new one: # (does this work in linux?) diff --git a/pyfpdb/locale/de_DE/LC_MESSAGES/fpdb.mo b/pyfpdb/locale/de/LC_MESSAGES/fpdb.mo similarity index 100% rename from pyfpdb/locale/de_DE/LC_MESSAGES/fpdb.mo rename to pyfpdb/locale/de/LC_MESSAGES/fpdb.mo diff --git a/pyfpdb/windows_make_bats.py b/pyfpdb/windows_make_bats.py index 976040c1..de6a970b 100755 --- a/pyfpdb/windows_make_bats.py +++ b/pyfpdb/windows_make_bats.py @@ -17,9 +17,18 @@ # create .bat scripts in windows to try out different gtk dirs -import gettext -trans = gettext.translation("fpdb", localedir="locale", languages=["de_DE"]) -trans.install() +import locale +lang=locale.getdefaultlocale()[0][0:2] +print "lang:", lang +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 try: From b08cb18c0e60d025453e798a90f8ff5973885fbc Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sun, 15 Aug 2010 21:09:18 +0200 Subject: [PATCH 2/2] remove debug print; add import to Config; gettextify tables --- pyfpdb/Anonymise.py | 1 - pyfpdb/BetfairToFpdb.py | 1 - pyfpdb/Card.py | 1 - pyfpdb/Configuration.py | 12 ++++++++++++ pyfpdb/GuiBulkImport.py | 1 - pyfpdb/GuiDatabase.py | 1 - pyfpdb/GuiLogView.py | 1 - pyfpdb/HandHistoryConverter.py | 1 - pyfpdb/ImapFetcher.py | 1 - pyfpdb/Options.py | 1 - pyfpdb/Tables.py | 19 +++++++++++++++---- pyfpdb/Tables_Demo.py | 1 - pyfpdb/TourneyFilters.py | 8 ++++---- pyfpdb/fpdb.pyw | 1 - pyfpdb/windows_make_bats.py | 1 - 15 files changed, 31 insertions(+), 20 deletions(-) diff --git a/pyfpdb/Anonymise.py b/pyfpdb/Anonymise.py index 32878900..3281fa3f 100755 --- a/pyfpdb/Anonymise.py +++ b/pyfpdb/Anonymise.py @@ -25,7 +25,6 @@ import sys import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/BetfairToFpdb.py b/pyfpdb/BetfairToFpdb.py index 4a5f8b5c..07ee2612 100755 --- a/pyfpdb/BetfairToFpdb.py +++ b/pyfpdb/BetfairToFpdb.py @@ -24,7 +24,6 @@ from HandHistoryConverter import * import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 6bdf3e8b..576a7b38 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -17,7 +17,6 @@ import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 38b4544d..53ccaa56 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -36,6 +36,18 @@ import re import xml.dom.minidom from xml.dom.minidom import Node +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 + import logging, logging.config import ConfigParser diff --git a/pyfpdb/GuiBulkImport.py b/pyfpdb/GuiBulkImport.py index e7132018..9b88a12f 100755 --- a/pyfpdb/GuiBulkImport.py +++ b/pyfpdb/GuiBulkImport.py @@ -35,7 +35,6 @@ import Exceptions import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/GuiDatabase.py b/pyfpdb/GuiDatabase.py index c6cf926e..0f7cdab1 100755 --- a/pyfpdb/GuiDatabase.py +++ b/pyfpdb/GuiDatabase.py @@ -37,7 +37,6 @@ import SQL import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/GuiLogView.py b/pyfpdb/GuiLogView.py index cd901eef..f42db9e2 100755 --- a/pyfpdb/GuiLogView.py +++ b/pyfpdb/GuiLogView.py @@ -32,7 +32,6 @@ log = logging.getLogger("logview") import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 91ac373d..eb1d7de8 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -43,7 +43,6 @@ import Configuration import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/ImapFetcher.py b/pyfpdb/ImapFetcher.py index e43f799b..006f9894 100755 --- a/pyfpdb/ImapFetcher.py +++ b/pyfpdb/ImapFetcher.py @@ -24,7 +24,6 @@ import PokerStarsSummary import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/Options.py b/pyfpdb/Options.py index 268009c1..11ef9d43 100644 --- a/pyfpdb/Options.py +++ b/pyfpdb/Options.py @@ -21,7 +21,6 @@ from optparse import OptionParser import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index c33b1828..3ffc7d1a 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -29,8 +29,19 @@ import os import sys import re -# Win32 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 +# Win32 modules if os.name == 'nt': import win32gui import win32process @@ -220,7 +231,7 @@ def discover_nt(c): tw.site = "Full Tilt" else: tw.site = "Unknown" - sys.stderr.write("Found unknown table = %s" % tw.title) + sys.stderr.write(_("Found unknown table = %s") % tw.title) if tw.site != "Unknown": eval("%s(tw)" % c.supported_sites[tw.site].decoder) else: @@ -247,7 +258,7 @@ def discover_nt_by_name(c, tablename): if 'Chat:' in titles[hwnd]: continue # Some sites (FTP? PS? Others?) have seperable or seperately constructed chat windows if ' - Table ' in titles[hwnd]: continue # Absolute table Chat window.. sigh. TODO: Can we tell what site we're trying to discover for somehow in here, so i can limit this check just to AP searches? temp = decode_windows(c, titles[hwnd], hwnd) - print "attach to window", temp + print _("attach to window"), temp return temp return None @@ -434,5 +445,5 @@ if __name__=="__main__": for t in tables.keys(): print tables[t] - print "press enter to continue" + print _("press enter to continue") sys.stdin.readline() diff --git a/pyfpdb/Tables_Demo.py b/pyfpdb/Tables_Demo.py index 45013120..f583ae48 100755 --- a/pyfpdb/Tables_Demo.py +++ b/pyfpdb/Tables_Demo.py @@ -38,7 +38,6 @@ from HandHistoryConverter import getTableTitleRe import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/TourneyFilters.py b/pyfpdb/TourneyFilters.py index 774c64c7..92b86ef3 100644 --- a/pyfpdb/TourneyFilters.py +++ b/pyfpdb/TourneyFilters.py @@ -45,9 +45,9 @@ class TourneyFilters(Filters.Filters): self.conf = db.config self.display = display - self.filterText = {'playerstitle':'Hero:', 'sitestitle':'Sites:', 'seatstitle':'Number of Players:', - 'seatsbetween':'Between:', 'seatsand':'And:', 'datestitle':'Date:', - 'tourneyTypesTitle':'Tourney Type'} + self.filterText = {'playerstitle':_('Hero:'), 'sitestitle':_('Sites:'), 'seatstitle':_('Number of Players:'), + 'seatsbetween':_('Between:'), 'seatsand':_('And:'), 'datestitle':_('Date:'), + 'tourneyTypesTitle':_('Tourney Type')} gen = self.conf.get_general_params() self.day_start = 0 @@ -102,7 +102,7 @@ class TourneyFilters(Filters.Filters): if len(result) == 1: self.siteid[site] = result[0][0] else: - print "Either 0 or more than one site matched (%s) - EEK" % site + print _("Either 0 or more than one site matched (%s) - EEK") % site # For use in date ranges. self.start_date = gtk.Entry(max=12) diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index e04d6af6..f0d73b8f 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -22,7 +22,6 @@ import Queue import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: diff --git a/pyfpdb/windows_make_bats.py b/pyfpdb/windows_make_bats.py index de6a970b..39449fc7 100755 --- a/pyfpdb/windows_make_bats.py +++ b/pyfpdb/windows_make_bats.py @@ -19,7 +19,6 @@ import locale lang=locale.getdefaultlocale()[0][0:2] -print "lang:", lang if lang=="en": def _(string): return string else: