Changeset 16660 in josm


Ignore:
Timestamp:
2020-06-16T20:21:16+02:00 (7 weeks ago)
Author:
simon04
Message:

fix #19397 - JosmDecimalFormatSymbolsProvider is not used for locale en_IE or de_AT

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LanguagePreference.java

    r16438 r16660  
    66import java.awt.Component;
    77import java.util.ArrayList;
    8 import java.util.Arrays;
    98import java.util.Comparator;
    109import java.util.List;
     
    8584        LanguageComboBoxModel() {
    8685            data.add(0, null);
    87             List<Locale> locales = Arrays.asList(I18n.getAvailableTranslations());
    88             locales.sort(Comparator.comparing(Locale::getDisplayLanguage));
    89             data.addAll(locales);
     86            I18n.getAvailableTranslations()
     87                    .sorted(Comparator.comparing(Locale::getDisplayLanguage))
     88                    .forEachOrdered(data::add);
    9089        }
    9190
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r16470 r16660  
    1212import java.nio.file.InvalidPathException;
    1313import java.text.MessageFormat;
    14 import java.util.ArrayList;
    15 import java.util.Arrays;
    16 import java.util.Collection;
    17 import java.util.Comparator;
    1814import java.util.HashMap;
    1915import java.util.Locale;
     
    2117import java.util.regex.Matcher;
    2218import java.util.regex.Pattern;
     19import java.util.stream.Stream;
    2320import java.util.zip.ZipEntry;
    2421import java.util.zip.ZipFile;
     
    362359     * @return an array of locale objects.
    363360     */
    364     public static Locale[] getAvailableTranslations() {
    365         Collection<Locale> v = new ArrayList<>(languages.size());
    366         if (getTranslationFile("en") != null) {
    367             for (String loc : languages.keySet()) {
    368                 if (getTranslationFile(loc) != null) {
    369                     v.add(LanguageInfo.getLocale(loc));
    370                 }
    371             }
    372         }
    373         v.add(Locale.ENGLISH);
    374         Locale[] l = new Locale[v.size()];
    375         l = v.toArray(l);
    376         Arrays.sort(l, Comparator.comparing(Locale::toString));
    377         return l;
     361    public static Stream<Locale> getAvailableTranslations() {
     362        Stream<String> languages = Stream.concat(
     363                getTranslationFile("en") != null ? I18n.languages.keySet().stream() : Stream.empty(),
     364                Stream.of("en"));
     365        return languages.filter(loc -> getTranslationFile(loc) != null).map(LanguageInfo::getLocale);
    378366    }
    379367
  • trunk/src/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProvider.java

    r13124 r16660  
    55import java.text.spi.DecimalFormatSymbolsProvider;
    66import java.util.Locale;
     7import java.util.function.Function;
     8import java.util.stream.Stream;
    79
    810/**
     
    2628    @Override
    2729    public Locale[] getAvailableLocales() {
    28         return I18n.getAvailableTranslations();
     30        return Stream.of(
     31                Stream.of(Locale.ROOT),
     32                Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")),
     33                Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, "")),
     34                I18n.getAvailableTranslations()
     35        ).flatMap(Function.identity()).toArray(Locale[]::new);
    2936    }
    3037
  • trunk/test/unit/org/openstreetmap/josm/tools/JosmDecimalFormatSymbolsProviderTest.java

    r13124 r16660  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
    56
     7import java.text.DecimalFormat;
    68import java.util.Locale;
     9import java.util.stream.Stream;
    710
    811import org.junit.Rule;
     
    2427    public JOSMTestRules test = new JOSMTestRules();
    2528
     29    @Test
     30    public void testGroupingSeparator() {
     31        checkGroupingSymbol(Locale.ROOT);
     32        assertTrue(I18n.getAvailableTranslations().count() > 10);
     33        I18n.getAvailableTranslations().forEach(this::checkGroupingSymbol);
     34        Stream.of("", "AU", "IE", "US", "UK").map(country -> new Locale("en", country, "")).forEach(this::checkGroupingSymbol);
     35        Stream.of("", "AT", "CH", "DE").map(country -> new Locale("de", country, "")).forEach(this::checkGroupingSymbol);
     36    }
     37
     38    private void checkGroupingSymbol(Locale locale) {
     39        assertEquals(locale.toString(), "123\u202F456", DecimalFormat.getInstance(locale).format(123_456));
     40    }
     41
    2642    /**
    2743     * Test {@link JosmDecimalFormatSymbolsProvider#parseDouble}.
Note: See TracChangeset for help on using the changeset viewer.