Changeset 15711 in josm


Ignore:
Timestamp:
2020-01-14T21:55:56+01:00 (3 months ago)
Author:
simon04
Message:

see #14465 - Tag2Link: restrict names by JOSM language

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r15661 r15711  
    22package org.openstreetmap.josm.tools;
    33
    4 import java.util.LinkedList;
     4import java.util.ArrayList;
    55import java.util.List;
    66import java.util.Locale;
     
    288288     */
    289289    public static List<String> getLanguageCodes(Locale l) {
    290         List<String> list = new LinkedList<>();
     290        List<String> list = new ArrayList<>(4);
    291291        if (l == null)
    292292            l = Locale.getDefault();
  • trunk/src/org/openstreetmap/josm/tools/Tag2Link.java

    r15706 r15711  
    1212import java.util.regex.Matcher;
    1313import java.util.regex.Pattern;
     14import java.util.stream.Collectors;
    1415import java.util.stream.Stream;
    1516
     
    4243     * Maps OSM keys to formatter URLs from Wikidata and OSM Sophox where {@code "$1"} has to be replaced by a value.
    4344     */
    44     static MultiMap<String, String> wikidataRules = new MultiMap<>();
     45    static final MultiMap<String, String> wikidataRules = new MultiMap<>();
     46
     47    static final String languagePattern = LanguageInfo.getLanguageCodes(null).stream()
     48            .map(Pattern::quote)
     49            .collect(Collectors.joining("|"));
    4550
    4651    private Tag2Link() {
     
    127132
    128133        // Search
    129         if (key.matches("^(.+[:_])?name([:_].+)?$")) {
     134        if (key.matches("^(.+[:_])?name([:_]" + languagePattern + ")?$")) {
    130135            linkConsumer.acceptLink(tr("Search on DuckDuckGo"), "https://duckduckgo.com/?q=" + value);
    131136        }
Note: See TracChangeset for help on using the changeset viewer.