feat(v2): Extract/translate hardcoded labels from classic theme (#4168)

* Translate theme hardcoded strings

* improve test
This commit is contained in:
Sébastien Lorber 2021-02-03 20:06:26 +01:00 committed by GitHub
parent 823d0fe3c2
commit ab7951571e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 217 additions and 60 deletions

View file

@ -12,6 +12,7 @@ import copy from 'copy-text-to-clipboard';
import rangeParser from 'parse-numeric-range';
import usePrismTheme from '@theme/hooks/usePrismTheme';
import type {Props} from '@theme/CodeBlock';
import Translate from '@docusaurus/Translate';
import styles from './styles.module.css';
import {useThemeConfig} from '@docusaurus/theme-common';
@ -86,11 +87,11 @@ const highlightDirectiveRegex = (lang) => {
};
const codeBlockTitleRegex = /(?:title=")(.*)(?:")/;
export default ({
export default function CodeBlock({
children,
className: languageClassName,
metastring,
}: Props): JSX.Element => {
}: Props): JSX.Element {
const {prism} = useThemeConfig();
const [showCopied, setShowCopied] = useState(false);
@ -242,11 +243,23 @@ export default ({
aria-label="Copy code to clipboard"
className={clsx(styles.copyButton)}
onClick={handleCopyCode}>
{showCopied ? 'Copied' : 'Copy'}
{showCopied ? (
<Translate
id="theme.CodeBlock.copied"
description="The copied button label on code blocks">
Copied
</Translate>
) : (
<Translate
id="theme.CodeBlock.copy"
description="The copy button label on code blocks">
Copy
</Translate>
)}
</button>
</div>
</>
)}
</Highlight>
);
};
}