diff --git a/ChangeLog b/ChangeLog index 70c4c7a9a..ea22cb4a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-11-08 Don Allingham + * src/DateHandler.py: add handlers for fr_FR + * src/DateParser.py: add parser for french + * src/DateDisplay.py: add displayer for french + +2004-11-08 Steve Swales + * src/gramps.py: Better way of setting locale + * src/DateHandler.py: Better locate settings + 2004-11-08 Alex Roitman * src/data/Makefile.am: Remove gramps.desktop from dist_pkgdata_DATA which was causing it to get installed diff --git a/src/DateDisplay.py b/src/DateDisplay.py index e30762180..44c9856a8 100644 --- a/src/DateDisplay.py +++ b/src/DateDisplay.py @@ -296,3 +296,39 @@ class DateDisplay: def _display_islamic(self,date_val): return self._display_calendar(date_val,self._islamic) +class DateDisplayFR(DateDisplay): + + calendar = ( + u"", u" (Julien)", u" (H\xe9breu)", + u" (R\xe9volutionnaire)", u" (Perse)", u" (Islamique)" + ) + + _mod_str = (u"",u"avant ",u"apr\xe8s ",u"vers ",u"",u"",u"") + + def display(self,date): + """ + Returns a text string representing the date. + """ + mod = date.get_modifier() + cal = date.get_calendar() + qual = date.get_quality() + start = date.get_start_date() + + qual_str = self._qual_str[qual] + + if mod == Date.MOD_TEXTONLY: + return date.get_text() + elif start == Date.EMPTY: + return u"" + elif mod == Date.MOD_SPAN: + d1 = self.display_cal[cal](start) + d2 = self.display_cal[cal](date.get_stop_date()) + return u"%sde %s \xe0 %s%s" % (qual_str,d1,d2,self.calendar[cal]) + elif mod == Date.MOD_RANGE: + d1 = self.display_cal[cal](start) + d2 = self.display_cal[cal](date.get_stop_date()) + return u"%sentre %s et %s%s" % (qual_str,d1,d2,self.calendar[cal]) + else: + text = self.display_cal[date.get_calendar()](start) + return u"%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) + diff --git a/src/DateHandler.py b/src/DateHandler.py index 422ed23f8..622029d4a 100644 --- a/src/DateHandler.py +++ b/src/DateHandler.py @@ -30,6 +30,7 @@ Class handling language-specific selection for date parser and displayer. # #------------------------------------------------------------------------- import os +import locale #------------------------------------------------------------------------- # @@ -45,11 +46,11 @@ import DateDisplay # Constants # #------------------------------------------------------------------------- -_lang = os.environ.get('LANG','C').split('.')[0] - +_lang = locale.getlocale(locale.LC_TIME)[0] _lang_to_parser = { 'C' : DateParser.DateParser, + 'fr_FR' : DateParser.DateParserFR, 'en_US' : DateParser.DateParser, 'en_GB' : DateParser.DateParser, 'en_AU' : DateParser.DateParser, @@ -60,6 +61,7 @@ _lang_to_parser = { _lang_to_display = { 'C' : DateDisplay.DateDisplay, + 'fr_FR' : DateDisplay.DateDisplayFR, 'en_US' : DateDisplay.DateDisplay, 'en_GB' : DateDisplay.DateDisplay, 'en_AU' : DateDisplay.DateDisplay, diff --git a/src/DateParser.py b/src/DateParser.py index f2e4f6bf8..6e59c8d16 100644 --- a/src/DateParser.py +++ b/src/DateParser.py @@ -486,6 +486,53 @@ class DateParser: self.set_date(new_date,text) return new_date +class DateParserFR(DateParser): + + modifier_to_int = { + u'avant' : Date.MOD_BEFORE, + u'av.' : Date.MOD_BEFORE, + u'av' : Date.MOD_BEFORE, + u'apr\xe8s' : Date.MOD_AFTER, + u'ap.' : Date.MOD_AFTER, + u'ap' : Date.MOD_AFTER, + u'env.' : Date.MOD_ABOUT, + u'env' : Date.MOD_ABOUT, + u'circa' : Date.MOD_ABOUT, + u'c.' : Date.MOD_ABOUT, + u'vers' : Date.MOD_ABOUT, + } + + calendar_to_int = { + u'gr\xe9gorien' : Date.CAL_GREGORIAN, + u'g' : Date.CAL_GREGORIAN, + u'julien' : Date.CAL_JULIAN, + u'j' : Date.CAL_JULIAN, + u'h\xe9breu' : Date.CAL_HEBREW, + u'h' : Date.CAL_HEBREW, + u'islamique' : Date.CAL_ISLAMIC, + u'i' : Date.CAL_ISLAMIC, + u'r\xe9volutionnaire': Date.CAL_FRENCH, + u'r' : Date.CAL_FRENCH, + u'perse' : Date.CAL_PERSIAN, + u'p' : Date.CAL_PERSIAN, + } + + quality_to_int = { + u'estimated' : Date.QUAL_ESTIMATED, + u'est.' : Date.QUAL_ESTIMATED, + u'est' : Date.QUAL_ESTIMATED, + u'calc.' : Date.QUAL_CALCULATED, + u'calc' : Date.QUAL_CALCULATED, + u'calculated' : Date.QUAL_CALCULATED, + } + + _span = re.compile("de\s+(.+)\s+\xe0\s+(.+)", + re.IGNORECASE) + _range = re.compile("(ent.|ent|entre)\s+(.+)\s+et\s+(.+)", + re.IGNORECASE) + + + _max_days = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] def gregorian_valid(date_tuple): @@ -497,3 +544,4 @@ def gregorian_valid(date_tuple): elif day > _max_days[month]: valid = False return valid + diff --git a/src/gramps.py b/src/gramps.py index 6c5dd68cd..1f8decfce 100755 --- a/src/gramps.py +++ b/src/gramps.py @@ -55,8 +55,8 @@ else: loc = "/usr/share/locale" try: + locale.setlocale(locale.LC_ALL,'C') locale.setlocale(locale.LC_ALL,'') - locale.setlocale(locale.LC_TIME,os.environ.get('LANG','C')) except locale.Error: pass except ValueError: