Changeset 16109 in josm


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
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/resources/data/boundaries.osm

    r15819 r16109  
    2138821388    <nd ref='-7116' />
    2138921389    <tag k='ISO3166-1:alpha2' v='BH' />
     21390    <tag k='ldml:nu:ar' v='arab' />
    2139021391    <tag k='name:en' v='Bahrain' />
    2139121392  </way>
     
    2661726618    <nd ref='-9548' />
    2661826619    <tag k='ISO3166-1:alpha2' v='EG' />
     26620    <tag k='ldml:nu:ar' v='arab' />
    2661926621    <tag k='name:en' v='Egypt, Arab Rep.' />
    2662026622  </way>
     
    3019830200    <nd ref='-9490' />
    3019930201    <tag k='ISO3166-1:alpha2' v='IQ' />
     30202    <tag k='ldml:nu:ar' v='arab' />
    3020030203    <tag k='name:en' v='Iraq' />
    3020130204  </way>
     
    3044830451    <nd ref='-9584' />
    3044930452    <tag k='ISO3166-1:alpha2' v='JO' />
     30453    <tag k='ldml:nu:ar' v='arab' />
    3045030454    <tag k='name:en' v='Jordan' />
    3045130455  </way>
     
    3129931303    <nd ref='-9888' />
    3130031304    <tag k='ISO3166-1:alpha2' v='KH' />
     31305    <tag k='ldml:nu:km' v='khmr' />
    3130131306    <tag k='name:en' v='Cambodia' />
    3130231307  </way>
     
    3145831463    <nd ref='-9928' />
    3145931464    <tag k='ISO3166-1:alpha2' v='KW' />
     31465    <tag k='ldml:nu:ar' v='arab' />
    3146031466    <tag k='name:en' v='Kuwait' />
    3146131467  </way>
     
    3186431870    <nd ref='-11224' />
    3186531871    <tag k='ISO3166-1:alpha2' v='LB' />
     31872    <tag k='ldml:nu:ar' v='arab' />
    3186631873    <tag k='name:en' v='Lebanon' />
    3186731874  </way>
     
    3622136228    <nd ref='-11040' />
    3622236229    <tag k='ISO3166-1:alpha2' v='QA' />
     36230    <tag k='ldml:nu:ar' v='arab' />
    3622336231    <tag k='name:en' v='Qatar' />
    3622436232  </way>
     
    3668036688    <nd ref='-9512' />
    3668136689    <tag k='ISO3166-1:alpha2' v='SA' />
     36690    <tag k='ldml:nu:ar' v='arab' />
    3668236691    <tag k='name:en' v='Saudi Arabia' />
    3668336692  </way>
     
    3815738166    <nd ref='-11220' />
    3815838167    <tag k='ISO3166-1:alpha2' v='SY' />
     38168    <tag k='ldml:nu:ar' v='arab' />
    3815938169    <tag k='name:en' v='Syrian Arab Republic' />
    3816038170  </way>
     
    4130041310    <nd ref='-11556' />
    4130141311    <tag k='ISO3166-1:alpha2' v='YE' />
     41312    <tag k='ldml:nu:ar' v='arab' />
    4130241313    <tag k='name:en' v='Yemen, Rep.' />
    4130341314  </way>
     
    5829758308    <member type='way' ref='-28920' role='inner' />
    5829858309    <tag k='ISO3166-1:alpha2' v='AE' />
     58310    <tag k='ldml:nu:ar' v='arab' />
    5829958311    <tag k='name:en' v='United Arab Emirates' />
    5830058312    <tag k='type' v='multipolygon' />
     
    5850958521    <member type='way' ref='-29158' role='outer' />
    5851058522    <tag k='ISO3166-1:alpha2' v='OM' />
     58523    <tag k='ldml:nu:ar' v='arab' />
    5851158524    <tag k='name:en' v='Oman' />
    5851258525    <tag k='type' v='multipolygon' />
  • trunk/src/org/openstreetmap/josm/gui/MainInitialization.java

    r15855 r16109  
    2020import org.openstreetmap.josm.data.validation.OsmValidator;
    2121import org.openstreetmap.josm.gui.layer.ImageryLayer;
    22 import org.openstreetmap.josm.gui.layer.Layer;
    2322import org.openstreetmap.josm.gui.layer.TMSLayer;
    2423import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
     
    9897                        // Otherwise they would not have been able to load the layers in the first place because they would have been disabled
    9998                        if (MainApplication.isDisplayingMapView()) {
    100                             for (Layer l : MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class)) {
    101                                 if (((ImageryLayer) l).getInfo().isBlacklisted()) {
     99                            for (ImageryLayer l : MainApplication.getLayerManager().getLayersOfType(ImageryLayer.class)) {
     100                                if (l.getInfo().isBlacklisted()) {
    102101                                    Logging.info(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName()));
    103102                                    MainApplication.getLayerManager().removeLayer(l);
     
    116115                }),
    117116            new InitializationTask(tr("Initializing internal traffic data"), RightAndLefthandTraffic::initialize),
     117            new InitializationTask(tr("Initializing numbering format"), I18n::initializeNumberingFormat),
    118118            new InitializationTask(tr("Initializing validator"), OsmValidator::initialize),
    119119            new InitializationTask(tr("Initializing presets"), TaggingPresets::initialize),
  • 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}
  • trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java

    r16032 r16109  
    44import static java.util.Collections.singleton;
    55import static org.junit.Assert.assertEquals;
     6import static org.junit.Assert.assertNull;
    67import static org.junit.Assert.assertTrue;
    78
     
    9091        assertTrue(error, error.contains(": Invalid token=EOF at (line no=3,"));
    9192    }
     93
     94    /**
     95     * Unit test of {@link Territories#getCustomTags}
     96     */
     97    @Test
     98    public void testGetCustomTags() {
     99        assertNull(Territories.getCustomTags(null));
     100        assertNull(Territories.getCustomTags("foo"));
     101        assertEquals("arab", Territories.getCustomTags("BH").get("ldml:nu:ar"));
     102    }
    92103}
Note: See TracChangeset for help on using the changeset viewer.