diff --git a/.storybook/decorators/withLang.tsx b/.storybook/decorators/withLang.tsx index a66847da..6e6cd226 100644 --- a/.storybook/decorators/withLang.tsx +++ b/.storybook/decorators/withLang.tsx @@ -1,14 +1,10 @@ import React from 'react'; -import {configure as uiKitConfigure} from '@gravity-ui/uikit'; +import {configure} from '@gravity-ui/uikit'; import type {Decorator} from '@storybook/react'; -import {configure} from '../../src'; - export const withLang: Decorator = (Story, context) => { const lang = context.globals.lang; - - uiKitConfigure({lang}); configure({lang}); return ; diff --git a/src/components/AdaptiveTabs/AdaptiveTabs.tsx b/src/components/AdaptiveTabs/AdaptiveTabs.tsx index e79db95a..a94c69c5 100644 --- a/src/components/AdaptiveTabs/AdaptiveTabs.tsx +++ b/src/components/AdaptiveTabs/AdaptiveTabs.tsx @@ -9,7 +9,7 @@ import ResizeObserver from 'resize-observer-polyfill'; import {block} from '../utils/cn'; import {DEFAULT_BREAK_POINTS_CONFIG} from './constants'; -import i18n from './i18n'; +import {i18n} from './i18n'; import './AdaptiveTabs.scss'; diff --git a/src/components/AdaptiveTabs/i18n/index.ts b/src/components/AdaptiveTabs/i18n/index.ts index e6ede6fc..7945f558 100644 --- a/src/components/AdaptiveTabs/i18n/index.ts +++ b/src/components/AdaptiveTabs/i18n/index.ts @@ -1,7 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'AdaptiveTabs'; -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}adaptive-tabs`); diff --git a/src/components/ChangelogDialog/ChangelogDialog.tsx b/src/components/ChangelogDialog/ChangelogDialog.tsx index e599f4de..e9b13675 100644 --- a/src/components/ChangelogDialog/ChangelogDialog.tsx +++ b/src/components/ChangelogDialog/ChangelogDialog.tsx @@ -8,7 +8,7 @@ import {block} from '../utils/cn'; import {ErrorContainer} from './components/ErrorContainer/ErrorContainer'; import {Item} from './components/Item/Item'; -import i18n from './i18n'; +import {i18n} from './i18n'; import type {ChangelogItem} from './types'; import './ChangelogDialog.scss'; diff --git a/src/components/ChangelogDialog/components/ErrorContainer/ErrorContainer.tsx b/src/components/ChangelogDialog/components/ErrorContainer/ErrorContainer.tsx index d970b604..10edef56 100644 --- a/src/components/ChangelogDialog/components/ErrorContainer/ErrorContainer.tsx +++ b/src/components/ChangelogDialog/components/ErrorContainer/ErrorContainer.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {Alert} from '@gravity-ui/uikit'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; interface ErrorContainerProps { onRetryClick?: () => void; diff --git a/src/components/ChangelogDialog/components/Item/Item.tsx b/src/components/ChangelogDialog/components/Item/Item.tsx index 91c3dbbb..9b53d8d6 100644 --- a/src/components/ChangelogDialog/components/Item/Item.tsx +++ b/src/components/ChangelogDialog/components/Item/Item.tsx @@ -4,7 +4,7 @@ import {CirclePlay} from '@gravity-ui/icons'; import {Button, Icon, Label} from '@gravity-ui/uikit'; import {block} from '../../../utils/cn'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; import type {ChangelogItem} from '../../types'; import {Picture} from '../Picture/Picture'; diff --git a/src/components/ChangelogDialog/i18n/index.ts b/src/components/ChangelogDialog/i18n/index.ts index 4fa1f2aa..3b7e90ae 100644 --- a/src/components/ChangelogDialog/i18n/index.ts +++ b/src/components/ChangelogDialog/i18n/index.ts @@ -1,8 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'ChangelogDialog'; - -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}changelog-dialog`); diff --git a/src/components/CookieConsent/components/ConsentNotification/ConsentNotification.tsx b/src/components/CookieConsent/components/ConsentNotification/ConsentNotification.tsx index b770a398..a573518b 100644 --- a/src/components/CookieConsent/components/ConsentNotification/ConsentNotification.tsx +++ b/src/components/CookieConsent/components/ConsentNotification/ConsentNotification.tsx @@ -3,7 +3,7 @@ import React from 'react'; import {Alert, Button, Link, useMobile} from '@gravity-ui/uikit'; import {block} from '../../../utils/cn'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; import {ConsentNotificationProps} from './types'; diff --git a/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx b/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx index 61e94a6f..6ce4b483 100644 --- a/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx +++ b/src/components/CookieConsent/components/ConsentPopup/ConsentPopup.tsx @@ -6,7 +6,7 @@ import {Button, Icon, Link, Modal, Text, useDirection, useMobile} from '@gravity import {block} from '../../../utils/cn'; import {ConsentType} from '../../ConsentManager'; import type {Consents} from '../../ConsentManager'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; import {FoldableList} from '../FoldableList/FoldableList'; import { diff --git a/src/components/CookieConsent/components/SimpleConsent/SimpleConsent.tsx b/src/components/CookieConsent/components/SimpleConsent/SimpleConsent.tsx index 7ba59aac..579448ce 100644 --- a/src/components/CookieConsent/components/SimpleConsent/SimpleConsent.tsx +++ b/src/components/CookieConsent/components/SimpleConsent/SimpleConsent.tsx @@ -3,7 +3,7 @@ import React from 'react'; import {Button, Portal} from '@gravity-ui/uikit'; import {block} from '../../../utils/cn'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; import {SimpleConsentProps} from './types'; diff --git a/src/components/CookieConsent/i18n/index.ts b/src/components/CookieConsent/i18n/index.ts index 947850d3..43318a04 100644 --- a/src/components/CookieConsent/i18n/index.ts +++ b/src/components/CookieConsent/i18n/index.ts @@ -1,7 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'CookieConsent'; -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}cookie-consent`); diff --git a/src/components/FormRow/FormRow.tsx b/src/components/FormRow/FormRow.tsx index 0add23e7..64fedb94 100644 --- a/src/components/FormRow/FormRow.tsx +++ b/src/components/FormRow/FormRow.tsx @@ -3,7 +3,7 @@ import React from 'react'; import {block} from '../utils/cn'; import {FormRowFieldDescription} from './FormRowFieldDescription'; -import i18n from './i18n'; +import {i18n} from './i18n'; import {FormRowProps} from './types'; import './FormRow.scss'; diff --git a/src/components/FormRow/i18n/index.ts b/src/components/FormRow/i18n/index.ts index cb0446db..642ebde9 100644 --- a/src/components/FormRow/i18n/index.ts +++ b/src/components/FormRow/i18n/index.ts @@ -1,8 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'FormRow'; - -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}form-row`); diff --git a/src/components/ItemSelector/ItemSelector.tsx b/src/components/ItemSelector/ItemSelector.tsx index c621f462..d29b1d50 100644 --- a/src/components/ItemSelector/ItemSelector.tsx +++ b/src/components/ItemSelector/ItemSelector.tsx @@ -5,7 +5,7 @@ import {Button, Icon, List, ListProps} from '@gravity-ui/uikit'; import {block} from '../utils/cn'; -import i18n from './i18n'; +import {i18n} from './i18n'; import './ItemSelector.scss'; diff --git a/src/components/ItemSelector/i18n/index.ts b/src/components/ItemSelector/i18n/index.ts index 7c00f1d9..8141cf11 100644 --- a/src/components/ItemSelector/i18n/index.ts +++ b/src/components/ItemSelector/i18n/index.ts @@ -1,7 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'ItemSelector'; -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}item-selector`); diff --git a/src/components/Notifications/Notifications.tsx b/src/components/Notifications/Notifications.tsx index 9b7e42c3..183f01f8 100644 --- a/src/components/Notifications/Notifications.tsx +++ b/src/components/Notifications/Notifications.tsx @@ -8,7 +8,7 @@ import {NotificationsErrorState} from './NotificationsErrorState'; import {NotificationsList} from './NotificationsList'; import {NotificationsLoadingState} from './NotificationsLoadingState'; import {NotificationsProps} from './definitions'; -import i18n from './i18n'; +import {i18n} from './i18n'; import './Notifications.scss'; diff --git a/src/components/Notifications/NotificationsEmptyState.tsx b/src/components/Notifications/NotificationsEmptyState.tsx index 1dea598f..fd304a78 100644 --- a/src/components/Notifications/NotificationsEmptyState.tsx +++ b/src/components/Notifications/NotificationsEmptyState.tsx @@ -4,7 +4,7 @@ import {Icon} from '@gravity-ui/uikit'; import {block} from '../utils/cn'; -import i18n from './i18n/index'; +import {i18n} from './i18n/index'; import './Notifications.scss'; diff --git a/src/components/Notifications/NotificationsErrorState.tsx b/src/components/Notifications/NotificationsErrorState.tsx index decacf0f..b186f48b 100644 --- a/src/components/Notifications/NotificationsErrorState.tsx +++ b/src/components/Notifications/NotificationsErrorState.tsx @@ -4,7 +4,7 @@ import {Icon} from '@gravity-ui/uikit'; import {block} from '../utils/cn'; -import i18n from './i18n/index'; +import {i18n} from './i18n/index'; import './Notifications.scss'; diff --git a/src/components/Notifications/i18n/index.ts b/src/components/Notifications/i18n/index.ts index 3c37d95a..5db018d7 100644 --- a/src/components/Notifications/i18n/index.ts +++ b/src/components/Notifications/i18n/index.ts @@ -1,7 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'Notifications'; -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}notifications`); diff --git a/src/components/PasswordInput/PasswordInput.tsx b/src/components/PasswordInput/PasswordInput.tsx index 4d9ac776..009d4ffb 100644 --- a/src/components/PasswordInput/PasswordInput.tsx +++ b/src/components/PasswordInput/PasswordInput.tsx @@ -12,7 +12,7 @@ import { import {block} from '../utils/cn'; -import i18n from './i18n'; +import {i18n} from './i18n'; import {getActionButtonSizeAndIconSize} from './utils'; import './PasswordInput.scss'; diff --git a/src/components/PasswordInput/i18n/index.ts b/src/components/PasswordInput/i18n/index.ts index a79a9a36..3d9c4adb 100644 --- a/src/components/PasswordInput/i18n/index.ts +++ b/src/components/PasswordInput/i18n/index.ts @@ -1,8 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'PasswordInput'; - -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}password-input`); diff --git a/src/components/SharePopover/ShareList/ShareList.tsx b/src/components/SharePopover/ShareList/ShareList.tsx index 87fccc63..56219a04 100644 --- a/src/components/SharePopover/ShareList/ShareList.tsx +++ b/src/components/SharePopover/ShareList/ShareList.tsx @@ -8,7 +8,7 @@ import {block} from '../../utils/cn'; import {isOfType} from '../../utils/isOfType'; import {ShareListItem} from '../ShareListItem/ShareListItem'; import type {LayoutDirection, ShareOptions} from '../constants'; -import i18n from '../i18n'; +import {i18n} from '../i18n'; import type {ShareOptionsData} from '../models'; import './ShareList.scss'; diff --git a/src/components/SharePopover/ShareListItem/ShareListItem.tsx b/src/components/SharePopover/ShareListItem/ShareListItem.tsx index c891c76f..2d696000 100644 --- a/src/components/SharePopover/ShareListItem/ShareListItem.tsx +++ b/src/components/SharePopover/ShareListItem/ShareListItem.tsx @@ -5,7 +5,7 @@ import type {IconData} from '@gravity-ui/uikit'; import {block} from '../../utils/cn'; import {LayoutDirection, ShareOptions} from '../constants'; -import i18n from '../i18n'; +import {i18n} from '../i18n'; import * as icons from '../icons'; import type {ShareOptionsData} from '../models'; diff --git a/src/components/SharePopover/i18n/index.ts b/src/components/SharePopover/i18n/index.ts index 7993027f..0e3ebe4c 100644 --- a/src/components/SharePopover/i18n/index.ts +++ b/src/components/SharePopover/i18n/index.ts @@ -1,8 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'SharePopover'; - -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}share-popover`); diff --git a/src/components/StoreBadge/StoreBadge.tsx b/src/components/StoreBadge/StoreBadge.tsx index 22f7df82..334e27b9 100644 --- a/src/components/StoreBadge/StoreBadge.tsx +++ b/src/components/StoreBadge/StoreBadge.tsx @@ -1,14 +1,12 @@ import React from 'react'; -import {Icon, Link, LinkProps} from '@gravity-ui/uikit'; +import {Icon, Lang, Link, LinkProps} from '@gravity-ui/uikit'; -import {i18n} from '../../i18n'; import {AppStoreEn} from '../../icons/stores/AppStoreEn'; import {AppStoreRu} from '../../icons/stores/AppStoreRu'; import {GooglePlayEn} from '../../icons/stores/GooglePlayEn'; import {GooglePlayRu} from '../../icons/stores/GooglePlayRu'; import {cn} from '../utils/cn'; -import {Lang} from '../utils/configure'; const b = cn('store-badge'); @@ -20,6 +18,7 @@ export type StoreBadgePlatform = typeof androidPlatform | typeof iosPlatform; export interface StoreBadgeProps extends Omit { /** store platform name */ platform: StoreBadgePlatform; + lang?: `${Lang}`; onClick?: React.MouseEventHandler; } @@ -42,9 +41,10 @@ export const StoreBadge = ({ className, onClick, href, + lang = Lang.En, ...restLinkProps }: StoreBadgeProps) => { - const lang = i18n.lang as Lang; + // const lang = i18n.lang as Lang; const iconData = badgeData?.[platform][lang]; if (!iconData) { diff --git a/src/components/Stories/components/StoriesLayout/StoriesLayout.tsx b/src/components/Stories/components/StoriesLayout/StoriesLayout.tsx index 896567f6..16e290c1 100644 --- a/src/components/Stories/components/StoriesLayout/StoriesLayout.tsx +++ b/src/components/Stories/components/StoriesLayout/StoriesLayout.tsx @@ -6,7 +6,7 @@ import type {ButtonProps} from '@gravity-ui/uikit'; import {MediaRenderer} from '..'; import {block} from '../../../utils/cn'; -import i18n from '../../i18n'; +import {i18n} from '../../i18n'; import type {StoriesItem} from '../../types'; import './StoriesLayout.scss'; diff --git a/src/components/Stories/i18n/index.ts b/src/components/Stories/i18n/index.ts index b43a82ff..60ce051c 100644 --- a/src/components/Stories/i18n/index.ts +++ b/src/components/Stories/i18n/index.ts @@ -1,8 +1,8 @@ -import {registerKeyset} from '../../utils/registerKeyset'; +import {addComponentKeysets} from '@gravity-ui/uikit/i18n'; + +import {NAMESPACE} from '../../utils/cn'; import en from './en.json'; import ru from './ru.json'; -const COMPONENT = 'Stories'; - -export default registerKeyset({en, ru}, COMPONENT); +export const i18n = addComponentKeysets({en, ru}, `${NAMESPACE}stories`); diff --git a/src/components/index.ts b/src/components/index.ts index a7534a32..bedffe9c 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -17,5 +17,3 @@ export * from './SharePopover'; export * from './StoreBadge'; export * from './Stories'; export * from './StoriesGroup'; - -export {Lang, configure} from './utils/configure'; diff --git a/src/components/utils/configure.ts b/src/components/utils/configure.ts deleted file mode 100644 index 89f4f2cd..00000000 --- a/src/components/utils/configure.ts +++ /dev/null @@ -1,33 +0,0 @@ -export enum Lang { - Ru = 'ru', - En = 'en', -} - -interface Config { - lang: `${Lang}`; -} - -type Subscriber = (config: Config) => void; - -let subs: Subscriber[] = []; - -const config: Config = { - lang: Lang.En, -}; - -export const configure = (newConfig: Partial) => { - Object.assign(config, newConfig); - subs.forEach((sub) => { - sub(config); - }); -}; - -export const subscribeConfigure = (sub: Subscriber) => { - subs.push(sub); - - return () => { - subs = subs.filter((item) => item !== sub); - }; -}; - -export const getConfig = () => config; diff --git a/src/components/utils/registerKeyset.ts b/src/components/utils/registerKeyset.ts deleted file mode 100644 index b5d97a60..00000000 --- a/src/components/utils/registerKeyset.ts +++ /dev/null @@ -1,11 +0,0 @@ -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/src/i18n.ts b/src/i18n.ts deleted file mode 100644 index 90f2b77a..00000000 --- a/src/i18n.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {I18N} from '@gravity-ui/i18n'; - -import {getConfig, subscribeConfigure} from './components/utils/configure'; - -export const i18n = new I18N(); - -i18n.setLang(getConfig().lang); - -subscribeConfigure((config) => { - i18n.setLang(config.lang); -}); diff --git a/test-utils/setup-tests.ts b/test-utils/setup-tests.ts index f9c06f47..0ef1710f 100644 --- a/test-utils/setup-tests.ts +++ b/test-utils/setup-tests.ts @@ -1,10 +1,5 @@ import {configure} from '@testing-library/dom'; -import {Lang, configure as libConfigure} from '../src'; - -libConfigure({ - lang: Lang.En, -}); configure({testIdAttribute: 'data-qa'}); global.ResizeObserver = class implements ResizeObserver {