Skip to content

Commit a609bd5

Browse files
JohudoDmitrii Zuev
andauthored
feat: added i18n.useTranslation in components (#362)
Co-authored-by: Dmitrii Zuev <zuevda@10.215.207.221-vpn.dhcp.yndx.net>
1 parent 85f8c27 commit a609bd5

9 files changed

Lines changed: 50 additions & 30 deletions

File tree

src/components/ChangelogDialog/ChangelogDialog.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ function getNextId() {
3737
return nextId++;
3838
}
3939

40-
export function ChangelogDialog({
41-
open,
42-
title = i18n('title'),
43-
fullListLink,
44-
items,
45-
disableBodyScrollLock = true,
46-
disableHeightTransition = true,
47-
disableOutsideClick,
48-
onClose,
49-
onStoryClick,
50-
onLinkClick,
51-
onRetryClick,
52-
loading,
53-
error,
54-
className,
55-
}: ChangelogDialogProps) {
40+
export function ChangelogDialog(props: ChangelogDialogProps) {
41+
const {t} = i18n.useTranslation();
42+
43+
const {
44+
open,
45+
title = t('title'),
46+
fullListLink,
47+
items,
48+
disableBodyScrollLock = true,
49+
disableHeightTransition = true,
50+
disableOutsideClick,
51+
onClose,
52+
onStoryClick,
53+
onLinkClick,
54+
onRetryClick,
55+
loading,
56+
error,
57+
className,
58+
} = props;
59+
5660
const idRef = React.useRef<number>();
5761
idRef.current = idRef.current || getNextId();
5862
const dialogCaptionId = `changelog-dialog-title-${idRef.current}`;
@@ -71,7 +75,7 @@ export function ChangelogDialog({
7175
{fullListLink ? (
7276
<Dialog.Body key="full-list-link">
7377
<Link href={fullListLink} target="_blank">
74-
<span>{i18n('link_full_list')}</span>
78+
<span>{t('link_full_list')}</span>
7579
<span className={b('full-list-link-icon')}>
7680
<Icon data={ArrowUpRightFromSquare} size={14} />
7781
</span>
@@ -98,7 +102,7 @@ export function ChangelogDialog({
98102
/>
99103
))
100104
) : (
101-
<div className={b('empty-placeholder')}>{i18n('label_empty')}</div>
105+
<div className={b('empty-placeholder')}>{t('label_empty')}</div>
102106
))}
103107
</Dialog.Body>
104108
</Dialog>

src/components/ChangelogDialog/components/ErrorContainer/ErrorContainer.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@ interface ErrorContainerProps {
1010
}
1111

1212
export function ErrorContainer({onRetryClick, error}: ErrorContainerProps) {
13+
const {t} = i18n.useTranslation();
14+
1315
const {title, description} = React.useMemo(() => {
1416
return error && typeof error === 'object' ? error : {};
1517
}, [error]);
1618

1719
return (
1820
<Alert
19-
title={title || i18n('label_error-title')}
21+
title={title || t('label_error-title')}
2022
message={description}
2123
theme={'danger'}
2224
actions={
2325
onRetryClick && [
2426
{
25-
text: i18n('button_retry'),
27+
text: t('button_retry'),
2628
handler: onRetryClick,
2729
},
2830
]

src/components/ChangelogDialog/components/Item/Item.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const formatLangDisplay = {
3434
};
3535

3636
export function Item({className, data, onStoryClick, onLinkClick}: ItemProps) {
37+
const {t} = i18n.useTranslation();
38+
3739
const handleLinkClick = React.useCallback(() => {
3840
if (onLinkClick && data.link) {
3941
onLinkClick(data.link);
@@ -70,7 +72,7 @@ export function Item({className, data, onStoryClick, onLinkClick}: ItemProps) {
7072
{formattedDate ? <div className={b('date')}>{formattedDate}</div> : null}
7173
{data.isNew ? (
7274
<Label className={b('label-new')} theme="info">
73-
{i18n('label_new')}
75+
{t('label_new')}
7476
</Label>
7577
) : null}
7678
</div>
@@ -95,7 +97,7 @@ export function Item({className, data, onStoryClick, onLinkClick}: ItemProps) {
9597
target={'_blank'}
9698
onClick={handleLinkClick}
9799
>
98-
{i18n('action_read-more')}
100+
{t('action_read-more')}
99101
</Button>
100102
) : null}
101103
{data.storyId && onStoryClick ? (
@@ -104,7 +106,7 @@ export function Item({className, data, onStoryClick, onLinkClick}: ItemProps) {
104106
view="outlined-action"
105107
onClick={handleStoryClick}
106108
>
107-
{i18n('button_view_story')}
109+
{t('button_view_story')}
108110
<Icon data={CirclePlay} size={14} />
109111
</Button>
110112
) : null}

src/components/FormRow/FormRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const FormRowComponent = ({
1919
children,
2020
direction = 'row',
2121
}: FormRowProps) => {
22+
const {t} = i18n.useTranslation();
23+
2224
const LabelComponent = fieldId ? 'label' : 'span';
2325

2426
return (
@@ -32,7 +34,7 @@ const FormRowComponent = ({
3234
&nbsp;
3335
<sup
3436
className={b('required-mark')}
35-
aria-label={i18n('label_required-field')}
37+
aria-label={t('label_required-field')}
3638
>
3739
*
3840
</sup>

src/components/Notifications/Notifications.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import './Notifications.scss';
1515
const b = block('notifications');
1616

1717
export const Notifications = React.memo(function Notifications(props: NotificationsProps) {
18+
const {t} = i18n.useTranslation();
19+
1820
let content: JSX.Element;
1921

2022
const visibleNotificationsCount = props.notifications.filter((n) => !n.archived).length;
@@ -53,7 +55,7 @@ export const Notifications = React.memo(function Notifications(props: Notificati
5355
);
5456
}
5557

56-
const title = <div className={b('head-title')}>{props.title || i18n('title')}</div>;
58+
const title = <div className={b('head-title')}>{props.title || t('title')}</div>;
5759

5860
return (
5961
<div className={b()} data-qa={props.qa}>

src/components/Notifications/NotificationsEmptyState.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ const nothingFoundSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="172" hei
1515
type Props = {image?: React.ReactNode; title?: React.ReactNode; content?: React.ReactNode};
1616

1717
export const NotificationsEmptyState = React.memo(function NotificationsEmptyState(props: Props) {
18+
const {t} = i18n.useTranslation();
19+
1820
return (
1921
<div className={b('empty')}>
2022
{props.image ? props.image : <Icon data={nothingFoundSvg} size={172} />}
2123
<div className={b('empty-message')}>
22-
<div className={b('empty-title')}>{props.title || i18n('no-notifications')}</div>
24+
<div className={b('empty-title')}>{props.title || t('no-notifications')}</div>
2325
{props.content ? (
2426
<div className={b('empty-message-content')}>{props.content}</div>
2527
) : null}

src/components/Notifications/NotificationsErrorState.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ const errorSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="174" height="17
1515
type Props = {image?: React.ReactNode; title?: React.ReactNode; content?: React.ReactNode};
1616

1717
export const NotificationsErrorState = React.memo(function NotificationsEmptyState(props: Props) {
18+
const {t} = i18n.useTranslation();
19+
1820
return (
1921
<div className={b('empty')}>
2022
{props.image ? props.image : <Icon data={errorSvg} width="174" height="172" />}
2123
<div className={b('empty-message')}>
22-
<div className={b('empty-title')}>{props.title || i18n('notifications-error')}</div>
24+
<div className={b('empty-title')}>{props.title || t('notifications-error')}</div>
2325
{props.content ? (
2426
<div className={b('empty-message-content')}>{props.content}</div>
2527
) : null}

src/components/Reactions/Reactions.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ export function Reactions<AddReactionRef extends HTMLElement = HTMLButtonElement
162162
renderAddReaction,
163163
renderReactionsContent,
164164
}: ReactionsProps<AddReactionRef>) {
165+
const {t} = i18n.useTranslation();
166+
165167
const addReactionButtonRef = React.useRef<HTMLButtonElement>(null);
166168
const addReactionRef = React.useRef<AddReactionRef>(null);
167169

@@ -243,7 +245,7 @@ export function Reactions<AddReactionRef extends HTMLElement = HTMLButtonElement
243245
<Button
244246
ref={addReactionButtonRef}
245247
size={size}
246-
aria-label={i18n('add-reaction')}
248+
aria-label={t('add-reaction')}
247249
aria-expanded={palettePopupOpened}
248250
aria-haspopup={true}
249251
aria-controls={popupId}
@@ -258,7 +260,7 @@ export function Reactions<AddReactionRef extends HTMLElement = HTMLButtonElement
258260
</Button.Icon>
259261
</Button>
260262
);
261-
}, [readOnly, renderAddReaction, size, onTogglePalettePopup, palettePopupOpened]);
263+
}, [readOnly, renderAddReaction, size, onTogglePalettePopup, palettePopupOpened, t]);
262264

263265
const addReactionPopup = readOnly ? null : (
264266
<Popup

src/components/Stories/components/StoriesLayout/StoriesLayout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export const StoriesLayout = ({
4040
handleGotoNext,
4141
handleGotoPrevious,
4242
}: StoriesLayoutProps) => {
43+
const {t} = i18n.useTranslation();
44+
4345
const currentStory = items[storyIndex];
4446

4547
return (
@@ -99,7 +101,7 @@ export const StoriesLayout = ({
99101
{currentStory.url && (
100102
<div className={b('story-link-block')}>
101103
<Link href={currentStory.url} target={'_blank'}>
102-
{i18n('label_more')}
104+
{t('label_more')}
103105
</Link>
104106
</div>
105107
)}

0 commit comments

Comments
 (0)