---
title: "Intl.ListFormat:列表本地化格式与串联规则"
keywords:
- Intl.ListFormat
- conjunction
- disjunction
- unit
- 本地化
description: "介绍 Intl.ListFormat 的列表格式化能力,支持并列/选择/单位等类型,按语言规则生成“a、b 和 c”等本地化串联,提供示例与工程建议。"
categories:
- 文章资讯
- 编程技术
---
概述
Intl.ListFormat 根据语言规则将数组格式化为本地化串联文本,支持 type: 'conjunction'|'disjunction'|'unit' 与 style: 'long'|'short'|'narrow',适用于汇总与自然语言输出。
示例
const lf = new Intl.ListFormat('zh-CN', { type: 'conjunction', style: 'short' })
console.log(lf.format(['苹果', '香蕉', '梨'])) // 苹果、香蕉和梨
工程建议
- 文案一致:与其他 Intl 格式器协作;避免手工拼接导致语言不自然。
- 性能:缓存实例;避免在渲染循环中新建。
- 回退:不支持时使用 i18n 库或模板;确保标点与连词正确。
参考与验证
- MDN Intl.ListFormat 文档:https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat
- ECMA-402 规范:https://tc39.es/ecma402/#listformat-objects

发表评论 取消回复