2004-09-25 05:12:15 +00:00
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-08 00:55:04 +00:00
|
|
|
# Copyright (C) 2004-2006 Donald N. Allingham
|
2004-09-25 05:12:15 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
2004-09-17 03:30:04 +00:00
|
|
|
|
2004-09-25 05:12:15 +00:00
|
|
|
"""
|
|
|
|
Class handling language-specific selection for date parser and displayer.
|
|
|
|
"""
|
2004-09-17 03:30:04 +00:00
|
|
|
|
2004-09-25 05:12:15 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2006-05-14 20:14:59 +00:00
|
|
|
# Python modules
|
2004-09-25 05:12:15 +00:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-11-09 04:23:34 +00:00
|
|
|
import locale
|
2004-09-25 05:12:15 +00:00
|
|
|
|
2006-03-05 04:45:44 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".DateHandler")
|
|
|
|
|
2004-09-25 05:12:15 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-08 01:09:17 +00:00
|
|
|
from _DateParser import DateParser
|
|
|
|
from _DateDisplay import DateDisplay, DateDisplayEn
|
2004-09-17 03:30:04 +00:00
|
|
|
|
2004-09-25 05:12:15 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-11-09 04:23:34 +00:00
|
|
|
_lang = locale.getlocale(locale.LC_TIME)[0]
|
2005-06-05 04:01:56 +00:00
|
|
|
if _lang:
|
|
|
|
_lang_short = _lang.split('_')[0]
|
|
|
|
else:
|
|
|
|
_lang_short = "C"
|
2004-09-17 03:30:04 +00:00
|
|
|
|
|
|
|
_lang_to_parser = {
|
2006-03-08 01:09:17 +00:00
|
|
|
'C' : DateParser,
|
|
|
|
'en' : DateParser,
|
2004-09-17 03:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_lang_to_display = {
|
2006-03-08 01:09:17 +00:00
|
|
|
'C' : DateDisplayEn,
|
|
|
|
'en' : DateDisplayEn,
|
|
|
|
'zh_CN' : DateDisplay,
|
|
|
|
'zh_TW' : DateDisplay,
|
|
|
|
'zh_SG' : DateDisplay,
|
|
|
|
'zh_HK' : DateDisplay,
|
|
|
|
'ja_JP' : DateDisplay,
|
|
|
|
'ko_KR' : DateDisplay,
|
2004-09-17 03:30:04 +00:00
|
|
|
}
|
|
|
|
|
2004-12-26 17:43:22 +00:00
|
|
|
def register_datehandler(locales,parse_class,display_class):
|
|
|
|
"""
|
|
|
|
Registers the passed date parser class and date displayer
|
|
|
|
classes with the specfied language locales.
|
|
|
|
|
|
|
|
@param locales: tuple of strings containing language codes.
|
|
|
|
The character encoding is not included, so the langauge
|
|
|
|
should be in the form of fr_FR, not fr_FR.utf8
|
|
|
|
@type locales: tuple
|
|
|
|
@param parse_class: Class to be associated with parsing
|
|
|
|
@type parse_class: DateParse
|
|
|
|
@param display_class: Class to be associated with displaying
|
|
|
|
@type display_class: DateDisplay
|
|
|
|
"""
|
|
|
|
for lang_str in locales:
|
|
|
|
_lang_to_parser[lang_str] = parse_class
|
|
|
|
_lang_to_display[lang_str] = display_class
|