Skip to content

Commit 3eb4374

Browse files
committed
docs(i18n): add copy code button title workaround
1 parent 730fc08 commit 3eb4374

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

docs/.vitepress/config/shared.ts

+34-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { defineConfig } from 'vitepress'
2-
import { search as zhSearch } from './zh'
3-
import { search as ptSearch } from './pt'
4-
import { search as ruSearch } from './ru'
52
import { search as esSearch } from './es'
6-
import { search as koSearch } from './ko'
73
import { search as faSearch } from './fa'
4+
import { search as koSearch } from './ko'
5+
import { search as ptSearch } from './pt'
6+
import { search as ruSearch } from './ru'
7+
import { search as zhSearch } from './zh'
88

99
export const shared = defineConfig({
1010
title: 'VitePress',
@@ -26,7 +26,36 @@ export const shared = defineConfig({
2626
return code.replace(/\[\!\!code/g, '[!code')
2727
}
2828
}
29-
]
29+
],
30+
config(md) {
31+
// TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
32+
const fence = md.renderer.rules.fence!
33+
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
34+
const { localeIndex = 'root' } = env
35+
const codeCopyButtonTitle = (() => {
36+
switch (localeIndex) {
37+
case 'es':
38+
return 'Copiar código'
39+
case 'fa':
40+
return 'کپی کد'
41+
case 'ko':
42+
return '코드 복사'
43+
case 'pt':
44+
return 'Copiar código'
45+
case 'ru':
46+
return 'Скопировать код'
47+
case 'zh':
48+
return '复制代码'
49+
default:
50+
return 'Copy code'
51+
}
52+
})()
53+
return fence(tokens, idx, options, env, self).replace(
54+
'<button title="Copy Code" class="copy"></button>',
55+
`<button title="${codeCopyButtonTitle}" class="copy"></button>`
56+
)
57+
}
58+
}
3059
},
3160

3261
sitemap: {

0 commit comments

Comments
 (0)