def make_string_from_list(base_str, item_list):
""" This function takes a list of items and builds a nice human readable
string with it of the form. Note that the base string needs a "%s".
Example return:
The base string with the list items a,b and c in it.
Note that base_str needs to be a ngettext string already, so the
example usage is:
l = ["foo", "bar"]
base_str = ngettext("This list: %s.", "This list: %s", len(l))
s = make_string_from_list(base_string, l)
"""
list_str = item_list[0]
if len(item_list) > 1:
# TRANSLATORS: this is a generic list delimit char, e.g. "foo, bar"
list_str = _(", ").join(item_list[:-1])
# TRANSLATORS: this is the last part of a list, e.g. "foo, bar and baz"
list_str = _("%s and %s") % (list_str,
item_list[-1])
s = base_str % list_str
return s
评论列表
文章目录