[openstreetmap/openstreetmap-website] Localize directions time and distance formatting (PR #7514)

Jac Chambers notifications at github.com
Tue Oct 20 22:10:50 UTC 2026


@JovialOptimist commented on this pull request.



>        if (minorValue < 200) return this.print(this.minorName, Math.round(minorValue / 10) * 10);
       if (minorValue < 1500 || majorValue < 0.25) return this.print(this.minorName, Math.round(minorValue / 100) * 100);
-      if (majorValue < 5) return this.print(this.majorName, majorValue.toFixed(1));
+      if (majorValue < 5) return this.print(this.majorName, majorValue, 1);

Okay I think I get you. I have a local uncommitted change that make print accept a new param called options, which can override the default maximumFractionDigits (0) and supply minimumFractionDigits as well as roundingIncrement, which would get rid of every `Math.round`.

```js

// new print signature
print(name, value, options = {}) {
  const scope = "javascripts.directions.distance_in_units";
  const distance = value.toLocaleString(OSM.i18n.locale, { maximumFractionDigits: 0, ...options });
  return OSM.i18n.t(name, { scope, distance });
}

// ...

stepDistance(m) {
  const minorValue = m / this.minorScale;
  const majorValue = m / this.majorScale;

  if (minorValue < 5) return "";
  if (minorValue < 200) return this.print(this.minorName, minorValue, { roundingIncrement: 10 });
  // ↓ uses roundingIncrement instead of Math.Round
  if (minorValue < 1500 || majorValue < 0.25) return this.print(this.minorName, minorValue, { roundingIncrement: 100 }); 
  if (majorValue < 5) return this.print(this.majorName, majorValue, { minimumFractionDigits: 1, maximumFractionDigits: 1 });
  return this.print(this.majorName, majorValue);
}
```

The only real downside I can see is that older browsers don't support `roundingIncrement`, so they'd see "186m" instead of "190m". I could add a fallback that would use Math.Round, unless that's overkill?

Also, side note on best practice since this is my first time contributing to open source - should I commit and push that fix so people can see it, or am I supposed to talk it out in the thread first?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/7514#discussion_r4330874133
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/7514/review/5592426527 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20261020/376f5ab4/attachment-0001.htm>


More information about the rails-dev mailing list