Trees | Indices | Help |
|
---|
|
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_sv.py 9912 2008-01-22 09:17:46Z acraphae $ 23 24 """ 25 Swedish-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 #-------------------------------------------------------------------------51 """ 52 Convert a text string into a Date object, expecting a date 53 notation in the swedish 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öre' : Date.MOD_BEFORE, 60 u'innan' : Date.MOD_BEFORE, 61 u'efter' : Date.MOD_AFTER, 62 u'omkring' : Date.MOD_ABOUT, 63 u'ca' : Date.MOD_ABOUT, 64 u'c:a' : Date.MOD_ABOUT 65 } 66 67 bce = ["f Kr"] 68 69 calendar_to_int = { 70 u'gregoriansk ' : Date.CAL_GREGORIAN, 71 u'g' : Date.CAL_GREGORIAN, 72 u'juliansk' : Date.CAL_JULIAN, 73 u'j' : Date.CAL_JULIAN, 74 u'hebreisk' : Date.CAL_HEBREW, 75 u'h' : Date.CAL_HEBREW, 76 u'islamisk' : Date.CAL_ISLAMIC, 77 u'muslimsk' : Date.CAL_ISLAMIC, 78 u'i' : Date.CAL_ISLAMIC, 79 u'fransk' : Date.CAL_FRENCH, 80 u'fransk republikansk' : Date.CAL_FRENCH, 81 u'f' : Date.CAL_FRENCH, 82 u'persisk' : Date.CAL_PERSIAN, 83 u'p' : Date.CAL_PERSIAN, 84 } 85 86 quality_to_int = { 87 u'uppskattat' : Date.QUAL_ESTIMATED, 88 u'uppskattad' : Date.QUAL_ESTIMATED, 89 u'bedömt' : Date.QUAL_ESTIMATED, 90 u'bedömd' : Date.QUAL_ESTIMATED, 91 u'beräknat' : Date.QUAL_CALCULATED, 92 u'beräknad' : Date.QUAL_CALCULATED, 93 } 94101 102 #------------------------------------------------------------------------- 103 # 104 # Swedish display class 105 # 106 #-------------------------------------------------------------------------96 DateParser.init_strings(self) 97 self._span = re.compile(u"(från)?\s*(?P<start>.+)\s*(till|--|–)\s*(?P<stop>.+)", 98 re.IGNORECASE) 99 self._range = re.compile(u"(mellan)\s+(?P<start>.+)\s+och\s+(?P<stop>.+)", 100 re.IGNORECASE)108 """ 109 Swedish language date display class. 110 """ 111 112 formats = ( 113 u"YYYY-MM-DD (ISO)", 114 u"Numerisk", 115 u"Månad dag, år", 116 u"MÅN DAG ÅR", 117 u"Dag månad år", 118 u"DAG MÅN ÅR", 119 ) 120 121 calendar = ( 122 "", 123 " (juliansk)", 124 " (hebreisk)", 125 " (fransk republikansk)", 126 " (persisk)", 127 " (islamisk)" 128 ) 129 130 _mod_str = ("", u"före ", u"efter ", u"c:a ", "", "", "") 131 132 _qual_str = ("", u"uppskattat ", u"beräknat ") 133 134 _bce_str = "%s f Kr" 135164 165 #------------------------------------------------------------------------- 166 # 167 # Register classes 168 # 169 #------------------------------------------------------------------------- 170 register_datehandler(('sv_SE', 'sv', 'svensk'), DateParserSv, DateDisplaySv) 171137 """ 138 Return a text string representing the date. 139 """ 140 mod = date.get_modifier() 141 cal = date.get_calendar() 142 qual = date.get_quality() 143 start = date.get_start_date() 144 145 qual_str = self._qual_str[qual] 146 147 if mod == Date.MOD_TEXTONLY: 148 return date.get_text() 149 elif start == Date.EMPTY: 150 return u"" 151 elif mod == Date.MOD_SPAN: 152 d1 = self.display_cal[cal](start) 153 d2 = self.display_cal[cal](date.get_stop_date()) 154 return u"%sfrån %s till %s%s" % (qual_str, d1, d2, self.calendar[cal]) 155 elif mod == Date.MOD_RANGE: 156 d1 = self.display_cal[cal](start) 157 d2 = self.display_cal[cal](date.get_stop_date()) 158 return u"%smellan %s och %s%s" % (qual_str, d1, d2, 159 self.calendar[cal]) 160 else: 161 text = self.display_cal[date.get_calendar()](start) 162 return u"%s%s%s%s" % (qual_str, self._mod_str[mod], 163 text, self.calendar[cal])
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sun Mar 9 21:53:14 2008 | http://epydoc.sourceforge.net |