From d48b1b9d72f26fdc373074861673cb0a712eb12d Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 3 Aug 2022 13:31:36 +0300 Subject: [PATCH] chore(Toaster): add close button label (#288) --- src/components/Toaster/Toast/Toast.tsx | 8 +++++++- src/components/Toaster/i18n/en.json | 3 +++ src/components/Toaster/i18n/index.ts | 13 +++++++++++++ src/components/Toaster/i18n/ru.json | 3 +++ src/components/utils/registerKeyset.ts | 10 ++++++++++ test-utils/setup-tests.ts | 2 +- 6 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/components/Toaster/i18n/en.json create mode 100644 src/components/Toaster/i18n/index.ts create mode 100644 src/components/Toaster/i18n/ru.json create mode 100644 src/components/utils/registerKeyset.ts diff --git a/src/components/Toaster/Toast/Toast.tsx b/src/components/Toaster/Toast/Toast.tsx index 960701f994..75142dfb5e 100644 --- a/src/components/Toaster/Toast/Toast.tsx +++ b/src/components/Toaster/Toast/Toast.tsx @@ -5,6 +5,7 @@ import {Icon, IconProps} from '../../Icon'; import {Button} from '../../Button'; import {Alarm, CrossIcon, Info, Success} from '../../icons'; import type {ToastAction, ToastProps, ToastType} from '../types'; +import i18n from '../i18n'; import './Toast.scss'; @@ -212,7 +213,12 @@ export function Toast(props: ToastUnitedProps) { {renderIcon({type})}

{title}

{isClosable && ( - )} diff --git a/src/components/Toaster/i18n/en.json b/src/components/Toaster/i18n/en.json new file mode 100644 index 0000000000..df760d7e03 --- /dev/null +++ b/src/components/Toaster/i18n/en.json @@ -0,0 +1,3 @@ +{ + "label_close-button": "Close" +} diff --git a/src/components/Toaster/i18n/index.ts b/src/components/Toaster/i18n/index.ts new file mode 100644 index 0000000000..2a312951da --- /dev/null +++ b/src/components/Toaster/i18n/index.ts @@ -0,0 +1,13 @@ +import {registerKeyset} from '../../utils/registerKeyset'; +import en from './en.json'; +import ru from './ru.json'; + +const COMPONENT = 'Toaster'; + +export default registerKeyset( + { + en, + ru, + }, + COMPONENT, +); diff --git a/src/components/Toaster/i18n/ru.json b/src/components/Toaster/i18n/ru.json new file mode 100644 index 0000000000..b368bc0ad3 --- /dev/null +++ b/src/components/Toaster/i18n/ru.json @@ -0,0 +1,3 @@ +{ + "label_close-button": "Закрыть" +} diff --git a/src/components/utils/registerKeyset.ts b/src/components/utils/registerKeyset.ts new file mode 100644 index 0000000000..a76b9da7a2 --- /dev/null +++ b/src/components/utils/registerKeyset.ts @@ -0,0 +1,10 @@ +import {i18n} from '../../i18n'; +import {Lang} from './configure'; + +type KeysData = Parameters[2]; + +export function registerKeyset(data: Record, keysetName: string) { + Object.entries(data).forEach(([lang, keys]) => i18n.registerKeyset(lang, keysetName, keys)); + + return i18n.keyset(keysetName); +} diff --git a/test-utils/setup-tests.ts b/test-utils/setup-tests.ts index 655a92b207..9bb540cfc8 100644 --- a/test-utils/setup-tests.ts +++ b/test-utils/setup-tests.ts @@ -1,4 +1,4 @@ -import {configure as libConfigure, Lang} from '../src/components/utils/configure'; +import {configure as libConfigure, Lang} from '../src'; import {configure} from '@testing-library/dom'; libConfigure({