Skip to content

Commit

Permalink
Merge pull request #5213 from HSLdevcom/NaviFixes4
Browse files Browse the repository at this point in the history
Fix navigator translations and scheduled departure info
  • Loading branch information
partisaani authored Dec 27, 2024
2 parents e607e53 + 1f7cdd1 commit 85b1615
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 38 deletions.
7 changes: 6 additions & 1 deletion app/component/itinerary/Itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,12 @@ const Itinerary = (
firstDeparture = compressedLegs.find(isTransitLeg);
if (firstDeparture) {
let firstDepartureStopType;
if (firstDeparture.mode === 'RAIL' || firstDeparture.mode === 'SUBWAY') {
if (firstDeparture.mode === 'FERRY') {
firstDepartureStopType = 'from-ferrypier';
} else if (
firstDeparture.mode === 'RAIL' ||
firstDeparture.mode === 'SUBWAY'
) {
firstDepartureStopType = 'from-station';
} else {
firstDepartureStopType = 'from-stop';
Expand Down
29 changes: 18 additions & 11 deletions app/component/itinerary/navigator/NaviInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { displayDistance } from '../../../util/geo-utils';
import { legShape, configShape } from '../../../util/shapes';
import { legDestination, legTimeStr, legTime } from '../../../util/legUtils';
import RouteNumber from '../../RouteNumber';
import { LEGTYPE, getLocalizedMode, getRemainingTraversal } from './NaviUtils';
import {
LEGTYPE,
getLocalizedMode,
getToLocalizedMode,
getRemainingTraversal,
} from './NaviUtils';
import { durationToString } from '../../../util/timeUtils';
import { getRouteMode } from '../../../util/modeUtils';

Expand Down Expand Up @@ -45,7 +50,6 @@ export default function NaviInstructions(
if (legType === LEGTYPE.WAIT && nextLeg.mode !== 'WALK') {
const { mode, headsign, route, start } = nextLeg;
const hs = headsign || nextLeg.trip?.tripHeadsign;
const localizedMode = getLocalizedMode(mode, intl);

const remainingDuration = Math.max(
Math.ceil((legTime(start) - time) / 60000),
Expand All @@ -66,9 +70,9 @@ export default function NaviInstructions(
<>
<div className="destination-header">
<FormattedMessage
id="navigation-wait-mode"
values={{ mode: localizedMode }}
defaultMessage="Wait for {mode}"
id="navigation-get-mode"
values={{ mode: getToLocalizedMode(mode, intl) }}
defaultMessage="Get on the {mode}"
/>
</div>
<div className="wait-leg">
Expand Down Expand Up @@ -96,12 +100,15 @@ export default function NaviInstructions(

if (legType === LEGTYPE.TRANSIT) {
const rt = leg.realtimeState === 'UPDATED';

const t = legTime(leg.end);
const stopOrStation = leg.to.stop.parentStation
? intl.formatMessage({ id: 'navileg-from-station' })
: intl.formatMessage({ id: 'navileg-from-stop' });
const localizedMode = getLocalizedMode(leg.mode, intl);

const destId = // eslint-disable-next-line no-nested-ternary
leg.mode === 'FERRY'
? 'navileg-at-ferrypier'
: leg.to.stop.parentStation
? 'navileg-at-station'
: 'navileg-at-stop';
const stopOrStation = intl.formatMessage({ id: destId });

const remainingDuration = Math.max(Math.ceil((t - time) / 60000), 0); // ms to minutes, >= 0
const values = {
Expand All @@ -117,7 +124,7 @@ export default function NaviInstructions(
<FormattedMessage
id={instructions}
defaultMessage="{mode}trip"
values={{ mode: localizedMode }}
values={{ mode: getLocalizedMode(leg.mode, intl) }}
/>
</div>
<div className="vehicle-leg">
Expand Down
26 changes: 21 additions & 5 deletions app/component/itinerary/navigator/NaviUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,21 @@ function findTransferProblems(legs, time, position, origin) {
}
return problems;
}

export const getLocalizedMode = (mode, intl) => {
return intl.formatMessage({
id: `${mode.toLowerCase()}`,
defaultMessage: `${mode}`,
});
};

export const getToLocalizedMode = (mode, intl) => {
return intl.formatMessage({
id: `to-${mode.toLowerCase()}`,
defaultMessage: `${mode}`,
});
};

export function getFirstLastLegs(legs) {
const first = legs[0];
const last = legs[legs.length - 1];
Expand Down Expand Up @@ -272,9 +281,10 @@ export const getTransitLegState = (leg, intl, messages, time) => {
1000 * (departure.serviceDay + departure.scheduledDeparture);
if (time - departed < DISPLAY_MESSAGE_THRESHOLD) {
// vehicle just departed, maybe no realtime yet
return [];
severity = 'INFO';
} else {
severity = 'WARNING';
}
severity = 'WARNING';
content = (
<div className="navi-info-content">
<FormattedMessage id="navileg-mode-schedule" />
Expand All @@ -290,9 +300,15 @@ export const getTransitLegState = (leg, intl, messages, time) => {
);
} else {
const { parentStation, name } = from.stop;
const stopOrStation = parentStation
? intl.formatMessage({ id: 'from-station' })
: intl.formatMessage({ id: 'from-stop' });

const fromId = // eslint-disable-next-line no-nested-ternary
mode === 'FERRY'
? 'from-ferrypier'
: parentStation
? 'from-station'
: 'from-stop';
const stopOrStation = intl.formatMessage({ id: fromId });

content = (
<div className="navi-info-content">
<FormattedMessage
Expand Down
48 changes: 27 additions & 21 deletions app/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ const translations = {
ferry: 'Fähre',
'ferry-with-route-number': 'Fähre {routeNumber} {headSign}',
'fetch-new-route': 'Neue Verbindung anfragen',
'from-station': 'von Bahnhof',
'from-stop': 'von Halt',
'from-station': 'Bahnhof',
'from-stop': 'Halt',
frontpage: 'Startseite',
'generic-error': 'Ein Fehler ist aufgetreten',
'geolocate-yourself': 'Lokalisieren',
Expand Down Expand Up @@ -450,7 +450,7 @@ const translations = {
'itinerary-summary-row.first-departure':
'{vehicle} fährt um {departureTime} von {stopName}.',
'itinerary-summary-row.first-leg-start-time':
'Fährt ab um {firstDepartureTime} {firstDepartureStopType} {firstDepartureStop}',
'Fährt ab um {firstDepartureTime} von {firstDepartureStopType} {firstDepartureStop}',
'itinerary-summary-row.first-leg-start-time-citybike':
'Abfahrt um {firstDepartureTime} von {firstDepartureStop} Leihrad-Station',
'itinerary-summary-row.no-transit-legs': 'Start jederzeit möglich',
Expand Down Expand Up @@ -1087,10 +1087,11 @@ const translations = {
'free-of-charge': 'Free',
'from-bus': 'bus',
'from-ferry': 'ferry',
'from-ferrypier': 'ferry pier',
'from-rail': 'train',
'from-scooter-location': 'the scooter location',
'from-station': 'from station',
'from-stop': 'from stop',
'from-station': 'station',
'from-stop': 'stop',
'from-subway': 'subway',
'from-tram': 'tram',
frontpage: 'Frontpage',
Expand Down Expand Up @@ -1188,7 +1189,7 @@ const translations = {
'itinerary-summary-row.first-departure':
'{vehicle} leaves at {departureTime} from stop {stopName}.',
'itinerary-summary-row.first-leg-start-time':
'Leaves at {firstDepartureTime} {firstDepartureStopType} {firstDepartureStop}{firstDeparturePlatform}',
'Leaves at {firstDepartureTime} from {firstDepartureStopType} {firstDepartureStop}{firstDeparturePlatform}',
'itinerary-summary-row.first-leg-start-time-citybike':
'Departure at {firstDepartureTime} from {firstDepartureStop} bike station',
'itinerary-summary-row.first-leg-start-time-scooter':
Expand Down Expand Up @@ -1304,6 +1305,7 @@ const translations = {
'navigation-abort-trip':
'TODO_Valitettavasti matkasi ei toteudu suunnitellusti.',
'navigation-description': 'Journey guidance',
'navigation-get-mode': 'Get on the {mode}',
'navigation-header': 'Journey tracking',
'navigation-intro-begin': 'TODO_navigation-intro-begin_EN',
'navigation-intro-header': 'TODO_navigation-intro-login-prompt_EN',
Expand All @@ -1326,12 +1328,12 @@ const translations = {
'navigation-ticket': 'Ticket',
'navigation-transfer-problem': 'TODO_Vaihto {route1} - {route2} ei onnistu',
'navigation-wait': 'Wait at the stop',
'navigation-wait-mode': 'Nouse {mode}',
'navileg-arrive-at': 'TODO_{duration} min päästä klo {legTime}',
'navileg-at-ferrypier': 'ferry pier',
'navileg-at-station': 'station',
'navileg-at-stop': 'stop',
'navileg-bicycle': 'Cycle to',
'navileg-car': 'Drive to',
'navileg-from-station': 'asemalla',
'navileg-from-stop': 'pysäkillä',
'navileg-in-transit': 'TODO_{mode}matka',
'navileg-leave-at':
'Jää pois {stopOrStation} {stop} {duration} min päästä klo {legTime}',
Expand Down Expand Up @@ -1700,7 +1702,7 @@ const translations = {
'to-ferry': 'ferry',
'to-frontpage': 'To the front page',
'to-rail': 'train',
'to-speedtram': 'TODO_pikaraitiovaunuun',
'to-speedtram': 'light rail',
'to-subway': 'subway',
'to-tram': 'tram',
today: 'Today',
Expand Down Expand Up @@ -2369,6 +2371,7 @@ const translations = {
'free-of-charge': 'Maksuton',
'from-bus': 'bussista',
'from-ferry': 'lautasta',
'from-ferrypier': 'lauttalaiturilta',
'from-rail': 'junasta',
'from-scooter-location': 'potkulaudan sijainti',
'from-station': 'asemalta',
Expand Down Expand Up @@ -2579,6 +2582,7 @@ const translations = {
'navigation-abort-trip':
'Valitettavasti matkasi ei toteudu suunnitellusti.',
'navigation-description': 'Löydä perille ohjatusti',
'navigation-get-mode': 'Nouse {mode}',
'navigation-header': 'Matkan seuranta',
'navigation-intro-begin': 'Aloita matka',
'navigation-intro-header': 'Mitä matkanseuranta tarjoaa?',
Expand All @@ -2601,12 +2605,12 @@ const translations = {
'navigation-ticket': 'Lippu',
'navigation-transfer-problem': 'Vaihto {route1} - {route2} ei onnistu',
'navigation-wait': 'Odota pysäkillä',
'navigation-wait-mode': 'Nouse {mode}',
'navileg-arrive-at': '{duration} min päästä klo {legTime}',
'navileg-at-ferrypier': 'lauttalaiturilla',
'navileg-at-station': 'asemalla',
'navileg-at-stop': 'pysäkillä',
'navileg-bicycle': 'Pyöräile',
'navileg-car': 'Aja',
'navileg-from-station': 'asemalla',
'navileg-from-stop': 'pysäkillä',
'navileg-in-transit': '{mode}matka',
'navileg-leave-at':
'Jää pois {stopOrStation} {stop} {duration} min päästä klo {legTime}',
Expand Down Expand Up @@ -2974,7 +2978,7 @@ const translations = {
'to-ferry': 'lauttaan',
'to-frontpage': 'Etusivulle',
'to-rail': 'junaan',
'to-speedtram': 'TODO_pikaraitiovaunuun',
'to-speedtram': 'pikaraitiovaunuun',
'to-subway': 'metroon',
'to-tram': 'raitiovaunuun',
today: 'Tänään',
Expand Down Expand Up @@ -5292,10 +5296,11 @@ const translations = {
'free-of-charge': 'Kostnadsfri',
'from-bus': 'bussen',
'from-ferry': 'färjan',
'from-ferrypier': 'färjerkajen',
'from-rail': 'tåget',
'from-scooter-location': 'platsen för sparkcykel',
'from-station': 'från stationen',
'from-stop': 'från hållplats',
'from-station': 'stationen',
'from-stop': 'hållplats',
'from-subway': 'metron',
'from-tram': 'spårvagnen',
frontpage: 'Framsidan',
Expand Down Expand Up @@ -5391,7 +5396,7 @@ const translations = {
'itinerary-summary-row.first-departure':
'{vehicle} avgår från station {stopName} klockan {departureTime}.',
'itinerary-summary-row.first-leg-start-time':
'Avgår kl {firstDepartureTime} {firstDepartureStopType} {firstDepartureStop}{firstDeparturePlatform}',
'Avgår kl {firstDepartureTime} från {firstDepartureStopType} {firstDepartureStop}{firstDeparturePlatform}',
'itinerary-summary-row.first-leg-start-time-citybike':
'Avgång kl {firstDepartureTime} från {firstDepartureStop} stadscykelstation',
'itinerary-summary-row.first-leg-start-time-scooter':
Expand Down Expand Up @@ -5506,6 +5511,7 @@ const translations = {
'navigation-abort-trip':
'TODO_Valitettavasti matkasi ei toteudu suunnitellusti.',
'navigation-description': 'Hitta fram med vägledning.',
'navigation-get-mode': 'Gå på {mode}',
'navigation-header': 'Följa',
'navigation-intro-begin': 'TODO_navigation-intro-begin_SV',
'navigation-intro-header': 'TODO_navigation-intro-login-prompt_SV',
Expand All @@ -5528,12 +5534,12 @@ const translations = {
'navigation-ticket': 'Biljett',
'navigation-transfer-problem': 'TODO_Vaihto {route1} - {route2} ei onnistu',
'navigation-wait': 'Vänta på hållplatsen',
'navigation-wait-mode': 'Odota {mode}',
'navileg-arrive-at': 'TODO_{duration} min päästä klo {legTime}',
'navileg-at-ferrypier': 'färjekajen',
'navileg-at-station': 'station',
'navileg-at-stop': 'hållplats',
'navileg-bicycle': 'Cycla till',
'navileg-car': 'Kör till',
'navileg-from-station': 'TODO_asemalla',
'navileg-from-stop': 'TODO_pysäkillä',
'navileg-in-transit': 'TODO_{mode}matka',
'navileg-leave-at':
'TODO_Jää pois {stopOrStation} {stop} {duration} min päästä klo {legTime}',
Expand Down Expand Up @@ -5904,7 +5910,7 @@ const translations = {
'to-ferry': 'färjan',
'to-frontpage': 'Till startsidan',
'to-rail': 'tåget',
'to-speedtram': 'TODO_pikaraitiovaunuun',
'to-speedtram': 'snabbspårvagnen',
'to-subway': 'metron',
'to-tram': 'spårvagnen',
today: 'I dag',
Expand Down

0 comments on commit 85b1615

Please sign in to comment.