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

Source Code for Module DateHandler._DateHandler

 1  # 
 2  # Gramps - a GTK+/GNOME based genealogy program 
 3  # 
 4  # Copyright (C) 2004-2006  Donald N. Allingham 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the Free Software 
18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19  # 
20   
21  # $Id: _DateHandler.py 6657 2006-05-14 20:14:59Z rshura $ 
22   
23  """ 
24  Class handling language-specific selection for date parser and displayer. 
25  """ 
26   
27  #------------------------------------------------------------------------- 
28  # 
29  # Python modules 
30  # 
31  #------------------------------------------------------------------------- 
32  import locale 
33   
34  #------------------------------------------------------------------------- 
35  # 
36  # set up logging 
37  # 
38  #------------------------------------------------------------------------- 
39  import logging 
40  log = logging.getLogger(".DateHandler") 
41   
42  #------------------------------------------------------------------------- 
43  # 
44  # GRAMPS modules 
45  # 
46  #------------------------------------------------------------------------- 
47  from _DateParser import DateParser 
48  from _DateDisplay import DateDisplay, DateDisplayEn 
49   
50  #------------------------------------------------------------------------- 
51  # 
52  # Constants  
53  # 
54  #------------------------------------------------------------------------- 
55  _lang = locale.getlocale(locale.LC_TIME)[0] 
56  if _lang: 
57      _lang_short = _lang.split('_')[0] 
58  else: 
59      _lang_short = "C" 
60   
61  _lang_to_parser = { 
62      'C'      : DateParser, 
63      'en'     : DateParser, 
64      } 
65   
66  _lang_to_display = { 
67      'C'      : DateDisplayEn, 
68      'en'     : DateDisplayEn, 
69      'zh_CN'  : DateDisplay, 
70      'zh_TW'  : DateDisplay, 
71      'zh_SG'  : DateDisplay, 
72      'zh_HK'  : DateDisplay, 
73      'ja_JP'  : DateDisplay, 
74      'ko_KR'  : DateDisplay, 
75      } 
76   
77 -def register_datehandler(locales,parse_class,display_class):
78 """ 79 Registers the passed date parser class and date displayer 80 classes with the specfied language locales. 81 82 @param locales: tuple of strings containing language codes. 83 The character encoding is not included, so the langauge 84 should be in the form of fr_FR, not fr_FR.utf8 85 @type locales: tuple 86 @param parse_class: Class to be associated with parsing 87 @type parse_class: DateParse 88 @param display_class: Class to be associated with displaying 89 @type display_class: DateDisplay 90 """ 91 for lang_str in locales: 92 _lang_to_parser[lang_str] = parse_class 93 _lang_to_display[lang_str] = display_class
94