enable deferred translation of date format strings

This commit is contained in:
Paul Franklin 2017-02-22 08:15:41 -08:00
parent 8876252771
commit 715cce27f4
2 changed files with 23 additions and 13 deletions

View File

@ -44,6 +44,10 @@ from . import _grampslocale
from ..utils.grampslocale import GrampsLocale
from ._datestrings import DateStrings
# _T_ is a gramps-defined keyword -- see po/update_po.py and po/genpot.sh
def _T_(value): # enable deferred translations (see Python docs 22.1.3.4)
return value
#-------------------------------------------------------------------------
#
# DateDisplay
@ -53,33 +57,31 @@ class DateDisplay:
"""
Base date display class.
"""
_locale = GrampsLocale(lang='en_US', languages='en')
_tformat = _grampslocale.tformat
_ = _grampslocale.glocale.translation.sgettext
formats = (
# format 0 - must always be ISO
_("YYYY-MM-DD (ISO)"),
_T_("YYYY-MM-DD (ISO)"),
# format # 1 - must always be locale-preferred numerical format
# such as YY.MM.DD, MM-DD-YY, or whatever your locale prefers.
# This should be the format that is used under the locale by
# strftime() for '%x'.
# You may translate this as "Numerical", "System preferred", or similar.
_("date format|Numerical"),
_T_("date format|Numerical"),
# Full month name, day, year
_("Month Day, Year"),
_T_("Month Day, Year"),
# Abbreviated month name, day, year
_("MON DAY, YEAR"),
_T_("MON DAY, YEAR"),
# Day, full month name, year
_("Day Month Year"),
_T_("Day Month Year"),
# Day, abbreviated month name, year
_("DAY MON YEAR")
_T_("DAY MON YEAR")
)
"""
.. note:: Will be overridden if a locale-specific date displayer exists.
@ -90,7 +92,6 @@ class DateDisplay:
This ``formats`` must agree with
:meth:`~_display_calendar`/:meth:`~_display_gregorian`.
"""
del _
newyear = ("", "Mar1", "Mar25", "Sep1")
@ -728,4 +729,4 @@ class DateDisplayEn(DateDisplay):
display = DateDisplay.display_formatted
_locale = DateDisplay._locale # normally set in register_datehandler
_locale = GrampsLocale(languages='en') # no register_datehandler here

View File

@ -34,6 +34,7 @@ import time
# Gramps modules
#
#-------------------------------------------------------------------------
from ..const import GRAMPS_LOCALE as glocale
from ..lib.date import Date
from . import LANG_TO_DISPLAY, LANG, parser, displayer
@ -42,14 +43,22 @@ from . import LANG_TO_DISPLAY, LANG, parser, displayer
# Convenience functions
#
#--------------------------------------------------------------
def get_date_formats():
def get_date_formats(flocale=glocale):
"""
Return the list of supported formats for date parsers and displayers.
The UI language formats will be used unless another locale is fed in.
:param flocale: allow deferred translation of date formats
:type flocale: a :class:`.GrampsLocale` instance
"""
# trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
trans_text = flocale.translation.sgettext
try:
return LANG_TO_DISPLAY[LANG].formats
return tuple(trans_text(fmt)
for fmt in LANG_TO_DISPLAY[flocale.lang].formats)
except:
return LANG_TO_DISPLAY["C"].formats
return tuple(trans_text(fmt)
for fmt in LANG_TO_DISPLAY['C'].formats)
def set_format(value):
try: