Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
♻️ Simplify structure of localizations components
Browse files Browse the repository at this point in the history
  • Loading branch information
cermakjiri committed Dec 1, 2021
1 parent 375f38d commit e2ec903
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 97 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { translateSelector } from '@ackee/jerome';
import type { ReactNode } from 'react';
import {
intlData,
// @use-antd-module-begin
antdData,
// @use-antd-module-end
} from '../../config';

import LocalizationsRaw from '../LocalizationsRaw'
import type { LocalizationsRawProps } from '../LocalizationsRaw'
// @use-antd-module-begin
import { LocalizationsAntd } from '../LocalizationsAntd';
// @use-antd-module-end
import { LocalizationsRaw } from '../LocalizationsRaw';

export interface LocalizationsProps extends Omit<LocalizationsRawProps, 'locale'> {
interface AppLocalizationsProps {
children: ReactNode | ReactNode[];
}

const Localizations = (props: LocalizationsProps) => {
const { locale } = useSelector(translateSelector)

return (
<LocalizationsRaw locale={locale} {...props} />
)
}

export default Localizations;
export const Localizations = ({ children }: AppLocalizationsProps) => (
// @use-antd-module-begin
<LocalizationsAntd antdLocaleData={antdData}>
{/* // @use-antd-module-end */}
<LocalizationsRaw intlMessages={intlData}>{children}</LocalizationsRaw>
{/* // @use-antd-module-begin */}
</LocalizationsAntd>
// @use-antd-module-end
);
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from './Localizations';
export type { LocalizationsProps } from './Localizations';
export * from './Localizations';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import type { ReactNode } from 'react';
import ConfigProvider from 'antd/es/config-provider';
import type { Locale as AntdLocaleData } from 'antd/es/locale-provider';
import { useSelector } from 'react-redux';
import { translateSelector } from '@ackee/jerome';

export interface LocalizationsAntdProps {
antdLocaleData: Record<string, AntdLocaleData>;
children: ReactNode;
}

export const LocalizationsAntd = ({ antdLocaleData, children }: LocalizationsAntdProps) => {
const { locale } = useSelector(translateSelector);

return <ConfigProvider locale={antdLocaleData[locale]}>{children}</ConfigProvider>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './LocalizationsAntd';
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import React from 'react';
import type { ReactNode } from 'react';
import { IntlProvider } from 'react-intl';
import type { IntlConfig } from 'react-intl';
import { useSelector } from 'react-redux';
import { translateSelector } from '@ackee/jerome';

export interface LocalizationsRawProps {
locale: string;
intlMessages: Record<string, IntlConfig['messages']>
children: ReactNode;
onError?: IntlConfig['onError']
intlMessages: Record<string, IntlConfig['messages']>;
children: ReactNode | ReactNode[];
onError?: IntlConfig['onError'];
}

const LocalizationsRaw = ({ locale, intlMessages, children, onError }: LocalizationsRawProps) => (
<IntlProvider locale={locale} key={locale} messages={intlMessages[locale]} onError={onError}>
{children}
</IntlProvider>
)
export const LocalizationsRaw = ({ intlMessages, children, onError }: LocalizationsRawProps) => {
const { locale } = useSelector(translateSelector);

export default LocalizationsRaw;
return (
<IntlProvider locale={locale} key={locale} messages={intlMessages[locale]} onError={onError}>
{children}
</IntlProvider>
);
};
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from './LocalizationsRaw';
export type { LocalizationsRawProps } from './LocalizationsRaw';
export * from './LocalizationsRaw';

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as Localizations } from './components/AppLocalizations';
export { Localizations } from './components/Localizations';
export { default as reducer } from './services/reducer';
export { saga } from '@ackee/jerome';

0 comments on commit e2ec903

Please sign in to comment.