From 078cafc0c8871a778d47bf66ed5ba2bdc0aa3963 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 4 Jun 2005 19:08:38 +0000 Subject: [PATCH] * src/DateHandler.py: handle generic "en", "fr" cases as a fallback if the unknown "yy_XX" code is passed. Try yy if yy_XX fails. * src/dates/Date_*.py: add a default xx case svn: r4783 --- gramps2/ChangeLog | 5 ++++ gramps2/src/DateHandler.py | 44 ++++++++++-------------------------- gramps2/src/dates/Date_de.py | 8 ++----- gramps2/src/dates/Date_es.py | 2 +- gramps2/src/dates/Date_fi.py | 2 +- gramps2/src/dates/Date_fr.py | 2 +- gramps2/src/dates/Date_ru.py | 2 +- 7 files changed, 23 insertions(+), 42 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e50b8973c..62c8fe765 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,8 @@ +2005-06-04 Don Allingham + * src/DateHandler.py: handle generic "en", "fr" cases as a fallback + if the unknown "yy_XX" code is passed. Try yy if yy_XX fails. + * src/dates/Date_*.py: add a default xx case + 2005-06-03 Don Allingham * src/DateHandler.py: add more English locales * src/dates/Date_fi.py: fix estimated/calculated, handle span diff --git a/gramps2/src/DateHandler.py b/gramps2/src/DateHandler.py index 38002d9ab..86606bbe7 100644 --- a/gramps2/src/DateHandler.py +++ b/gramps2/src/DateHandler.py @@ -46,44 +46,18 @@ import DateDisplay # #------------------------------------------------------------------------- _lang = locale.getlocale(locale.LC_TIME)[0] +if _lang: + _lang_short = _lang.split('_')[0] +else: + _lang_short = "C" _lang_to_parser = { 'C' : DateParser.DateParser, - 'en_AU' : DateParser.DateParser, - 'en_BW' : DateParser.DateParser, - 'en_CA' : DateParser.DateParser, - 'en_DK' : DateParser.DateParser, - 'en_GB' : DateParser.DateParser, - 'en_HK' : DateParser.DateParser, - 'en_IE' : DateParser.DateParser, - 'en_IN' : DateParser.DateParser, - 'en_NZ' : DateParser.DateParser, - 'en_PH' : DateParser.DateParser, - 'en_SE' : DateParser.DateParser, - 'en_SG' : DateParser.DateParser, - 'en_US' : DateParser.DateParser, - 'en_ZA' : DateParser.DateParser, - 'en_ZW' : DateParser.DateParser, 'en' : DateParser.DateParser, } _lang_to_display = { 'C' : DateDisplay.DateDisplayEn, - 'en_AU' : DateDisplay.DateDisplayEn, - 'en_BW' : DateDisplay.DateDisplayEn, - 'en_CA' : DateDisplay.DateDisplayEn, - 'en_DK' : DateDisplay.DateDisplayEn, - 'en_GB' : DateDisplay.DateDisplayEn, - 'en_HK' : DateDisplay.DateDisplayEn, - 'en_IE' : DateDisplay.DateDisplayEn, - 'en_IN' : DateDisplay.DateDisplayEn, - 'en_NZ' : DateDisplay.DateDisplayEn, - 'en_PH' : DateDisplay.DateDisplayEn, - 'en_SE' : DateDisplay.DateDisplayEn, - 'en_SG' : DateDisplay.DateDisplayEn, - 'en_US' : DateDisplay.DateDisplayEn, - 'en_ZA' : DateDisplay.DateDisplayEn, - 'en_ZW' : DateDisplay.DateDisplayEn, 'en' : DateDisplay.DateDisplayEn, 'zh_CN' : DateDisplay.DateDisplay, 'zh_TW' : DateDisplay.DateDisplay, @@ -143,7 +117,10 @@ load_plugins(datesDir) #------------------------------------------------------------------------- try: - parser = _lang_to_parser[_lang]() + if _lang_to_parser.has_key(_lang): + parser = _lang_to_parser[_lang] + else: + parser = _lang_to_parser[_lang_short] except: print "Date parser for",_lang,"not available, using default" parser = _lang_to_parser["C"]() @@ -158,7 +135,10 @@ except: val = 0 try: - displayer = _lang_to_display[_lang](val) + if _lang_to_display.has_key(_lang): + displayer = _lang_to_display[_lang](val) + else: + displayer = _lang_to_display[_lang_short](val) except: print "Date displayer for",_lang,"not available, using default" displayer = _lang_to_display["C"](val) diff --git a/gramps2/src/dates/Date_de.py b/gramps2/src/dates/Date_de.py index 9f5e1fdc3..afd0e7586 100644 --- a/gramps2/src/dates/Date_de.py +++ b/gramps2/src/dates/Date_de.py @@ -224,9 +224,5 @@ class DateDisplayDE(DateDisplay): # #------------------------------------------------------------------------- from DateHandler import register_datehandler -register_datehandler(('de_DE','german'),DateParserDE, DateDisplayDE) -register_datehandler(('de_AT','german (Austria)'),DateParserDE, DateDisplayDE) -register_datehandler(('de_CH','german (Switzerland)'),DateParserDE, DateDisplayDE) -register_datehandler(('de_LI','german (Lichtenstein)'),DateParserDE, DateDisplayDE) -register_datehandler(('de_LU','german (Luxembourg)'),DateParserDE, DateDisplayDE) -register_datehandler(('de_BE','german (Belgium)'),DateParserDE, DateDisplayDE) +register_datehandler(('de_DE','german','de_AT','de_CH', + 'de_LI','de_LU','de_BE','de'),DateParserDE, DateDisplayDE) diff --git a/gramps2/src/dates/Date_es.py b/gramps2/src/dates/Date_es.py index 114a90b22..101794101 100644 --- a/gramps2/src/dates/Date_es.py +++ b/gramps2/src/dates/Date_es.py @@ -159,4 +159,4 @@ class DateDisplayES(DateDisplay): # #------------------------------------------------------------------------- from DateHandler import register_datehandler -register_datehandler(('es_ES','spanish'),DateParserES, DateDisplayES) +register_datehandler(('es_ES','es','spanish'),DateParserES, DateDisplayES) diff --git a/gramps2/src/dates/Date_fi.py b/gramps2/src/dates/Date_fi.py index c20293138..6640a1a8e 100644 --- a/gramps2/src/dates/Date_fi.py +++ b/gramps2/src/dates/Date_fi.py @@ -177,5 +177,5 @@ class DateDisplayFI(DateDisplay): # #------------------------------------------------------------------------- from DateHandler import register_datehandler -register_datehandler(('fi_FI','finnish'), DateParserFI, DateDisplayFI) +register_datehandler(('fi_FI','fi','finnish'), DateParserFI, DateDisplayFI) diff --git a/gramps2/src/dates/Date_fr.py b/gramps2/src/dates/Date_fr.py index 8b58cf254..cbef84b22 100644 --- a/gramps2/src/dates/Date_fr.py +++ b/gramps2/src/dates/Date_fr.py @@ -153,4 +153,4 @@ class DateDisplayFR(DateDisplay): # #------------------------------------------------------------------------- from DateHandler import register_datehandler -register_datehandler(('fr_FR','french'),DateParserFR, DateDisplayFR) +register_datehandler(('fr_FR','fr','french'),DateParserFR, DateDisplayFR) diff --git a/gramps2/src/dates/Date_ru.py b/gramps2/src/dates/Date_ru.py index ffd1abb1f..15eaa5899 100644 --- a/gramps2/src/dates/Date_ru.py +++ b/gramps2/src/dates/Date_ru.py @@ -168,4 +168,4 @@ class DateDisplayRU(DateDisplay): # #------------------------------------------------------------------------- from DateHandler import register_datehandler -register_datehandler(('ru_RU','russian'),DateParserRU, DateDisplayRU) +register_datehandler(('ru_RU','ru','russian'),DateParserRU, DateDisplayRU)