mirror of
https://github.com/maputnik/editor.git
synced 2026-08-29 16:37:25 +00:00
58edd262b0
This is a rough start on adding react-i18next. I'll be working on adding more translatable strings and translations in the coming days. I'm going to need to wrap class components in HOCs, so let me know if there's something I should be fixing before doing that. I'm thinking now to keep the exported class names exactly the same, and rename the existing classes by prefixing an `I` (for internal). For example: ``` export default class AppToolbar ... ``` becomes ``` class IAppToolbar ... const AppToolbar = withTranslation()(IAppToolbar); export default AppToolbar; ``` I'll be able to contribute Japanese strings (I've talked to a couple people on my team and they'll be happy to help as well), so that's the language I decided to go with in this PR. Closes #746 --------- Co-authored-by: Ko Nagase <nagase@georepublic.co.jp> Co-authored-by: Harel M <harel.mazor@gmail.com>
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import React from 'react'
|
|
import {formatLayerId} from '../libs/format';
|
|
import {LayerSpecification, StyleSpecification} from 'maplibre-gl';
|
|
import { Trans, WithTranslation, withTranslation } from 'react-i18next';
|
|
|
|
type AppMessagePanelInternalProps = {
|
|
errors?: unknown[]
|
|
infos?: string[]
|
|
mapStyle?: StyleSpecification
|
|
onLayerSelect?(...args: unknown[]): unknown
|
|
currentLayer?: LayerSpecification
|
|
selectedLayerIndex?: number
|
|
} & WithTranslation;
|
|
|
|
class AppMessagePanelInternal extends React.Component<AppMessagePanelInternalProps> {
|
|
static defaultProps = {
|
|
onLayerSelect: () => {},
|
|
}
|
|
|
|
render() {
|
|
const {t, selectedLayerIndex} = this.props;
|
|
const errors = this.props.errors?.map((error: any, idx) => {
|
|
let content;
|
|
if (error.parsed && error.parsed.type === "layer") {
|
|
const {parsed} = error;
|
|
const layerId = this.props.mapStyle?.layers[parsed.data.index].id;
|
|
content = (
|
|
<>
|
|
<Trans t={t}>
|
|
Layer <span>{formatLayerId(layerId)}</span>: {parsed.data.message}
|
|
</Trans>
|
|
{selectedLayerIndex !== parsed.data.index &&
|
|
<>
|
|
—
|
|
<button
|
|
className="maputnik-message-panel__switch-button"
|
|
onClick={() => this.props.onLayerSelect!(parsed.data.index)}
|
|
>
|
|
{t("switch to layer")}
|
|
</button>
|
|
</>
|
|
}
|
|
</>
|
|
);
|
|
}
|
|
else {
|
|
content = error.message;
|
|
}
|
|
return <p key={"error-"+idx} className="maputnik-message-panel-error">
|
|
{content}
|
|
</p>
|
|
})
|
|
|
|
const infos = this.props.infos?.map((m, i) => {
|
|
return <p key={"info-"+i}>{m}</p>
|
|
})
|
|
|
|
return <div className="maputnik-message-panel">
|
|
{errors}
|
|
{infos}
|
|
</div>
|
|
}
|
|
}
|
|
|
|
const AppMessagePanel = withTranslation()(AppMessagePanelInternal);
|
|
export default AppMessagePanel;
|