Changeset 12892 in josm for trunk/src/gnu/getopt/Getopt.java


Ignore:
Timestamp:
2017-09-24T09:25:26+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - remove dependency of getopt library on JOSM classes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gnu/getopt/Getopt.java

    r10209 r12892  
    2121package gnu.getopt;
    2222
    23 import static org.openstreetmap.josm.tools.I18n.tr;
    24 
    2523import java.text.MessageFormat;
    2624import java.util.HashMap;
    2725import java.util.Map;
     26import java.util.function.Function;
    2827
    2928/**************************************************************************/
     
    582581/**************************************************************************/
    583582
     583private static Function<String, String> tr = Function.identity();
     584
     585/**
     586 * Set the global translation handler for Getopt.
     587 *
     588 * This needs to be done before any call to {@link Getopt} or {@link LongOpt}
     589 * constructor.
     590 * @param tr function that takes messages in English and returns the localized message
     591 */
     592public static void setI18nHandler(Function<String, String> tr) {
     593    Getopt.tr = tr;
     594}
     595
    584596static class OptI18n {
     597
     598    private final Map<String, String> trns = new HashMap<>();
     599
    585600    public  OptI18n() {
    586601        add("getopt.ambigious", tr("{0}: option ''{1}'' is ambiguous"));
     
    596611    }
    597612
    598     Map<String, String> trns = new HashMap<String, String>();
     613    private String tr(String s) {
     614        return Getopt.tr.apply(s);
     615    }
    599616
    600617    private void add(String key, String value) {
Note: See TracChangeset for help on using the changeset viewer.