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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.