Ignore:
Timestamp:
2020-03-10T22:43:23+01:00 (4 years ago)
Author:
Don-vip
Message:

see #18856 - override numbering format as follows:

  • Eastern Arabic(-Indic) numerals if Arabic language is used in Bahrain, Qatar, Kuwait, Oman, Lebanon, United Arab Emirates, Jordan, Syria, Yemen, Saudi Arabia, Iraq, Egypt
  • Khmer numerals if Khmer language is used in Cambodge
Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r16049 r16109  
    2323import java.util.zip.ZipEntry;
    2424import java.util.zip.ZipFile;
     25
     26import org.openstreetmap.josm.data.osm.TagMap;
    2527
    2628/**
     
    341343    }
    342344
     345    /**
     346     * Espaces the special i18n characters <code>'{}</code> with quotes.
     347     * @param msg unescaped string
     348     * @return escaped string
     349     * @since 4477
     350     */
    343351    public static String escape(String msg) {
    344352        if (msg == null) return null;
     
    626634    }
    627635
     636    /**
     637     * Updates the default locale : overrides the numbering system, if defined in internal boudnaries.xml for the current language/country.
     638     * @since 16109
     639     */
     640    public static void initializeNumberingFormat() {
     641        Locale l = Locale.getDefault();
     642        TagMap tags = Territories.getCustomTags(l.getCountry());
     643        if (tags != null) {
     644            String numberingSystem = tags.get("ldml:nu:" + l.getLanguage());
     645            if (numberingSystem != null && !numberingSystem.equals(l.getExtension(Locale.UNICODE_LOCALE_EXTENSION))) {
     646                Locale.setDefault(new Locale.Builder()
     647                        .setLanguage(l.getLanguage())
     648                        .setRegion(l.getCountry())
     649                        .setVariant(l.getVariant())
     650                        .setExtension(Locale.UNICODE_LOCALE_EXTENSION, numberingSystem)
     651                        .build());
     652            }
     653        }
     654    }
     655
    628656    private static int pluralEval(long n) {
    629657        switch(pluralMode) {
  • trunk/src/org/openstreetmap/josm/tools/Territories.java

    r15952 r16109  
    88import java.io.InputStream;
    99import java.util.ArrayList;
     10import java.util.Arrays;
    1011import java.util.Collection;
    1112import java.util.Collections;
     
    3334import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3435import org.openstreetmap.josm.data.osm.Relation;
     36import org.openstreetmap.josm.data.osm.TagMap;
    3537import org.openstreetmap.josm.data.osm.Way;
    3638import org.openstreetmap.josm.io.CachedFile;
     
    5860    private static volatile Map<String, TaginfoRegionalInstance> taginfoCache;
    5961    private static volatile Map<String, TaginfoRegionalInstance> taginfoGeofabrikCache;
     62    private static volatile Map<String, TagMap> customTagsCache;
     63
     64    private static final List<String> KNOWN_KEYS = Arrays.asList(ISO3166_1, ISO3166_2, TAGINFO, "type", "name:en", "driving_side", "note");
    6065
    6166    private Territories() {
     
    128133        iso3166Cache = new HashMap<>();
    129134        taginfoCache = new TreeMap<>();
     135        customTagsCache = new TreeMap<>();
    130136        try (CachedFile cf = new CachedFile("resource://data/" + FILENAME);
    131137                InputStream is = cf.getInputStream()) {
     
    137143                String iso2 = osm.get(ISO3166_2);
    138144                if (iso1 != null || iso2 != null) {
     145                    TagMap tags = osm.getKeys();
     146                    KNOWN_KEYS.forEach(tags::remove);
    139147                    GeoProperty<Boolean> gp;
    140148                    if (osm instanceof Way) {
     
    144152                    }
    145153                    GeoPropertyIndex<Boolean> gpi = new GeoPropertyIndex<>(gp, 24);
     154                    addInCache(iso1, gpi, tags);
     155                    addInCache(iso2, gpi, tags);
    146156                    if (iso1 != null) {
    147                         iso3166Cache.put(iso1, gpi);
    148157                        String taginfo = osm.get(TAGINFO);
    149158                        if (taginfo != null) {
     
    151160                        }
    152161                    }
    153                     if (iso2 != null) {
    154                         iso3166Cache.put(iso2, gpi);
    155                     }
    156162                }
    157163            }
    158164        } catch (IOException | IllegalDataException ex) {
    159165            throw new JosmRuntimeException(ex);
     166        }
     167    }
     168
     169    private static void addInCache(String code, GeoPropertyIndex<Boolean> gpi, TagMap tags) {
     170        if (code != null) {
     171            iso3166Cache.put(code, gpi);
     172            if (!tags.isEmpty()) {
     173                customTagsCache.put(code, tags);
     174            }
    160175        }
    161176    }
     
    216231                .collect(Collectors.toList());
    217232    }
     233
     234    /**
     235     * Returns the map of custom tags for a territory with the given ISO3166-1 or ISO3166-2 code.
     236     *
     237     * @param code the ISO3166-1 or ISO3166-2 code
     238     * @return the map of custom tags for a territory with the given ISO3166-1 or ISO3166-2 code, or {@code null}
     239     * @since 16109
     240     */
     241    public static TagMap getCustomTags(String code) {
     242        return code != null ? customTagsCache.get(code) : null;
     243    }
    218244}
Note: See TracChangeset for help on using the changeset viewer.