mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-08-02 17:11:48 +00:00
Refactored TranslatedTag component from class-based to functional
This commit is contained in:
@@ -1,9 +1,4 @@
|
|||||||
import {FormattedMessage, injectIntl, WrappedComponentProps} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
import * as React from 'react';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
tag: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const TAG_DESCRIPTIONS = new Map([
|
const TAG_DESCRIPTIONS = new Map([
|
||||||
['ADOP', 'Adoption'],
|
['ADOP', 'Adoption'],
|
||||||
@@ -29,8 +24,12 @@ const TAG_DESCRIPTIONS = new Map([
|
|||||||
['WWW', 'WWW'],
|
['WWW', 'WWW'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function translateTag(tag: string) {
|
interface Props {
|
||||||
const normalizedTag = tag.replace(/_/g, '');
|
tag: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TranslatedTag(props: Props) {
|
||||||
|
const normalizedTag = props.tag.replace(/_/g, '');
|
||||||
return (
|
return (
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id={`gedcom.${normalizedTag}`}
|
id={`gedcom.${normalizedTag}`}
|
||||||
@@ -38,14 +37,3 @@ function translateTag(tag: string) {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class TranslatedTagComponent extends React.Component<
|
|
||||||
Props & WrappedComponentProps,
|
|
||||||
{}
|
|
||||||
> {
|
|
||||||
render() {
|
|
||||||
return translateTag(this.props.tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TranslatedTag = injectIntl(TranslatedTagComponent);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user