Package DateHandler :: Module _Date_nb
[frames] | no frames]

Source Code for Module DateHandler._Date_nb

  1  # -*- coding: utf-8 -*- 
  2  # 
  3  # Gramps - a GTK+/GNOME based genealogy program 
  4  # 
  5  # Copyright (C) 2004-2006  Donald N. Allingham 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation; either version 2 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful,  
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program; if not, write to the Free Software 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 20  # 
 21   
 22  # $Id: _Date_nb.py 10103 2008-02-24 13:55:55Z acraphae $ 
 23   
 24  """ 
 25  Norwegian-specific classes for parsing and displaying dates. 
 26  """ 
 27   
 28  #------------------------------------------------------------------------- 
 29  # 
 30  # Python modules 
 31  # 
 32  #------------------------------------------------------------------------- 
 33  import re 
 34   
 35  #------------------------------------------------------------------------- 
 36  # 
 37  # GRAMPS modules 
 38  # 
 39  #------------------------------------------------------------------------- 
 40  from gen.lib import Date 
 41  from _DateParser import DateParser 
 42  from _DateDisplay import DateDisplay 
 43  from _DateHandler import register_datehandler 
 44   
 45  #------------------------------------------------------------------------- 
 46  # 
 47  # Swedish parser class 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserNb(DateParser):
51 """ 52 Convert a text string into a Date object, expecting a date 53 notation in the Norwegian language. If the date cannot be converted, 54 the text string is assigned. 55 """ 56 57 # modifiers before the date 58 modifier_to_int = { 59 u'før' : Date.MOD_BEFORE, 60 u'innen' : Date.MOD_BEFORE, 61 u'etter' : Date.MOD_AFTER, 62 u'omkring' : Date.MOD_ABOUT, 63 u'ca' : Date.MOD_ABOUT 64 } 65 66 bce = ["f Kr"] 67 68 calendar_to_int = { 69 u'gregoriansk ' : Date.CAL_GREGORIAN, 70 u'g' : Date.CAL_GREGORIAN, 71 u'juliansk' : Date.CAL_JULIAN, 72 u'j' : Date.CAL_JULIAN, 73 u'hebraisk' : Date.CAL_HEBREW, 74 u'h' : Date.CAL_HEBREW, 75 u'islamisk' : Date.CAL_ISLAMIC, 76 u'muslimsk' : Date.CAL_ISLAMIC, 77 u'i' : Date.CAL_ISLAMIC, 78 u'fransk' : Date.CAL_FRENCH, 79 u'fransk republikansk' : Date.CAL_FRENCH, 80 u'f' : Date.CAL_FRENCH, 81 u'persisk' : Date.CAL_PERSIAN, 82 u'p' : Date.CAL_PERSIAN, 83 } 84 85 quality_to_int = { 86 u'estimert' : Date.QUAL_ESTIMATED, 87 u'beregnet' : Date.QUAL_CALCULATED, 88 } 89
90 - def init_strings(self):
91 DateParser.init_strings(self) 92 self._span = re.compile(u"(fra)?\s*(?P<start>.+)\s*(til|--|–)\s*(?P<stop>.+)", 93 re.IGNORECASE) 94 self._range = re.compile(u"(mellom)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", 95 re.IGNORECASE)
96 97 #------------------------------------------------------------------------- 98 # 99 # Norwegian display class 100 # 101 #-------------------------------------------------------------------------
102 -class DateDisplayNb(DateDisplay):
103 """ 104 Norwegian language date display class. 105 """ 106 107 formats = ( 108 u"ÅÅÅÅ-MM-DD (ISO)", 109 u"Numerisk", 110 u"Måned dag, år", 111 u"Mån Dag År", 112 u"Dag måned år", 113 u"Dag Mån År", 114 ) 115 116 calendar = ( 117 "", 118 " (juliansk)", 119 " (hebraisk)", 120 " (fransk republikansk)", 121 " (persisk)", 122 " (islamisk)" 123 ) 124 125 _mod_str = ("", u"før ", u"etter ", u"ca ", "", "", "") 126 127 _qual_str = ("", u"beregnet ", u"beregnet ") 128 129 _bce_str = "%s f Kr" 130
131 - def display(self, date):
132 """ 133 Return a text string representing the date. 134 """ 135 mod = date.get_modifier() 136 cal = date.get_calendar() 137 qual = date.get_quality() 138 start = date.get_start_date() 139 140 qual_str = self._qual_str[qual] 141 142 if mod == Date.MOD_TEXTONLY: 143 return date.get_text() 144 elif start == Date.EMPTY: 145 return u"" 146 elif mod == Date.MOD_SPAN: 147 d1 = self.display_cal[cal](start) 148 d2 = self.display_cal[cal](date.get_stop_date()) 149 return u"%sfra %s til %s%s" % (qual_str, d1, d2, self.calendar[cal]) 150 elif mod == Date.MOD_RANGE: 151 d1 = self.display_cal[cal](start) 152 d2 = self.display_cal[cal](date.get_stop_date()) 153 return u"%smellom %s og %s%s" % (qual_str, d1, d2, 154 self.calendar[cal]) 155 else: 156 text = self.display_cal[date.get_calendar()](start) 157 return u"%s%s%s%s" % (qual_str, self._mod_str[mod], 158 text, self.calendar[cal])
159 160 #------------------------------------------------------------------------- 161 # 162 # Register classes 163 # 164 #------------------------------------------------------------------------- 165 register_datehandler(('nb_NO', 'nb', 'norsk'), DateParserNb, DateDisplayNb) 166