Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit befd3a8

Browse files
Feat (i18n): Added possibility to translate copy button (#3148)
* Feat (i18n): Added possibility to translate copy button * Fix: Format fix * Fix: Changed to default translation * fix: code format * update test for useCopyToClipboard Co-authored-by: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com>
1 parent 4e9dfaf commit befd3a8

File tree

9 files changed

+30
-15
lines changed

9 files changed

+30
-15
lines changed

src/components/ArticleComponents/Codebox/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2+
import { FormattedMessage } from 'react-intl';
23
import { highlight, languages } from 'prismjs';
34
import { sanitize } from 'isomorphic-dompurify';
45
import classnames from 'classnames';
@@ -62,7 +63,7 @@ const Codebox = ({ children: { props } }: Props): JSX.Element => {
6263
<div className={styles.top}>
6364
<span>{replaceLabelLanguages(language)}</span>
6465
<button type="button" onClick={handleCopyCode}>
65-
{copied ? 'copied' : 'copy'}
66+
<FormattedMessage id="components.codeBox.copy" values={{ copied }} />
6667
</button>
6768
</div>
6869
<div

src/components/CommonComponents/ShellBox/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { FormattedMessage } from 'react-intl';
23
import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard';
34
import styles from './index.module.scss';
45

@@ -22,7 +23,7 @@ const ShellBox = ({
2223
<div className={styles.top}>
2324
<span>SHELL</span>
2425
<button type="button" onClick={handleCopyCode}>
25-
{copied ? 'copied' : 'copy'}
26+
<FormattedMessage id="components.shellBox.copy" values={{ copied }} />
2627
</button>
2728
</div>
2829
<code>{children}</code>

src/hooks/__tests__/useCopyToClipboard.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { render, fireEvent, screen, waitFor } from '@testing-library/react';
3+
import { FormattedMessage } from 'react-intl';
34
import { useCopyToClipboard } from '../useCopyToClipboard';
45

56
describe('useCopyToClipboard', () => {
@@ -8,7 +9,7 @@ describe('useCopyToClipboard', () => {
89

910
return (
1011
<button onClick={() => copyText(text)} type="button">
11-
{copied ? 'copied' : 'copy'}
12+
<FormattedMessage id="components.codeBox.copy" values={{ copied }} />
1213
</button>
1314
);
1415
};

src/i18n/locales/en.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "Blog category for Node.js Release announcements",
9696
"blog.categories.vulnerability.description": "Blog category regarding Security Vulnerabilities",
9797
"components.downloadToggle.ltsVersions": "LTS Versions",
98-
"components.downloadToggle.currentVersions": "Current Versions"
99-
}
98+
"components.downloadToggle.currentVersions": "Current Versions",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

src/i18n/locales/es.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "Blog category for Node.js Release announcements",
9696
"blog.categories.vulnerability.description": "Blog category regarding Security Vulnerabilities",
9797
"components.downloadToggle.ltsVersions": "LTS Versions",
98-
"components.downloadToggle.currentVersions": "Current Versions"
99-
}
98+
"components.downloadToggle.currentVersions": "Current Versions",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

src/i18n/locales/fr.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "Catégorie de blog pour les annonces des versions de Node.js",
9696
"blog.categories.vulnerability.description": "Catégorie de blog concernant les vulnérabilités de sécurité",
9797
"components.downloadToggle.ltsVersions": "LTS Versions",
98-
"components.downloadToggle.currentVersions": "Versions actuelles"
99-
}
98+
"components.downloadToggle.currentVersions": "Versions actuelles",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

src/i18n/locales/he.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "קטגוריית הבלוגים של Node.js לגבי כל השחרורים",
9696
"blog.categories.vulnerability.description": "קטגוריית בלוג בנושא פגיעויות אבטחה",
9797
"components.downloadToggle.ltsVersions": "גרסאות LTS",
98-
"components.downloadToggle.currentVersions": "גרסאות נוכחיות"
99-
}
98+
"components.downloadToggle.currentVersions": "גרסאות נוכחיות",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

src/i18n/locales/ja.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "Node.jsのリリース案内カテゴリ",
9696
"blog.categories.vulnerability.description": "セキュリティや脆弱性カテゴリ",
9797
"components.downloadToggle.ltsVersions": "LTSバージョン",
98-
"components.downloadToggle.currentVersions": "現在のバージョン"
99-
}
98+
"components.downloadToggle.currentVersions": "現在のバージョン",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

src/i18n/locales/zh-cn.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,7 @@
9595
"blog.categories.release.description": "关于 Node.js 所有的发布信息",
9696
"blog.categories.vulnerability.description": "涉及到安全隐患方面的所有信息",
9797
"components.downloadToggle.ltsVersions": "长期维护版(LTS)",
98-
"components.downloadToggle.currentVersions": "尝鲜版"
99-
}
98+
"components.downloadToggle.currentVersions": "尝鲜版",
99+
"components.shellBox.copy": "{copied, select, true {copied}other {copy}}",
100+
"components.codeBox.copy": "{copied, select, true {copied}other {copy}}"
101+
}

0 commit comments

Comments
 (0)