66
69
# Cached translations
67
70
__translations = {}
72
# Replace these date/time formats to get a format without seconds
84
def format_time(time_val, gconf_client, display_seconds = True, show_timezone = False, compact = True):
86
Format a given time / datetime as a time in the 12hour format. GConf
87
is checked for custom format, otherwise the default for the locale is
91
time_val -- time / datetime object
92
gconf_client -- gconf client instance
93
display_seconds -- if false, seconds will be stripped from result
95
fmt = g15util.get_string_or_default(gconf_client,
96
"/apps/gnome15/time_format",
97
locale.nl_langinfo(locale.T_FMT_AMPM))
98
if not display_seconds:
99
fmt = __strip_seconds(fmt)
100
if isinstance(time_val, time.struct_time):
101
time_val = datetime.datetime(*time_val[:6])
103
if not show_timezone:
104
fmt = fmt.replace("%Z", "")
107
fmt = fmt.replace(" %p", "%p")
108
fmt = fmt.replace(" %P", "%P")
112
if isinstance(time_val, tuple):
113
return time.strftime(fmt, time_val)
115
return time_val.strftime(fmt)
117
def format_time_24hour(time_val, gconf_client, display_seconds = True, show_timezone = False):
119
Format a given time / datetime as a time in the 24hour format. GConf
120
is checked for custom format, otherwise the default for the locale is
124
time_val -- time / datetime object / tuple
125
gconf_client -- gconf client instance
126
display_seconds -- if false, seconds will be stripped from result
128
fmt = g15util.get_string_or_default(gconf_client, "/apps/gnome15/time_format_24hr", locale.nl_langinfo(locale.T_FMT))
129
if not display_seconds:
130
fmt = __strip_seconds(fmt)
131
if isinstance(time_val, time.struct_time):
132
time_val = datetime.datetime(*time_val[:6])
134
if not show_timezone:
135
fmt = fmt.replace("%Z", "")
138
if isinstance(time_val, tuple):
139
return time.strftime(fmt, time_val)
141
return time_val.strftime(fmt)
143
def format_date(date_val, gconf_client):
145
Format a datetime as a date (without time). GConf
146
is checked for custom format, otherwise the default for the locale is
150
date_val -- date / datetime object
151
gconf_client -- gconf client instance
153
fmt = g15util.get_string_or_default(gconf_client, "/apps/gnome15/date_format", locale.nl_langinfo(locale.D_FMT))
154
if isinstance(date_val, tuple):
155
return datetime.date.strftime(fmt, date_val)
157
return date_val.strftime(fmt)
159
def format_date_time(date_val, gconf_client, display_seconds = True):
161
Format a datetime as a date and a time. GConf
162
is checked for custom format, otherwise the default for the locale is
166
date_val -- date / datetime object
167
gconf_client -- gconf client instance
168
display_seconds -- if false, seconds will be stripped from result
170
fmt = g15util.get_string_or_default(gconf_client, "/apps/gnome15/date_time_format", locale.nl_langinfo(locale.D_T_FMT))
171
if not display_seconds:
172
fmt = __strip_seconds(fmt)
173
if isinstance(date_val, tuple):
174
return datetime.datetime.strftime(fmt, date_val)
176
return date_val.strftime(fmt)
69
178
def get_translation(domain, modfile=None):