Skip to content

Commit 3622ca2

Browse files
committed
feat: list formatter example
1 parent 5f85f9c commit 3622ca2

10 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import intl from 'core/intl';
3+
import ExampleBlock from 'components/example-block';
4+
import { renderCode } from 'components/format-doc-links';
5+
6+
const LocaleFormattingComponent: React.FC = () => {
7+
const formatListCode = `<div>
8+
{intl.formatList([
9+
<strong key="react">React</strong>,
10+
<strong key="typescript">TypeScript</strong>,
11+
<strong key="nextjs">Next.js</strong>,
12+
], { type: 'conjunction', style: 'long' })}
13+
</div>`;
14+
15+
const formatParenthesesCode = `<div>
16+
{intl.formatParentheses(
17+
<strong key="beta">{intl.get('EXAMPLE_STATUS_BETA').d('Beta')}</strong>
18+
)}
19+
</div>`;
20+
21+
const getColonCode = `<div>
22+
{intl.get('EXAMPLE_STATUS').d('Status')}
23+
{intl.getColon()}
24+
<strong>{intl.get('EXAMPLE_STATUS_ACTIVE').d('Active')}</strong>
25+
</div>`;
26+
27+
return (
28+
<div>
29+
<div className="title">
30+
{intl.get('EXAMPLE_TITLE_LOCALE_HELPERS').d('Locale-aware lists and punctuation')}
31+
</div>
32+
<p className="section-note">
33+
{intl.get('EXAMPLE_NOTE_LOCALE_HELPERS', {
34+
code: renderCode,
35+
}).d('Use <code>intl.formatList</code> to join React nodes and use <code>intl.formatParentheses</code> or <code>intl.getColon</code> for punctuation that matches the active locale.')}
36+
</p>
37+
<ExampleBlock code={formatListCode} />
38+
<ExampleBlock code={formatParenthesesCode} />
39+
<ExampleBlock code={getColonCode} />
40+
</div>
41+
);
42+
};
43+
44+
export default LocaleFormattingComponent;

packages/react-intl-universal/examples/nextjs-example/locales/de-DE.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "Sprachabhängige Listen und Satzzeichen",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "Verwenden Sie <code>intl.formatList</code> zum Verbinden von React-Knoten und <code>intl.formatParentheses</code> oder <code>intl.getColon</code> für Satzzeichen, die zur aktiven Sprache passen.",
21+
"EXAMPLE_STATUS_BETA": "Beta",
22+
"EXAMPLE_STATUS": "Status",
23+
"EXAMPLE_STATUS_ACTIVE": "Aktiv",
1924
"EXAMPLE_NOTE_PLAIN": "Schreiben Sie ICU variables in die <code>.d()</code> default message und übergeben Sie die Werte über den zweiten Parameter von <code>intl.get</code>. So bleiben Code, default message und Extraktion konsistent. Details finden Sie in der <formatjs>FormatJS ICU syntax</formatjs>.",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages verwenden ICU <code>plural</code> rules. Der <code>#</code> placeholder wird mit der aktiven locale formatiert, deshalb erhalten große Zahlen automatisch passende Trennzeichen. Mehr dazu im <icu>ICU MessageFormat guide</icu>.",
2126
"EXAMPLE_NOTE_DATE_TIME": "Formatieren Sie JavaScript Date-Werte mit intl.formatDate, intl.formatTime oder intl.formatDateTime und übergeben Sie das Ergebnis dann an intl.get. Diese Helper verwenden stabile Standardformate: YYYY-MM-DD, HH:mm:ss und YYYY-MM-DD HH:mm:ss. Die locale message enthält nur einfache Platzhalter wie '{start}'.",

packages/react-intl-universal/examples/nextjs-example/locales/en-US.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "Locale-aware lists and punctuation",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "Use <code>intl.formatList</code> to join React nodes and use <code>intl.formatParentheses</code> or <code>intl.getColon</code> for punctuation that matches the active locale.",
21+
"EXAMPLE_STATUS_BETA": "Beta",
22+
"EXAMPLE_STATUS": "Status",
23+
"EXAMPLE_STATUS_ACTIVE": "Active",
1924
"EXAMPLE_NOTE_PLAIN": "Use ICU variables with the values passed to <code>intl.get</code>. Keep <code>.d()</code> as the default message and source text for extraction. See <formatjs>FormatJS ICU syntax</formatjs> for details.",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages use ICU <code>plural</code> rules. The <code>#</code> placeholder is formatted with the active locale, so large numbers get locale-aware separators. Learn more in the <icu>ICU MessageFormat guide</icu>.",
2126
"EXAMPLE_NOTE_DATE_TIME": "Format JavaScript Date values with intl.formatDate, intl.formatTime, or intl.formatDateTime, then pass the formatted value into intl.get. The helpers use stable defaults: YYYY-MM-DD, HH:mm:ss, and YYYY-MM-DD HH:mm:ss. Locale messages keep plain placeholders such as '{start}'.",

packages/react-intl-universal/examples/nextjs-example/locales/es-ES.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "Listas y puntuación adaptadas al idioma",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "Usa <code>intl.formatList</code> para unir nodos de React y <code>intl.formatParentheses</code> o <code>intl.getColon</code> para generar signos de puntuación adecuados para el idioma activo.",
21+
"EXAMPLE_STATUS_BETA": "Beta",
22+
"EXAMPLE_STATUS": "Estado",
23+
"EXAMPLE_STATUS_ACTIVE": "Activo",
1924
"EXAMPLE_NOTE_PLAIN": "Usa ICU variables con los valores pasados a <code>intl.get</code>. Mantén <code>.d()</code> como default message y source text para la extracción. Consulta <formatjs>FormatJS ICU syntax</formatjs> para más detalles.",
2025
"EXAMPLE_NOTE_PLURAL": "Los plural messages usan las reglas ICU <code>plural</code>. El placeholder <code>#</code> se formatea con el locale activo, así que los números grandes usan separadores adecuados al idioma. Más detalles en la <icu>ICU MessageFormat guide</icu>.",
2126
"EXAMPLE_NOTE_DATE_TIME": "Formatea valores JavaScript Date con intl.formatDate, intl.formatTime o intl.formatDateTime, y luego pasa el resultado a intl.get. Estos helpers usan defaults estables: YYYY-MM-DD, HH:mm:ss y YYYY-MM-DD HH:mm:ss. Los locale messages conservan placeholders simples como '{start}'.",

packages/react-intl-universal/examples/nextjs-example/locales/fr-FR.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "Listes et ponctuation adaptées à la langue",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "Utilisez <code>intl.formatList</code> pour joindre des nœuds React, et <code>intl.formatParentheses</code> ou <code>intl.getColon</code> pour obtenir une ponctuation adaptée à la langue active.",
21+
"EXAMPLE_STATUS_BETA": "Bêta",
22+
"EXAMPLE_STATUS": "État",
23+
"EXAMPLE_STATUS_ACTIVE": "Actif",
1924
"EXAMPLE_NOTE_PLAIN": "Utilisez des ICU variables avec les valeurs passées à <code>intl.get</code>. Gardez <code>.d()</code> comme message par défaut et comme texte source pour l'extraction. Voir <formatjs>FormatJS ICU syntax</formatjs> pour les détails.",
2025
"EXAMPLE_NOTE_PLURAL": "Les plural messages utilisent les règles ICU <code>plural</code>. Le placeholder <code>#</code> est formaté selon la locale active, donc les grands nombres reçoivent les séparateurs adaptés. Voir le <icu>ICU MessageFormat guide</icu>.",
2126
"EXAMPLE_NOTE_DATE_TIME": "Formatez les valeurs JavaScript Date avec intl.formatDate, intl.formatTime ou intl.formatDateTime, puis passez le résultat à intl.get. Ces helpers utilisent des formats stables par défaut : YYYY-MM-DD, HH:mm:ss et YYYY-MM-DD HH:mm:ss. Le locale message garde de simples placeholders comme '{start}'.",

packages/react-intl-universal/examples/nextjs-example/locales/ja-JP.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages(複数形)",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting(日付と時刻)",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting(数値の整形)",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "ロケール対応のリストと句読点",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "<code>intl.formatList</code> で React ノードを連結し、<code>intl.formatParentheses</code> または <code>intl.getColon</code> で現在のロケールに合った句読点を生成します。",
21+
"EXAMPLE_STATUS_BETA": "ベータ",
22+
"EXAMPLE_STATUS": "状態",
23+
"EXAMPLE_STATUS_ACTIVE": "有効",
1924
"EXAMPLE_NOTE_PLAIN": "ICU variables を <code>.d()</code> の default message に書き、値は <code>intl.get</code> の第 2 引数で渡します。これによりコード、default message、抽出ツールの前提がそろいます。詳しくは <formatjs>FormatJS ICU syntax</formatjs> を参照してください。",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages は ICU の <code>plural</code> rules を使います。<code>#</code> は現在の locale に合わせて数値をフォーマットするため、大きな数値の区切りも locale に従います。詳しくは <icu>ICU MessageFormat guide</icu> を参照してください。",
2126
"EXAMPLE_NOTE_DATE_TIME": "JavaScript Date は、先に intl.formatDate、intl.formatTime、intl.formatDateTime で整形してから intl.get に渡します。これらの helper は YYYY-MM-DD、HH:mm:ss、YYYY-MM-DD HH:mm:ss の安定した既定形式を使います。locale message には '{start}' のような通常の placeholder だけを残します。",

packages/react-intl-universal/examples/nextjs-example/locales/ko-KR.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "로캘별 목록 및 문장 부호",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "<code>intl.formatList</code>로 React 노드를 연결하고 <code>intl.formatParentheses</code> 또는 <code>intl.getColon</code>으로 현재 로캘에 맞는 문장 부호를 생성하세요.",
21+
"EXAMPLE_STATUS_BETA": "베타",
22+
"EXAMPLE_STATUS": "상태",
23+
"EXAMPLE_STATUS_ACTIVE": "활성",
1924
"EXAMPLE_NOTE_PLAIN": "ICU variables는 <code>.d()</code> default message에 쓰고, 값은 <code>intl.get</code>의 두 번째 인자로 전달하세요. 이렇게 하면 코드, default message, extract 결과가 같은 기준을 공유합니다. 자세한 문법은 <formatjs>FormatJS ICU syntax</formatjs>를 참고하세요.",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages는 ICU <code>plural</code> rules를 사용합니다. <code>#</code> placeholder는 현재 locale에 맞게 숫자를 포맷하므로 큰 숫자도 locale에 맞는 구분 기호를 사용합니다. 자세한 내용은 <icu>ICU MessageFormat guide</icu>를 참고하세요.",
2126
"EXAMPLE_NOTE_DATE_TIME": "JavaScript Date 값은 intl.formatDate, intl.formatTime, intl.formatDateTime으로 먼저 포맷한 뒤 intl.get에 전달하세요. 이 helper들은 YYYY-MM-DD, HH:mm:ss, YYYY-MM-DD HH:mm:ss처럼 안정적인 기본 형식을 사용합니다. locale message에는 '{start}' 같은 일반 placeholder만 남깁니다.",

packages/react-intl-universal/examples/nextjs-example/locales/zh-CN.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages(复数场景)",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting(日期时间)",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting(数字格式化)",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "本地化列表与标点",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "使用 <code>intl.formatList</code> 连接 React 节点,并使用 <code>intl.formatParentheses</code> 或 <code>intl.getColon</code> 生成符合当前语言习惯的标点。",
21+
"EXAMPLE_STATUS_BETA": "测试版",
22+
"EXAMPLE_STATUS": "状态",
23+
"EXAMPLE_STATUS_ACTIVE": "启用",
1924
"EXAMPLE_NOTE_PLAIN": "把 ICU variables 写在 <code>.d()</code> 默认文案里,再通过 <code>intl.get</code> 第二个参数传值。这样代码、默认文案和抽取工具会保持一致。更多语法见 <formatjs>FormatJS ICU syntax</formatjs>。",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages 使用 ICU <code>plural</code> rules。<code>#</code> 会按当前 locale 格式化数字,所以大数字会自动带上对应语言环境的分隔符。详细规则见 <icu>ICU MessageFormat guide</icu>。",
2126
"EXAMPLE_NOTE_DATE_TIME": "先用 intl.formatDate、intl.formatTime 或 intl.formatDateTime 格式化 JavaScript Date,再把结果传给 intl.get。这三个 helper 使用稳定默认格式:YYYY-MM-DD、HH:mm:ss、YYYY-MM-DD HH:mm:ss。locale message 只保留 '{start}' 这类普通占位符。",

packages/react-intl-universal/examples/nextjs-example/locales/zh-TW.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
"EXAMPLE_TITLE_PLURAL": "Plural messages(複數情境)",
1717
"EXAMPLE_TITLE_DATE_TIME": "Date and time formatting(日期時間)",
1818
"EXAMPLE_TITLE_NUMBER_CURRENCY": "Number formatting(數字格式化)",
19+
"EXAMPLE_TITLE_LOCALE_HELPERS": "在地化清單與標點",
20+
"EXAMPLE_NOTE_LOCALE_HELPERS": "使用 <code>intl.formatList</code> 串接 React 節點,並使用 <code>intl.formatParentheses</code> 或 <code>intl.getColon</code> 產生符合目前語系習慣的標點。",
21+
"EXAMPLE_STATUS_BETA": "測試版",
22+
"EXAMPLE_STATUS": "狀態",
23+
"EXAMPLE_STATUS_ACTIVE": "啟用",
1924
"EXAMPLE_NOTE_PLAIN": "把 ICU variables 寫在 <code>.d()</code> 預設文案裡,再透過 <code>intl.get</code> 第二個參數傳值。這樣程式碼、預設文案和抽取工具會保持一致。更多語法見 <formatjs>FormatJS ICU syntax</formatjs>。",
2025
"EXAMPLE_NOTE_PLURAL": "Plural messages 使用 ICU <code>plural</code> rules。<code>#</code> 會依照目前 locale 格式化數字,所以大數字會自動帶上對應語言環境的分隔符。詳細規則見 <icu>ICU MessageFormat guide</icu>。",
2126
"EXAMPLE_NOTE_DATE_TIME": "先用 intl.formatDate、intl.formatTime 或 intl.formatDateTime 格式化 JavaScript Date,再把結果傳給 intl.get。這三個 helper 使用穩定預設格式:YYYY-MM-DD、HH:mm:ss、YYYY-MM-DD HH:mm:ss。locale message 只保留 '{start}' 這類普通佔位符。",

packages/react-intl-universal/examples/nextjs-example/pages/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SkillComponent from "components/skill";
1717
import ExtractComponent from "components/extract";
1818
import DateComponent from "components/date";
1919
import CurrencyComponent from "components/currency";
20+
import LocaleFormattingComponent from "components/locale-formatting";
2021
import MessageNotInComponent from "components/message-not-in-component";
2122

2223
const LOCALES_LIST = [
@@ -191,6 +192,7 @@ const ReactIntlUniversalExample: React.FC<any> = (props) => {
191192
<PluralComponent />
192193
<DateComponent />
193194
<CurrencyComponent />
195+
<LocaleFormattingComponent />
194196
</section>
195197

196198
<section className="example-section" id="extract-usage">

0 commit comments

Comments
 (0)