Skip to content

Commit

Permalink
docs(i18n): add copy code button title workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Dec 18, 2024
1 parent 730fc08 commit 3eb4374
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions docs/.vitepress/config/shared.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { defineConfig } from 'vitepress'
import { search as zhSearch } from './zh'
import { search as ptSearch } from './pt'
import { search as ruSearch } from './ru'
import { search as esSearch } from './es'
import { search as koSearch } from './ko'
import { search as faSearch } from './fa'
import { search as koSearch } from './ko'
import { search as ptSearch } from './pt'
import { search as ruSearch } from './ru'
import { search as zhSearch } from './zh'

export const shared = defineConfig({
title: 'VitePress',
Expand All @@ -26,7 +26,36 @@ export const shared = defineConfig({
return code.replace(/\[\!\!code/g, '[!code')
}
}
]
],
config(md) {
// TODO: remove when https://github.com/vuejs/vitepress/issues/4431 is fixed
const fence = md.renderer.rules.fence!
md.renderer.rules.fence = function (tokens, idx, options, env, self) {
const { localeIndex = 'root' } = env
const codeCopyButtonTitle = (() => {
switch (localeIndex) {
case 'es':
return 'Copiar código'
case 'fa':
return 'کپی کد'
case 'ko':
return '코드 복사'
case 'pt':
return 'Copiar código'
case 'ru':
return 'Скопировать код'
case 'zh':
return '复制代码'
default:
return 'Copy code'
}
})()
return fence(tokens, idx, options, env, self).replace(
'<button title="Copy Code" class="copy"></button>',
`<button title="${codeCopyButtonTitle}" class="copy"></button>`
)
}
}
},

sitemap: {
Expand Down

0 comments on commit 3eb4374

Please sign in to comment.