Changeset 19045 in josm


Ignore:
Timestamp:
2024-04-19T11:48:22+02:00 (3 weeks ago)
Author:
stoecker
Message:

support language keys not following the naming of languages in JOSM, allow more than one language specific code, see #23627

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LabelCompositionStrategy.java

    r17466 r19045  
    145145         * The list of default name tags from which a label candidate is derived.
    146146         */
    147         private static final String[] DEFAULT_NAME_TAGS = {
    148             "name:" + LanguageInfo.getJOSMLocaleCode(),
    149             "name",
    150             "int_name",
    151             "distance",
    152             "railway:position",
    153             "ref",
    154             "operator",
    155             "brand",
    156             "addr:unit",
    157             "addr:flats",
    158             "addr:housenumber"
    159         };
     147        private static final String[] DEFAULT_NAME_TAGS = getDefaultNameTags();
    160148
    161149        /**
     
    175163            Config.getPref().addPreferenceChangeListener(this);
    176164            initNameTagsFromPreferences();
     165        }
     166
     167        /* Is joining an array really that complicated in Java? */
     168        private static String[] getDefaultNameTags() {
     169            ArrayList<String> tags = new ArrayList<String>(Arrays.asList(LanguageInfo.getOSMLocaleCodes("name:")));
     170            tags.addAll(Arrays.asList(new String[]{
     171                "name",
     172                "int_name",
     173                "distance",
     174                "railway:position",
     175                "ref",
     176                "operator",
     177                "brand",
     178                "addr:unit",
     179                "addr:flats",
     180                "addr:housenumber"
     181            }));
     182            return tags.toArray(String[]::new);
    177183        }
    178184
  • trunk/src/org/openstreetmap/josm/tools/LanguageInfo.java

    r18211 r19045  
    155155
    156156    /**
     157     * Replies the OSM locale codes for the default locale.
     158     *
     159     * @return the OSM locale codes for the default locale
     160     * @see #getOSMLocaleCode(String, Locale)
     161     * @since 19045
     162     */
     163    public static String[] getOSMLocaleCodes(String prefix) {
     164        return getOSMLocaleCodes(prefix, Locale.getDefault());
     165    }
     166
     167    /**
     168     * Replies the locale codes used by OSM for a given locale.
     169     *
     170     * In most cases OSM uses the 2-character ISO 639 language code ({@link Locale#getLanguage()}
     171     * to identify the locale of a localized resource, but in some cases it may use the
     172     * programmatic name for locales, as replied by {@link Locale#toString()}.
     173     *
     174     * For unknown country codes and variants this function already does fallback to
     175     * internally known translations.
     176     *
     177     * @param prefix a prefix like {@code name:}.
     178     * @param locale the locale. Replies "en" if null.
     179     * @return the OSM codes for the given locale
     180     * @since 19045
     181     */
     182    public static String[] getOSMLocaleCodes(String prefix, Locale locale) {
     183        if (prefix == null) {
     184            prefix = "";
     185        }
     186        String main = getJOSMLocaleCode(locale);
     187        switch (main) {
     188            case "zh_CN":
     189                return new String[]{prefix+"zh-Hans-CN", prefix+"zh-Hans", prefix+"zh"};
     190            case "zh_TW":
     191                return new String[]{prefix+"zh-Hant-TW", prefix+"zh-Hant", prefix+"zh"};
     192            default:
     193                return new String[]{prefix+main};
     194        }
     195    }
     196
     197    /**
    157198     * Replies the locale code used by Java for a given locale.
    158199     *
Note: See TracChangeset for help on using the changeset viewer.