|
| 1 | +--- |
| 2 | +title: Internationalization |
| 3 | +description: Override default English labels with your own translations. |
| 4 | +type: reference |
| 5 | +summary: Localize all UI labels in Streamdown controls and modals. |
| 6 | +prerequisites: |
| 7 | + - /docs/getting-started |
| 8 | +related: |
| 9 | + - /docs/configuration |
| 10 | + - /docs/interactivity |
| 11 | +--- |
| 12 | + |
| 13 | +Streamdown ships with English labels for all interactive controls — copy buttons, download menus, link modals, and more. Override any label via the `translations` prop. |
| 14 | + |
| 15 | +## Basic usage |
| 16 | + |
| 17 | +Pass a partial translations object to replace specific labels: |
| 18 | + |
| 19 | +```tsx title="app/page.tsx" |
| 20 | +<Streamdown |
| 21 | + translations={{ |
| 22 | + copyCode: "Copiar código", |
| 23 | + close: "Cerrar", |
| 24 | + openLink: "Abrir enlace", |
| 25 | + downloadImage: "Descargar imagen", |
| 26 | + }} |
| 27 | +> |
| 28 | + {markdown} |
| 29 | +</Streamdown> |
| 30 | +``` |
| 31 | + |
| 32 | +## Available translation keys |
| 33 | + |
| 34 | +### Code block |
| 35 | + |
| 36 | +<TypeTable |
| 37 | + type={{ |
| 38 | + copyCode: { |
| 39 | + description: "Tooltip for the code copy button", |
| 40 | + type: "string", |
| 41 | + default: '"Copy Code"', |
| 42 | + }, |
| 43 | + downloadFile: { |
| 44 | + description: "Tooltip for the file download button", |
| 45 | + type: "string", |
| 46 | + default: '"Download file"', |
| 47 | + }, |
| 48 | + }} |
| 49 | +/> |
| 50 | + |
| 51 | +### Mermaid diagrams |
| 52 | + |
| 53 | +<TypeTable |
| 54 | + type={{ |
| 55 | + downloadDiagram: { |
| 56 | + description: "Label for the diagram download button", |
| 57 | + type: "string", |
| 58 | + default: '"Download diagram"', |
| 59 | + }, |
| 60 | + downloadDiagramAsSvg: { |
| 61 | + description: "Download diagram as SVG option", |
| 62 | + type: "string", |
| 63 | + default: '"Download diagram as SVG"', |
| 64 | + }, |
| 65 | + downloadDiagramAsPng: { |
| 66 | + description: "Download diagram as PNG option", |
| 67 | + type: "string", |
| 68 | + default: '"Download diagram as PNG"', |
| 69 | + }, |
| 70 | + downloadDiagramAsMmd: { |
| 71 | + description: "Download diagram as MMD option", |
| 72 | + type: "string", |
| 73 | + default: '"Download diagram as MMD"', |
| 74 | + }, |
| 75 | + viewFullscreen: { |
| 76 | + description: "Toggle fullscreen button label", |
| 77 | + type: "string", |
| 78 | + default: '"View fullscreen"', |
| 79 | + }, |
| 80 | + exitFullscreen: { |
| 81 | + description: "Exit fullscreen button label", |
| 82 | + type: "string", |
| 83 | + default: '"Exit fullscreen"', |
| 84 | + }, |
| 85 | + mermaidFormatSvg: { |
| 86 | + description: "Short format label for SVG", |
| 87 | + type: "string", |
| 88 | + default: '"SVG"', |
| 89 | + }, |
| 90 | + mermaidFormatPng: { |
| 91 | + description: "Short format label for PNG", |
| 92 | + type: "string", |
| 93 | + default: '"PNG"', |
| 94 | + }, |
| 95 | + mermaidFormatMmd: { |
| 96 | + description: "Short format label for MMD", |
| 97 | + type: "string", |
| 98 | + default: '"MMD"', |
| 99 | + }, |
| 100 | + }} |
| 101 | +/> |
| 102 | + |
| 103 | +### Table |
| 104 | + |
| 105 | +<TypeTable |
| 106 | + type={{ |
| 107 | + copyTable: { |
| 108 | + description: "Label for the table copy button", |
| 109 | + type: "string", |
| 110 | + default: '"Copy table"', |
| 111 | + }, |
| 112 | + copyTableAsMarkdown: { |
| 113 | + description: "Copy as Markdown option", |
| 114 | + type: "string", |
| 115 | + default: '"Copy table as Markdown"', |
| 116 | + }, |
| 117 | + copyTableAsCsv: { |
| 118 | + description: "Copy as CSV option", |
| 119 | + type: "string", |
| 120 | + default: '"Copy table as CSV"', |
| 121 | + }, |
| 122 | + copyTableAsTsv: { |
| 123 | + description: "Copy as TSV option", |
| 124 | + type: "string", |
| 125 | + default: '"Copy table as TSV"', |
| 126 | + }, |
| 127 | + downloadTable: { |
| 128 | + description: "Label for the table download button", |
| 129 | + type: "string", |
| 130 | + default: '"Download table"', |
| 131 | + }, |
| 132 | + downloadTableAsCsv: { |
| 133 | + description: "Download table as CSV option", |
| 134 | + type: "string", |
| 135 | + default: '"Download table as CSV"', |
| 136 | + }, |
| 137 | + downloadTableAsMarkdown: { |
| 138 | + description: "Download table as Markdown option", |
| 139 | + type: "string", |
| 140 | + default: '"Download table as Markdown"', |
| 141 | + }, |
| 142 | + tableFormatMarkdown: { |
| 143 | + description: "Short format label for Markdown", |
| 144 | + type: "string", |
| 145 | + default: '"Markdown"', |
| 146 | + }, |
| 147 | + tableFormatCsv: { |
| 148 | + description: "Short format label for CSV", |
| 149 | + type: "string", |
| 150 | + default: '"CSV"', |
| 151 | + }, |
| 152 | + tableFormatTsv: { |
| 153 | + description: "Short format label for TSV", |
| 154 | + type: "string", |
| 155 | + default: '"TSV"', |
| 156 | + }, |
| 157 | + }} |
| 158 | +/> |
| 159 | + |
| 160 | +### Image |
| 161 | + |
| 162 | +<TypeTable |
| 163 | + type={{ |
| 164 | + imageNotAvailable: { |
| 165 | + description: "Fallback text for broken images", |
| 166 | + type: "string", |
| 167 | + default: '"Image not available"', |
| 168 | + }, |
| 169 | + downloadImage: { |
| 170 | + description: "Tooltip for the image download button", |
| 171 | + type: "string", |
| 172 | + default: '"Download image"', |
| 173 | + }, |
| 174 | + }} |
| 175 | +/> |
| 176 | + |
| 177 | +### Link modal |
| 178 | + |
| 179 | +<TypeTable |
| 180 | + type={{ |
| 181 | + openExternalLink: { |
| 182 | + description: "Modal title for external links", |
| 183 | + type: "string", |
| 184 | + default: '"Open external link?"', |
| 185 | + }, |
| 186 | + externalLinkWarning: { |
| 187 | + description: "Warning text in the link modal", |
| 188 | + type: "string", |
| 189 | + default: '"You\'re about to visit an external website."', |
| 190 | + }, |
| 191 | + close: { |
| 192 | + description: "Close button label", |
| 193 | + type: "string", |
| 194 | + default: '"Close"', |
| 195 | + }, |
| 196 | + copyLink: { |
| 197 | + description: "Copy link button label", |
| 198 | + type: "string", |
| 199 | + default: '"Copy link"', |
| 200 | + }, |
| 201 | + copied: { |
| 202 | + description: "Label shown after copying", |
| 203 | + type: "string", |
| 204 | + default: '"Copied"', |
| 205 | + }, |
| 206 | + openLink: { |
| 207 | + description: "Open link button label", |
| 208 | + type: "string", |
| 209 | + default: '"Open link"', |
| 210 | + }, |
| 211 | + }} |
| 212 | +/> |
| 213 | + |
| 214 | +## Partial overrides |
| 215 | + |
| 216 | +The `translations` prop accepts `Partial<StreamdownTranslations>`. Any key you omit falls back to the built-in English default: |
| 217 | + |
| 218 | +```tsx title="app/page.tsx" |
| 219 | +// Only override what you need — everything else stays English |
| 220 | +<Streamdown translations={{ copyCode: "コピー", close: "閉じる" }}> |
| 221 | + {markdown} |
| 222 | +</Streamdown> |
| 223 | +``` |
| 224 | + |
| 225 | +## Access translations in custom components |
| 226 | + |
| 227 | +Use the `useTranslations` hook inside custom components to read the active translations: |
| 228 | + |
| 229 | +```tsx title="app/page.tsx" |
| 230 | +import { useTranslations } from "streamdown"; |
| 231 | + |
| 232 | +function CustomCodeBlock({ children }) { |
| 233 | + const translations = useTranslations(); |
| 234 | + |
| 235 | + return ( |
| 236 | + <div> |
| 237 | + <button>{translations.copyCode}</button> |
| 238 | + <pre><code>{children}</code></pre> |
| 239 | + </div> |
| 240 | + ); |
| 241 | +} |
| 242 | +``` |
| 243 | + |
| 244 | +## Exported types and values |
| 245 | + |
| 246 | +```tsx |
| 247 | +import type { StreamdownTranslations } from "streamdown"; |
| 248 | +import { defaultTranslations, useTranslations } from "streamdown"; |
| 249 | +``` |
| 250 | + |
| 251 | +- `StreamdownTranslations` — interface with all 37 translation keys |
| 252 | +- `defaultTranslations` — the built-in English defaults |
| 253 | +- `useTranslations()` — React hook returning the active translations object |
0 commit comments