Modify

Opened 11 years ago

Closed 11 years ago

#3261 closed enhancement (fixed)

[PATCH] Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists

Reported by: avarab@… Owned by: Gubaer
Priority: minor Milestone:
Component: Core Version: latest
Keywords: Cc:

Description

UI elements in JOSM such as the selection dialog will display the value of the "name" tag instead of just "node/way/relation" if it exists.

This feature should be expanded so that JOSM looks at "name:$CURRENT_LOCALE" first, then "name". So that someone using JOSM in e.g. German or Icelandic will get a localized interface when viewing objects with name:de or name:is tags.

Attachments (1)

locale-name.patch (2.6 KB) - added by plaicy 11 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 11 years ago by avarab@…

I note that it looks like mappaint already does this. But the rest of the UI doesn't.

Changed 11 years ago by plaicy

Attachment: locale-name.patch added

comment:2 in reply to:  1 Changed 11 years ago by plaicy

Priority: majorminor
Summary: Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists[PATCH] Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists

Replying to avar:

I note that it looks like mappaint already does this. But the rest of the UI doesn't.

I did not know that. I think this should always show the same name. Because I did not realize this fact I only write a patch for the selected name.

comment:3 Changed 11 years ago by Gubaer

This line

if (Main.pref.getBoolean("tags.name.uselocale", true)) { 

creates a dependency from the basic OSM data class OsmPrimitive to Main which, I think, we should avoid.

There is already the preference osm-primitives.showid which controls whether the display name of a primitive should include its id. The formatting code is in PrimitiveNameFormatter.java in order to avoid dependencies to Main.pref.

I see two alternatives:

  1. a new method getLocalizedName() on OsmPrimitive and derived classes. Depending on tags.name.uselocale getName() in PrimitiveNameFormatter whould then either invoke getName() or getLocalizedName()
  1. don't make localized names configurable at all. If the name of a primitive is always localized the dependency to Main.prefs is gone.

Actually, I'd prefer the following API on OSMPrimitive:

  • getName() - replies the content of the tag "name" if present; null, otherwise
  • getName(Locale locale) - replies the content of the "name:xx" tag matching locale, or getName() if no such tag exists
  • getDisplayName(INameFormatter formatter) - replies the display name of an OSM primititive formatted by a formatter. Is abstract on OsmPrimitive and dispatches to formatter on Node, Way and Relation.


where

  interface INameFormatter  {
      // implementations will encapsulate the "name formatting strategy",
      // including whether an id is to be displayed, whether  a localized
      // name is to be displayed, which other tags are to be used to build the tag, etc.
      //
      void String format(Node node);
      void String format(Way way)
      void String format(Relation relation)
 }

comment:4 in reply to:  3 ; Changed 11 years ago by plaicy

Replying to Gubaer:

creates a dependency from the basic OSM data class OsmPrimitive to Main which, I think, we should avoid.

Okay. But there is already a dependency to Main.pref for "tags.uninteresting" and "tags.direction".

[...]

  1. don't make localized names configurable at all. If the name of a primitive is always localized the dependency to Main.prefs is gone.

First I did not think about preference. Then I think different users may have different preferences in this topic. That's why I added the preference to code. One point against localize names: Names may different from rendered map.

[...]

  • getDisplayName(INameFormatter formatter) - replies the display name of an OSM primititive formatted by a formatter. Is abstract on OsmPrimitive and dispatches to formatter on Node, Way and Relation.


where

  interface INameFormatter  {

[...]

You have to add DataSet to INameFormatter (in may opinion the name should not include an "i" as all other interfaces). Then it is only different in return value to org.openstreetmap.josm.data.osm.visitor.Visitor.

comment:5 in reply to:  4 ; Changed 11 years ago by Gubaer

Replying to plaicy:

Replying to Gubaer:

creates a dependency from the basic OSM data class OsmPrimitive to Main which, I think, we should avoid.

Okay. But there is already a dependency to Main.pref for "tags.uninteresting" and "tags.direction".

Yes, I know - and I don't like them either. In the last couple of weeks/months we removed more and more dependencies to Main.xyz, for instance as result of the the work Jiri did on progress monitoring. I'd like to continue our work in this direction.

[...]

  1. don't make localized names configurable at all. If the name of a primitive is always localized the dependency to Main.prefs is gone.

First I did not think about preference. Then I think different users may have different preferences in this topic. That's why I added the preference to code. One point against localize names: Names may different from rendered map.

I support making localized names configurable, I'm only suggesting to do it outside of the base OsmPrimitive class.

You have to add DataSet to INameFormatter (in may opinion the name should not include an "i" as all other interfaces). Then it is only different in return value to org.openstreetmap.josm.data.osm.visitor.Visitor.

Agree. NameFormatter without an I is fine for me.

Why do you think DataSet should be added to NameFormatter? It is not required today in getName(). Furthermore, if the "strategy" in a particular NameFormatter would require access to a dataset you can always write one à la

   public class MyNameFormatterDependingOnDataSet implements NameFormatter {
      private DataSet ds; 
      public MyNameFormatterDependingOnDataSet(DataSet ds) {
         this.ds = ds; 
      }

      public String format(Node node) {
         // build the name depending on the current dataset 
      }
   }

Jiri is also working on keeping a reference from each primitive to "its" dataset in the future which will make access to a primitives "parent dataset" easier, too.

Then it is only different in return value to org.openstreetmap.josm.data.osm.visitor.Visitor.

Indeed, it follows the same visitor pattern but it was for the different return type that I didn't propose to either use Visitor or to have

   interface NameFormatter extends Visitor ....

comment:6 in reply to:  5 ; Changed 11 years ago by anonymous

You have to add DataSet to INameFormatter (in may opinion the name should not include an "i" as all other interfaces). Then it is only different in return value to org.openstreetmap.josm.data.osm.visitor.Visitor.

Agree. NameFormatter without an I is fine for me.

Why do you think DataSet should be added to NameFormatter? It is not required today in getName(). Furthermore, if the "strategy" in a particular NameFormatter would require access to a dataset you can always write one à la

I do not need it. But if you make getDisplayName(INameFormatter formatter) abstract in OsmPrimitive you have to overwrite it in org.openstreetmap.josm.data.osm.Changeset (sorry for that typo). If you simple ignore this call in Changeset write some documentation in INameFormatter (or which ever name). Would confuse the next person otherwise.

Choose a solution you like. This patch was only one possible way to add locale names.

comment:7 in reply to:  6 Changed 11 years ago by Gubaer

I do not need it. But if you make getDisplayName(INameFormatter formatter) abstract in OsmPrimitive you have to overwrite it in org.openstreetmap.josm.data.osm.Changeset (sorry for that typo).

Sure. That's what I recently did for getName(), too. And, of course, I forgot to add

   String format(Changeset changeset);

in the definition of NameFormatter above.

comment:8 Changed 11 years ago by Gubaer

Owner: changed from team to Gubaer

I'm going to take care of this but I wait until the next tested release is released. Changing this naming stuff will impact a couple of classes in the core, it might also have an impact on plugins.

comment:9 Changed 11 years ago by Gubaer

Resolution: fixed
Status: newclosed

(In [1990]) fixed #3261: Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists
new: new checkbox in LAF preferences for enabling/disabling localized names for primitives

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Gubaer.
as The resolution will be set.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.