From b4317bba2ad2a216d4b82739ff9e799e0aa26cfe Mon Sep 17 00:00:00 2001 From: steffen123 Date: Sun, 15 Aug 2010 20:50:49 +0200 Subject: [PATCH] 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: