首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何翻译“反应手册”的说明?

如何翻译“反应手册”的说明?
EN

Stack Overflow用户
提问于 2022-09-04 16:23:14
回答 1查看 57关注 0票数 0

我遇到了一个问题,说明翻译传单-路由机。我不能把它翻译成另一种语言(但单位指标改变了),我真的不明白,我在这里做错了什么。设置语言的唯一方法是为Routing.Control设置自定义格式化程序,但它不起作用。这是我的密码。我用的是react传单v.4

代码语言:javascript
复制
import { useEffect, useCallback, useRef, MutableRefObject } from 'react';

import L, { LatLng, Routing } from 'leaflet';
import iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png';
import iconUrl from 'leaflet/dist/images/marker-icon.png';
import shadowUrl from 'leaflet/dist/images/marker-shadow.png';
import * as ReactLeaflet from 'react-leaflet';

import 'leaflet/dist/leaflet.css';
import 'leaflet-routing-machine';
import 'leaflet-routing-machine/src/localization';
import 'lrm-graphhopper';

const { MapContainer } = ReactLeaflet;
const DEFAULT_CENTER = [50.093572, 118.036912];

function MyComponent({
  routingRef,
}: {
  routingRef: MutableRefObject<Routing.Control | null>;
}) {
  const map = ReactLeaflet.useMap();

  const markerRef = useRef<L.Marker | null>(null);

  ReactLeaflet.useMapEvents({
    click(e) {
      if (markerRef.current) {
        map.removeLayer(markerRef.current);
        routingRef.current?.getPlan().setWaypoints([]);
        markerRef.current = null;
      }

      markerRef.current = new L.Marker(e.latlng, {
        draggable: false,
        interactive: false,
      });
      if (markerRef.current) {
        map.removeLayer(markerRef.current);
        routingRef.current
          ?.getPlan()
          .setWaypoints([
            markerRef.current.getLatLng(),
            { lat: DEFAULT_CENTER[0], lng: DEFAULT_CENTER[1] } as LatLng,
          ]);
      }
    },
  });

  const control = useCallback(
    () =>
      L.Routing.control({
        showAlternatives: true,
        autoRoute: true,
        formatter: new Routing.Formatter({
          language: 'ru',
          distanceTemplate: '{value} {unit}',
        }),

        summaryTemplate:
          '<h2 >Дистанция: <span>{distance}</span></h2><h3> Время: {time}</h3>',
        routeLine: (route, opt) => {
          return new Routing.Line(route, {
            ...opt,
            styles: [{ color: 'green', opacity: 1, weight: 5 }],
          });
        },
        useZoomParameter: false,
        addWaypoints: false,
        router: (L.Routing as any).graphHopper(
          'api-key',
          {
            urlParameters: {
              vehicle: 'foot',
            },
          }
        ),
        show: true,
        routeWhileDragging: true,
        fitSelectedRoutes: false,
      }).addTo(map),
    [map]
  );

  useEffect(() => {
    (async function init() {
      L.Icon.Default.mergeOptions({
        iconRetinaUrl: iconRetinaUrl.src,
        iconUrl: iconUrl.src,
        shadowUrl: shadowUrl.src,
      });

      routingRef.current = control();
    })();
  }, [control, routingRef]);

  return null;
}

const Map = ({ children, className, ...rest }: any) => {
  const routingRef = useRef<Routing.Control | null>(null);

  return (
    <>
      <MapContainer
        center={DEFAULT_CENTER}
        zoom={16}
        {...rest}
        className="h-full"
      >
        <>
          <ReactLeaflet.TileLayer
            url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
            attribution="Барбершоп Bronson в Краснокаменске"
          />
          <ReactLeaflet.Marker
            position={DEFAULT_CENTER as L.LatLngExpression}
            // icon={new L.Icon({})}
          >
            <ReactLeaflet.Popup>
              A pretty CSS3 popup. <br /> Easily customizable.
            </ReactLeaflet.Popup>
          </ReactLeaflet.Marker>
          <MyComponent routingRef={routingRef} />
        </>
      </MapContainer>
    </>
  );
};

export default Map;

最后我收到了什么,部分翻译文本

请提供任何解决方案。希望你今天过得愉快!

EN

回答 1

Stack Overflow用户

发布于 2022-09-04 16:52:18

您可以使用_formatter.formatInstruction进行说明。

例如:

代码语言:javascript
复制
var text = router._formatter.formatInstruction(router._routes[0].instructions[0], 0);
var distance = router._formatter.formatDistance(router._routes[0].instructions[0].distance);

为了同样的问题

希望它能帮到你。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73600996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档