Changeset 14647 in josm


Ignore:
Timestamp:
2019-01-05T21:20:11+01:00 (11 days ago)
Author:
simon04
Message:

see #17173 - Use correct language prefixes for OSM wiki

Reference: https://wiki.openstreetmap.org/wiki/Template:Languages

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/HelpAction.java

    r14641 r14647  
    100100     */
    101101    public static void displayTagHelp(String key, String val) {
    102         final String lang = LanguageInfo.getWikiLanguagePrefix();
     102        final String lang = LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI);
    103103        final List<String> pages = Arrays.asList(
    104104                String.format("%sTag:%s=%s", lang, key, val),
     
    118118     */
    119119    public static void displayRelationHelp(IRelation<?> rel) {
    120         final String lang = LanguageInfo.getWikiLanguagePrefix();
     120        final String lang = LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI);
    121121        final List<String> pages = new ArrayList<>();
    122122        String type = rel.get("type");
     
    140140     */
    141141    public static void displayGenericHelp() {
    142         final String lang = LanguageInfo.getWikiLanguagePrefix();
     142        final String lang = LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI);
    143143        final List<String> pages = Arrays.asList(
    144144                String.format("%sMap_Features", lang),
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java

    r14646 r14647  
    77import java.util.Arrays;
    88import java.util.Collection;
     9import java.util.List;
    910import java.util.Optional;
    1011
     
    4344                    if (SwingUtilities.isLeftMouseButton(e)) {
    4445                        // Open localized page if exists
    45                         HelpAction.displayHelp(Arrays.asList(LanguageInfo.getWikiLanguagePrefix() + wiki, wiki));
     46                        final List<String> pages = Arrays.asList(
     47                                LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI) + wiki,
     48                                wiki);
     49                        HelpAction.displayHelp(pages);
    4650                    } else {
    4751                        super.mouseClicked(e);
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r14642 r14647  
    2727        BASELANGUAGE,
    2828        /** The standard english texts */
    29         ENGLISH
     29        ENGLISH,
     30        /** The locale prefix on the OSM wiki */
     31        OSM_WIKI,
    3032    }
    3133
     
    4547
    4648    static String getWikiLanguagePrefix(Locale locale, LocaleType type) {
    47         if (type == LocaleType.ENGLISH)
    48           return "";
     49        if (type == LocaleType.ENGLISH) {
     50            return "";
     51        } else if (type == LocaleType.OSM_WIKI && Locale.ENGLISH.getLanguage().equals(locale.getLanguage())) {
     52            return "";
     53        } else if (type == LocaleType.OSM_WIKI && Locale.SIMPLIFIED_CHINESE.equals(locale)) {
     54            return "Zh-hans:";
     55        } else if (type == LocaleType.OSM_WIKI && Locale.TRADITIONAL_CHINESE.equals(locale)) {
     56            return "Zh-hant:";
     57        } else if (type == LocaleType.OSM_WIKI) {
     58            return locale.getLanguage() + ':';
     59        }
    4960
    5061        String code = getJOSMLocaleCode(locale);
     
    6071            return null;
    6172        } else if (code.matches(".+@.+")) {
    62           return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1, 2)
    63           + '-' + code.substring(3, 4).toUpperCase(Locale.ENGLISH) + code.substring(4) + ':';
     73            return code.substring(0, 1).toUpperCase(Locale.ENGLISH)
     74                    + code.substring(1, 2)
     75                    + '-'
     76                    + code.substring(3, 4).toUpperCase(Locale.ENGLISH)
     77                    + code.substring(4)
     78                    + ':';
    6479        }
    6580        return code.substring(0, 1).toUpperCase(Locale.ENGLISH) + code.substring(1) + ':';
  • trunk/test/unit/org/openstreetmap/josm/tools/LanguageInfoTest.java

    r14642 r14647  
    33
    44import java.util.Arrays;
     5import java.util.List;
    56import java.util.Locale;
     7import java.util.stream.Collectors;
     8import java.util.stream.Stream;
    69
    710import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2326    public JOSMTestRules test = new JOSMTestRules().i18n("ca@valencia");
    2427
     28    private static final Locale EN_CA = Locale.CANADA;
    2529    private static final Locale DE_DE = Locale.GERMANY;
    2630    private static final Locale PT_BR = new Locale("pt", "BR");
    2731    private static final Locale CA_ES_VALENCIA = new Locale("ca", "ES", "valencia");
     32    private static final Locale ZN_CN = Locale.SIMPLIFIED_CHINESE;
     33    private static final Locale ZN_TW = Locale.TRADITIONAL_CHINESE;
    2834
    2935    /**
     
    3238    @Test
    3339    public void getWikiLanguagePrefix() {
    34         Assert.assertEquals("De:", LanguageInfo.getWikiLanguagePrefix(DE_DE, LanguageInfo.LocaleType.DEFAULT));
    35         Assert.assertEquals("Pt_BR:", LanguageInfo.getWikiLanguagePrefix(PT_BR, LanguageInfo.LocaleType.DEFAULT));
     40        testWikiLanguagePrefixes(LanguageInfo.LocaleType.DEFAULT,
     41                "En:", "De:", "Pt_BR:", "Ca-Valencia:", "Zh_CN:", "Zh_TW:");
     42        testWikiLanguagePrefixes(LanguageInfo.LocaleType.DEFAULTNOTENGLISH,
     43                null, "De:", "Pt_BR:", "Ca-Valencia:", "Zh_CN:", "Zh_TW:");
     44        testWikiLanguagePrefixes(LanguageInfo.LocaleType.BASELANGUAGE,
     45                null, null, "Pt:", null, "Zh:", "Zh:");
     46        testWikiLanguagePrefixes(LanguageInfo.LocaleType.ENGLISH,
     47                "", "", "", "", "", "");
     48        testWikiLanguagePrefixes(LanguageInfo.LocaleType.OSM_WIKI,
     49                "", "de:", "pt:", "ca:", "Zh-hans:", "Zh-hant:");
     50    }
     51
     52    private static void testWikiLanguagePrefixes(LanguageInfo.LocaleType type, String...expected) {
     53        final List<String> actual = Stream.of(EN_CA, DE_DE, PT_BR, CA_ES_VALENCIA, ZN_CN, ZN_TW)
     54                .map(locale -> LanguageInfo.getWikiLanguagePrefix(locale, type))
     55                .collect(Collectors.toList());
     56        Assert.assertEquals(Arrays.asList(expected), actual);
    3657    }
    3758
Note: See TracChangeset for help on using the changeset viewer.