mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-05-26 23:26:15 +00:00
Translate dates and linkify texts in the details panel
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
"react": "latest",
|
"react": "latest",
|
||||||
"react-dom": "latest",
|
"react-dom": "latest",
|
||||||
"react-intl": "^2.8.0",
|
"react-intl": "^2.8.0",
|
||||||
|
"react-linkify": "^0.2.2",
|
||||||
"react-router-dom": "^4.3.1",
|
"react-router-dom": "^4.3.1",
|
||||||
"semantic-ui-css": "^2.4.1",
|
"semantic-ui-css": "^2.4.1",
|
||||||
"semantic-ui-react": "^0.84.0",
|
"semantic-ui-react": "^0.84.0",
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import flatMap from 'array.prototype.flatmap';
|
||||||
|
import Linkify from 'react-linkify';
|
||||||
|
import {formatDate, getDate} from 'topola';
|
||||||
|
import {FormattedMessage} from 'react-intl';
|
||||||
import {GedcomData} from './gedcom_util';
|
import {GedcomData} from './gedcom_util';
|
||||||
import {GedcomEntry} from 'parse-gedcom';
|
import {GedcomEntry} from 'parse-gedcom';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {intlShape} from 'react-intl';
|
||||||
import flatMap from 'array.prototype.flatmap';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
gedcom: GedcomData;
|
gedcom: GedcomData;
|
||||||
@@ -33,11 +36,20 @@ function translateTag(tag: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function eventDetails(entry: GedcomEntry, tag: string) {
|
function translateDate(gedcomDate: string, locale: string) {
|
||||||
|
const dateOrRange = getDate(gedcomDate);
|
||||||
|
const date = dateOrRange && dateOrRange.date;
|
||||||
|
if (!date) {
|
||||||
|
return gedcomDate;
|
||||||
|
}
|
||||||
|
return formatDate(date, locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
function eventDetails(entry: GedcomEntry, tag: string, locale: string) {
|
||||||
const lines = [];
|
const lines = [];
|
||||||
const date = entry.tree.find((subentry) => subentry.tag === 'DATE');
|
const date = entry.tree.find((subentry) => subentry.tag === 'DATE');
|
||||||
if (date && date.data) {
|
if (date && date.data) {
|
||||||
lines.push(date.data);
|
lines.push(translateDate(date.data, locale));
|
||||||
}
|
}
|
||||||
const place = entry.tree.find((subentry) => subentry.tag === 'PLAC');
|
const place = entry.tree.find((subentry) => subentry.tag === 'PLAC');
|
||||||
if (place && place.data) {
|
if (place && place.data) {
|
||||||
@@ -57,7 +69,7 @@ function eventDetails(entry: GedcomEntry, tag: string) {
|
|||||||
<span>
|
<span>
|
||||||
{lines.map((line) => (
|
{lines.map((line) => (
|
||||||
<>
|
<>
|
||||||
{line}
|
<Linkify properties={{target: '_blank'}}>{line}</Linkify>
|
||||||
<br />
|
<br />
|
||||||
</>
|
</>
|
||||||
))}
|
))}
|
||||||
@@ -85,7 +97,7 @@ function dataDetails(entry: GedcomEntry, tag: string) {
|
|||||||
<span>
|
<span>
|
||||||
{lines.map((line) => (
|
{lines.map((line) => (
|
||||||
<>
|
<>
|
||||||
{line}
|
<Linkify properties={{target: '_blank'}}>{line}</Linkify>
|
||||||
<br />
|
<br />
|
||||||
</>
|
</>
|
||||||
))}
|
))}
|
||||||
@@ -125,13 +137,20 @@ function getDetails(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Details extends React.Component<Props, {}> {
|
export class Details extends React.Component<Props, {}> {
|
||||||
|
/** Make intl appear in this.context. */
|
||||||
|
static contextTypes = {
|
||||||
|
intl: intlShape,
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const entries = this.props.gedcom.indis[this.props.indi].tree;
|
const entries = this.props.gedcom.indis[this.props.indi].tree;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ui segments" id="details">
|
<div className="ui segments" id="details">
|
||||||
{getDetails(entries, NAME_TAGS, nameDetails)}
|
{getDetails(entries, NAME_TAGS, nameDetails)}
|
||||||
{getDetails(entries, EVENT_TAGS, eventDetails)}
|
{getDetails(entries, EVENT_TAGS, (entry, tag) =>
|
||||||
|
eventDetails(entry, tag, this.context.intl.locale),
|
||||||
|
)}
|
||||||
{getDetails(entries, DATA_TAGS, dataDetails)}
|
{getDetails(entries, DATA_TAGS, dataDetails)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
3
src/react-linkify.d.ts
vendored
Normal file
3
src/react-linkify.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
declare module 'react-linkify' {
|
||||||
|
export default class Linkify extends React.Component<any, any> {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user