Skip to content

Commit 4813dd7

Browse files
fix(lesson): i18n code-block copy button (was hardcoded Spanish) (#303)
CodeBlock copy button rendered 'Copiar'/'Copiado'/'Código' literally, showing Spanish on the /en/ locale. Wire it to next-intl via new components.codeBlock namespace (en + es). Found during QA of #286 (core lesson flow). Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cea7395 commit 4813dd7

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

components/lesson/code-block.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { useState, useEffect } from 'react'
4+
import { useTranslations } from 'next-intl'
45
import { cn } from '@/lib/utils'
56
import { IconCopy, IconCheck, IconFile } from '@tabler/icons-react'
67

@@ -21,6 +22,7 @@ export function CodeBlock({
2122
highlightLines = [],
2223
className,
2324
}: CodeBlockProps) {
25+
const t = useTranslations('components.codeBlock')
2426
const [copied, setCopied] = useState(false)
2527
const [highlightedHtml, setHighlightedHtml] = useState<string | null>(null)
2628

@@ -90,24 +92,24 @@ export function CodeBlock({
9092
) : language ? (
9193
<span className="uppercase">{language}</span>
9294
) : (
93-
<span>Código</span>
95+
<span>{t('code')}</span>
9496
)}
9597
</div>
9698
<button
9799
type="button"
98100
onClick={handleCopy}
99101
className="flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-400 hover:bg-gray-700 hover:text-gray-200 transition-colors"
100-
aria-label={copied ? 'Copiado' : 'Copiar código'}
102+
aria-label={copied ? t('copiedAriaLabel') : t('copyAriaLabel')}
101103
>
102104
{copied ? (
103105
<>
104106
<IconCheck className="size-4 text-green-400" />
105-
<span>Copiado</span>
107+
<span>{t('copied')}</span>
106108
</>
107109
) : (
108110
<>
109111
<IconCopy className="size-4" />
110-
<span>Copiar</span>
112+
<span>{t('copy')}</span>
111113
</>
112114
)}
113115
</button>
3.94 MB
Loading

messages/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,6 +3120,13 @@
31203120
"finishCourse": "Finish Course",
31213121
"completeFirst": "Complete this lesson first"
31223122
},
3123+
"codeBlock": {
3124+
"copy": "Copy",
3125+
"copied": "Copied",
3126+
"copyAriaLabel": "Copy code",
3127+
"copiedAriaLabel": "Copied",
3128+
"code": "Code"
3129+
},
31233130
"lessonComments": {
31243131
"title": "Comments ({count})",
31253132
"placeholder": "Share your thoughts or ask a question...",

messages/es.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,6 +2965,13 @@
29652965
"finishCourse": "Finalizar Curso",
29662966
"completeFirst": "Completa esta lección primero"
29672967
},
2968+
"codeBlock": {
2969+
"copy": "Copiar",
2970+
"copied": "Copiado",
2971+
"copyAriaLabel": "Copiar código",
2972+
"copiedAriaLabel": "Copiado",
2973+
"code": "Código"
2974+
},
29682975
"lessonComments": {
29692976
"title": "Comentarios ({count})",
29702977
"placeholder": "Comparte tus pensamientos o haz una pregunta...",

0 commit comments

Comments
 (0)