Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add “Maximum Speed” to analysis sidebar #830

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions js/control/TrackAnalysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,19 @@ BR.TrackAnalysis = L.Class.extend({
case 'surface':
case 'smoothness':
if (typeof analysis[tagName][wayTagParts[1]] === 'undefined') {
let formattedName = i18next.t([
'sidebar.analysis.data.' + tagName + '.' + wayTagParts[1],
wayTagParts[1],
]);
let formattedName;

if (tagName.indexOf('maxspeed') === 0) {
formattedName += ' km/h';
formattedName = i18next.t('sidebar.analysis.data.maxspeed', {
maxspeed: wayTagParts[1],
Copy link
Collaborator

@bagage bagage Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could totally remove the if specific to maxSpeed, and instead have a fallback mecanism:

  1. try to use the full key sidebar.analysis.data.highway.footway
  2. if not available, try sidebar.analysis.data.highway
  3. otherwise simply fallback to untranslated highway type eg footway here

It should cover all cases while being agnostic of the kind of analysis (if there are more analysis coming in the future 😏)

const highwayType = wayTagParts[1];
formattedName = i18next.t(
    [
         'sidebar.analysis.data.' + tagName + '.' + highwayType,
         'sidebar.analysis.data.' + tagName,
          highwayType
    ], 
    {highwayType: highwayType}
);

If a translation key needs the highwayType it can use it, otherwise it can just skip it and it should work just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spotted some more possibilities to simplify the translations for the analysis sidebar, but I'd rather create a separate PR as there're changes on places unrelated to this PR.

Can you agree with this?

});
} else {
formattedName = i18next.t([
'sidebar.analysis.data.' + tagName + '.' + wayTagParts[1],
wayTagParts[1],
]);
}

analysis[tagName][wayTagParts[1]] = {
formatted_name: formattedName,
name: wayTagParts[1],
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@
"horrible": "Horrible",
"very_horrible": "Very Horrible",
"impassable": "Impassable"
}
},
"maxspeed": "{{maxspeed}} km/h"
},
"header": {
"highway": "Highway",
Expand Down
Loading