列表格式设置

此模块允许您以与区域设置相关的方式设置项目列表的格式。

babel.lists.format_list(lst: Sequence[str], style: Literal['standard', 'standard-short', 'or', 'or-short', 'unit', 'unit-short', 'unit-narrow'] = 'standard', locale: Locale | str | None = 'en_US') str

将项目格式设置为 lst 作为一个列表。

>>> format_list(['apples', 'oranges', 'pears'], locale='en')
u'apples, oranges, and pears'
>>> format_list(['apples', 'oranges', 'pears'], locale='zh')
u'apples、oranges和pears'
>>> format_list(['omena', 'peruna', 'aplari'], style='or', locale='fi')
u'omena, peruna tai aplari'

这些样式是已定义的,但并非所有样式都必须在所有区域设置中都可用。以下文本逐字摘自Unicode TR35-49规范 [1] .

  • 标准:任意占位符的典型‘and’列表。例如。1月、2月和3月

  • Standard-Short:‘and’列表的简短版本,适合与简短或缩写的占位符一起使用。例如。1月、2月和3月。

  • OR:任意占位符的典型“或”列表。例如。1月、2月或3月

  • or-Short:‘or’列表的简短版本。例如。1月、2月或3月。

  • 单元:适用于宽幅单元的列表。例如。3英尺7英寸

  • 短单位:适用于短单位的清单。3英尺7英寸

  • 单元-窄:适用于屏幕空间非常有限的窄单元的列表。例如。“3‘7”“

[1] :https://www.unicode.org/reports/tr35/tr35-49/tr35-general.html#ListPatterns

参数:
  • lst -- 要格式化到列表中的项目序列

  • style -- 要设置列表格式的样式。有关说明,请参阅上文。

  • locale -- 区域设置