Changeset 15661 in josm for trunk


Ignore:
Timestamp:
2020-01-08T23:03:36+01:00 (5 years ago)
Author:
simon04
Message:

fix #18388 - SystemOfMeasurement: primarily obtain country from LC_MEASUREMENT

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/SystemOfMeasurement.java

    r15427 r15661  
    1616import org.openstreetmap.josm.data.preferences.StringProperty;
    1717import org.openstreetmap.josm.spi.preferences.Config;
     18import org.openstreetmap.josm.tools.LanguageInfo;
    1819
    1920/**
     
    289290     */
    290291    public static SystemOfMeasurement getDefault() {
    291         switch (Locale.getDefault().getCountry()) {
     292        final String country = Optional.ofNullable(System.getenv("LC_MEASUREMENT"))
     293                .map(LanguageInfo::getLocale)
     294                .orElse(Locale.getDefault())
     295                .getCountry();
     296        switch (country) {
    292297            case "US":
    293298                // https://en.wikipedia.org/wiki/Metrication_in_the_United_States#Current_use
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r15547 r15661  
    203203     * Replies the locale used by Java for a given language code.
    204204     *
    205      * Accepts JOSM and Java codes as input.
     205     * Accepts JOSM, Java and POSIX codes as input.
    206206     *
    207207     * @param localeName the locale code.
     
    211211     */
    212212    public static Locale getLocale(String localeName, boolean useDefaultCountry) {
     213        final int encoding = localeName.indexOf('.');
     214        if (encoding > 0) {
     215            localeName = localeName.substring(0, encoding);
     216        }
    213217        int country = localeName.indexOf('_');
    214218        int variant = localeName.indexOf('@');
  • trunk/test/unit/org/openstreetmap/josm/tools/LanguageInfoTest.java

    r14811 r15661  
    6363
    6464    /**
     65     * Unit test of {@link LanguageInfo#getLocale}.
     66     */
     67    @Test
     68    public void testGetLocale() {
     69        Assert.assertEquals(RU, LanguageInfo.getLocale("ru"));
     70        Assert.assertEquals(EN_GB, LanguageInfo.getLocale("en_GB"));
     71        Assert.assertEquals(CA_ES_VALENCIA, LanguageInfo.getLocale("ca_ES@valencia"));
     72        Assert.assertEquals(DE_DE, LanguageInfo.getLocale("de_DE"));
     73        Assert.assertEquals(DE_DE, LanguageInfo.getLocale("de_DE.UTF-8")); // LANG, LC_MEASUREMENT
     74        Assert.assertEquals(PT_BR, LanguageInfo.getLocale("pt_BR.UTF-8")); // LANG, LC_MEASUREMENT
     75    }
     76
     77    /**
    6578     * Unit test of {@link LanguageInfo#getJOSMLocaleCode}.
    6679     */
Note: See TracChangeset for help on using the changeset viewer.