2004-09-25 10:42:15 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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 09:00:04 +05:30
|
|
|
|
2004-09-25 10:42:15 +05:30
|
|
|
"""
|
|
|
|
Class handling language-specific selection for date parser and displayer.
|
|
|
|
"""
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2004-09-25 10:42:15 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2004-11-09 09:53:34 +05:30
|
|
|
import locale
|
2004-09-25 10:42:15 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import DateParser
|
|
|
|
import DateDisplay
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2004-09-25 10:42:15 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-11-09 09:53:34 +05:30
|
|
|
_lang = locale.getlocale(locale.LC_TIME)[0]
|
2005-06-05 00:38:38 +05:30
|
|
|
if _lang:
|
|
|
|
_lang_short = _lang.split('_')[0]
|
|
|
|
else:
|
|
|
|
_lang_short = "C"
|
2004-09-17 09:00:04 +05:30
|
|
|
|
|
|
|
_lang_to_parser = {
|
2004-11-07 08:32:24 +05:30
|
|
|
'C' : DateParser.DateParser,
|
|
|
|
'en' : DateParser.DateParser,
|
2004-09-17 09:00:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
_lang_to_display = {
|
2005-01-13 02:53:31 +05:30
|
|
|
'C' : DateDisplay.DateDisplayEn,
|
|
|
|
'en' : DateDisplay.DateDisplayEn,
|
|
|
|
'zh_CN' : DateDisplay.DateDisplay,
|
|
|
|
'zh_TW' : DateDisplay.DateDisplay,
|
|
|
|
'zh_SG' : DateDisplay.DateDisplay,
|
|
|
|
'zh_HK' : DateDisplay.DateDisplay,
|
|
|
|
'ja_JP' : DateDisplay.DateDisplay,
|
|
|
|
'ko_KR' : DateDisplay.DateDisplay,
|
2004-09-17 09:00:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
def get_date_formats():
|
2004-12-26 23:13:22 +05:30
|
|
|
"""
|
|
|
|
Returns the lists supported formats for date parsers and displayers
|
|
|
|
"""
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
|
|
|
return _lang_to_display[_lang].formats
|
|
|
|
except:
|
2005-05-11 21:15:04 +05:30
|
|
|
return _lang_to_display["C"].formats
|
2004-09-17 09:00:04 +05:30
|
|
|
|
2005-01-09 07:48:49 +05:30
|
|
|
def set_format(value):
|
2004-09-17 09:00:04 +05:30
|
|
|
try:
|
2005-01-13 02:53:31 +05:30
|
|
|
displayer.set_format(value)
|
2004-09-17 09:00:04 +05:30
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2004-12-26 23:13:22 +05:30
|
|
|
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
|
|
|
|
|
2004-11-16 09:14:23 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Import localized date classes
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-01-05 10:32:19 +05:30
|
|
|
from PluginMgr import load_plugins
|
2004-11-16 09:14:23 +05:30
|
|
|
from const import datesDir
|
|
|
|
load_plugins(datesDir)
|
2004-12-26 23:13:22 +05:30
|
|
|
|
2004-12-29 10:36:10 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Initialize global parser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
try:
|
2005-06-05 00:38:38 +05:30
|
|
|
if _lang_to_parser.has_key(_lang):
|
|
|
|
parser = _lang_to_parser[_lang]
|
|
|
|
else:
|
|
|
|
parser = _lang_to_parser[_lang_short]
|
2004-12-29 10:36:10 +05:30
|
|
|
except:
|
|
|
|
print "Date parser for",_lang,"not available, using default"
|
2005-05-11 21:15:04 +05:30
|
|
|
parser = _lang_to_parser["C"]()
|
2004-12-29 10:36:10 +05:30
|
|
|
|
|
|
|
try:
|
2005-01-06 22:58:31 +05:30
|
|
|
import GrampsKeys
|
|
|
|
val = GrampsKeys.get_date_format(_lang_to_display[_lang].formats)
|
2005-01-04 01:13:22 +05:30
|
|
|
except:
|
2005-05-11 21:15:04 +05:30
|
|
|
try:
|
|
|
|
val = GrampsKeys.get_date_format(_lang_to_display["C"].formats)
|
|
|
|
except:
|
|
|
|
val = 0
|
2005-01-04 01:13:22 +05:30
|
|
|
|
|
|
|
try:
|
2005-06-05 00:38:38 +05:30
|
|
|
if _lang_to_display.has_key(_lang):
|
|
|
|
displayer = _lang_to_display[_lang](val)
|
|
|
|
else:
|
|
|
|
displayer = _lang_to_display[_lang_short](val)
|
2004-12-29 10:36:10 +05:30
|
|
|
except:
|
|
|
|
print "Date displayer for",_lang,"not available, using default"
|
2005-05-11 21:15:04 +05:30
|
|
|
displayer = _lang_to_display["C"](val)
|
2005-06-04 09:36:47 +05:30
|
|
|
|