Changeset 12931 in josm for trunk/src/org


Ignore:
Timestamp:
2017-10-07T13:31:45+02:00 (7 years ago)
Author:
Don-vip
Message:

see #14602 - Override digit group separator to be consistent across languages with ISO 80000-1 + checkstyle fixes

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r12927 r12931  
    225225    public void paintComponent(Graphics g) {
    226226        super.paintComponent(g);
    227         Graphics2D g2d = (Graphics2D)g;
     227        Graphics2D g2d = (Graphics2D) g;
    228228
    229229        // draw shaded area for non-downloaded region of current "edit layer", but only if there *is* a current "edit layer",
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java

    r12928 r12931  
    1818import javax.swing.JSeparator;
    1919
    20 import org.openstreetmap.josm.Main;
    2120import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    2221import org.openstreetmap.josm.gui.help.HelpUtil;
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/OAuthAuthenticationPreferencesPanel.java

    r12928 r12931  
    2323import javax.swing.JPanel;
    2424
    25 import org.openstreetmap.josm.Main;
    2625import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    2726import org.openstreetmap.josm.data.oauth.OAuthParameters;
  • trunk/src/org/openstreetmap/josm/io/OsmConnection.java

    r12928 r12931  
    1212import java.util.Objects;
    1313
    14 import org.openstreetmap.josm.Main;
    1514import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
    1615import org.openstreetmap.josm.data.oauth.OAuthParameters;
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r12644 r12931  
    9090    private static volatile Map<String, String[]> pstrings;
    9191    private static Map<String, PluralMode> languages = new HashMap<>();
    92 
    93     /**
    94      * Translates some text for the current locale.
    95      * These strings are collected by a script that runs on the source code files.
    96      * After translation, the localizations are distributed with the main program.
    97      * <br>
    98      * For example, <code>tr("JOSM''s default value is ''{0}''.", val)</code>.
    99      * <br>
    100      * Use {@link #trn} for distinguishing singular from plural text, i.e.,
    101      * do not use {@code tr(size == 1 ? "singular" : "plural")} nor
    102      * {@code size == 1 ? tr("singular") : tr("plural")}
    103      *
    104      * @param text the text to translate.
    105      * Must be a string literal. (No constants or local vars.)
    106      * Can be broken over multiple lines.
    107      * An apostrophe ' must be quoted by another apostrophe.
    108      * @param objects the parameters for the string.
    109      * Mark occurrences in {@code text} with <code>{0}</code>, <code>{1}</code>, ...
    110      * @return the translated string.
    111      * @see #trn
    112      * @see #trc
    113      * @see #trnc
    114      */
    115     public static String tr(String text, Object... objects) {
    116         if (text == null) return null;
    117         return MessageFormat.format(gettext(text, null), objects);
    118     }
    119 
    120     /**
    121      * Translates some text in a context for the current locale.
    122      * There can be different translations for the same text within different contexts.
    123      *
    124      * @param context string that helps translators to find an appropriate
    125      * translation for {@code text}.
    126      * @param text the text to translate.
    127      * @return the translated string.
    128      * @see #tr
    129      * @see #trn
    130      * @see #trnc
    131      */
    132     public static String trc(String context, String text) {
    133         if (context == null)
    134             return tr(text);
    135         if (text == null)
    136             return null;
    137         return MessageFormat.format(gettext(text, context), (Object) null);
    138     }
    139 
    140     public static String trcLazy(String context, String text) {
    141         if (context == null)
    142             return tr(text);
    143         if (text == null)
    144             return null;
    145         return MessageFormat.format(gettextLazy(text, context), (Object) null);
    146     }
    147 
    148     /**
    149      * Marks a string for translation (such that a script can harvest
    150      * the translatable strings from the source files).
    151      *
    152      * For example, <code>
    153      * String[] options = new String[] {marktr("up"), marktr("down")};
    154      * lbl.setText(tr(options[0]));</code>
    155      * @param text the string to be marked for translation.
    156      * @return {@code text} unmodified.
    157      */
    158     public static String marktr(String text) {
    159         return text;
    160     }
    161 
    162     public static String marktrc(String context, String text) {
    163         return text;
    164     }
    165 
    166     /**
    167      * Translates some text for the current locale and distinguishes between
    168      * {@code singularText} and {@code pluralText} depending on {@code n}.
    169      * <br>
    170      * For instance, {@code trn("There was an error!", "There were errors!", i)} or
    171      * <code>trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)</code>.
    172      *
    173      * @param singularText the singular text to translate.
    174      * Must be a string literal. (No constants or local vars.)
    175      * Can be broken over multiple lines.
    176      * An apostrophe ' must be quoted by another apostrophe.
    177      * @param pluralText the plural text to translate.
    178      * Must be a string literal. (No constants or local vars.)
    179      * Can be broken over multiple lines.
    180      * An apostrophe ' must be quoted by another apostrophe.
    181      * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
    182      * @param objects the parameters for the string.
    183      * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
    184      * @return the translated string.
    185      * @see #tr
    186      * @see #trc
    187      * @see #trnc
    188      */
    189     public static String trn(String singularText, String pluralText, long n, Object... objects) {
    190         return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
    191     }
    192 
    193     /**
    194      * Translates some text in a context for the current locale and distinguishes between
    195      * {@code singularText} and {@code pluralText} depending on {@code n}.
    196      * There can be different translations for the same text within different contexts.
    197      *
    198      * @param context string that helps translators to find an appropriate
    199      * translation for {@code text}.
    200      * @param singularText the singular text to translate.
    201      * Must be a string literal. (No constants or local vars.)
    202      * Can be broken over multiple lines.
    203      * An apostrophe ' must be quoted by another apostrophe.
    204      * @param pluralText the plural text to translate.
    205      * Must be a string literal. (No constants or local vars.)
    206      * Can be broken over multiple lines.
    207      * An apostrophe ' must be quoted by another apostrophe.
    208      * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
    209      * @param objects the parameters for the string.
    210      * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
    211      * @return the translated string.
    212      * @see #tr
    213      * @see #trc
    214      * @see #trn
    215      */
    216     public static String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
    217         return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
    218     }
    219 
    220     private static String gettext(String text, String ctx, boolean lazy) {
    221         int i;
    222         if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
    223             ctx = text.substring(2, i-1);
    224             text = text.substring(i+1);
    225         }
    226         if (strings != null) {
    227             String trans = strings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
    228             if (trans != null)
    229                 return trans;
    230         }
    231         if (pstrings != null) {
    232             i = pluralEval(1);
    233             String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
    234             if (trans != null && trans.length > i)
    235                 return trans[i];
    236         }
    237         return lazy ? gettext(text, null) : text;
    238     }
    239 
    240     private static String gettext(String text, String ctx) {
    241         return gettext(text, ctx, false);
    242     }
    243 
    244     /* try without context, when context try fails */
    245     private static String gettextLazy(String text, String ctx) {
    246         return gettext(text, ctx, true);
    247     }
    248 
    249     private static String gettextn(String text, String plural, String ctx, long num) {
    250         int i;
    251         if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
    252             ctx = text.substring(2, i-1);
    253             text = text.substring(i+1);
    254         }
    255         if (pstrings != null) {
    256             i = pluralEval(num);
    257             String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
    258             if (trans != null && trans.length > i)
    259                 return trans[i];
    260         }
    261 
    262         return num == 1 ? text : plural;
    263     }
    264 
    265     public static String escape(String msg) {
    266         if (msg == null) return null;
    267         return msg.replace("\'", "\'\'").replace("{", "\'{\'").replace("}", "\'}\'");
    268     }
    269 
    270     private static URL getTranslationFile(String lang) {
    271         return I18n.class.getResource("/data/"+lang.replace('@', '-')+".lang");
    272     }
    273 
    274     /**
    275      * Get a list of all available JOSM Translations.
    276      * @return an array of locale objects.
    277      */
    278     public static Locale[] getAvailableTranslations() {
    279         Collection<Locale> v = new ArrayList<>(languages.size());
    280         if (getTranslationFile("en") != null) {
    281             for (String loc : languages.keySet()) {
    282                 if (getTranslationFile(loc) != null) {
    283                     v.add(LanguageInfo.getLocale(loc));
    284                 }
    285             }
    286         }
    287         v.add(Locale.ENGLISH);
    288         Locale[] l = new Locale[v.size()];
    289         l = v.toArray(l);
    290         Arrays.sort(l, Comparator.comparing(Locale::toString));
    291         return l;
    292     }
    293 
    294     /**
    295      * Determines if a language exists for the given code.
    296      * @param code The language code
    297      * @return {@code true} if a language exists, {@code false} otherwise
    298      */
    299     public static boolean hasCode(String code) {
    300         return languages.containsKey(code);
    301     }
    302 
    303     /**
    304      * I18n initialization.
    305      */
    306     public static void init() {
    307         // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer.
    308         // http://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
    309         // FIXME: This can be removed after we switch to a minimal version of Java that enables CLDR by default
    310         // or includes all languages we need in the JRE. See http://openjdk.java.net/jeps/252 for Java 9
    311         System.setProperty("java.locale.providers", "JRE,CLDR"); // Don't call Utils.updateSystemProperty to avoid spurious log at startup
    312 
     92    static {
    31393        //languages.put("ar", PluralMode.MODE_AR);
    31494        languages.put("ast", PluralMode.MODE_NOTONE);
     
    353133        languages.put("zh_CN", PluralMode.MODE_NONE);
    354134        languages.put("zh_TW", PluralMode.MODE_NONE);
     135    }
     136
     137    /**
     138     * Translates some text for the current locale.
     139     * These strings are collected by a script that runs on the source code files.
     140     * After translation, the localizations are distributed with the main program.
     141     * <br>
     142     * For example, <code>tr("JOSM''s default value is ''{0}''.", val)</code>.
     143     * <br>
     144     * Use {@link #trn} for distinguishing singular from plural text, i.e.,
     145     * do not use {@code tr(size == 1 ? "singular" : "plural")} nor
     146     * {@code size == 1 ? tr("singular") : tr("plural")}
     147     *
     148     * @param text the text to translate.
     149     * Must be a string literal. (No constants or local vars.)
     150     * Can be broken over multiple lines.
     151     * An apostrophe ' must be quoted by another apostrophe.
     152     * @param objects the parameters for the string.
     153     * Mark occurrences in {@code text} with <code>{0}</code>, <code>{1}</code>, ...
     154     * @return the translated string.
     155     * @see #trn
     156     * @see #trc
     157     * @see #trnc
     158     */
     159    public static String tr(String text, Object... objects) {
     160        if (text == null) return null;
     161        return MessageFormat.format(gettext(text, null), objects);
     162    }
     163
     164    /**
     165     * Translates some text in a context for the current locale.
     166     * There can be different translations for the same text within different contexts.
     167     *
     168     * @param context string that helps translators to find an appropriate
     169     * translation for {@code text}.
     170     * @param text the text to translate.
     171     * @return the translated string.
     172     * @see #tr
     173     * @see #trn
     174     * @see #trnc
     175     */
     176    public static String trc(String context, String text) {
     177        if (context == null)
     178            return tr(text);
     179        if (text == null)
     180            return null;
     181        return MessageFormat.format(gettext(text, context), (Object) null);
     182    }
     183
     184    public static String trcLazy(String context, String text) {
     185        if (context == null)
     186            return tr(text);
     187        if (text == null)
     188            return null;
     189        return MessageFormat.format(gettextLazy(text, context), (Object) null);
     190    }
     191
     192    /**
     193     * Marks a string for translation (such that a script can harvest
     194     * the translatable strings from the source files).
     195     *
     196     * For example, <code>
     197     * String[] options = new String[] {marktr("up"), marktr("down")};
     198     * lbl.setText(tr(options[0]));</code>
     199     * @param text the string to be marked for translation.
     200     * @return {@code text} unmodified.
     201     */
     202    public static String marktr(String text) {
     203        return text;
     204    }
     205
     206    public static String marktrc(String context, String text) {
     207        return text;
     208    }
     209
     210    /**
     211     * Translates some text for the current locale and distinguishes between
     212     * {@code singularText} and {@code pluralText} depending on {@code n}.
     213     * <br>
     214     * For instance, {@code trn("There was an error!", "There were errors!", i)} or
     215     * <code>trn("Found {0} error in {1}!", "Found {0} errors in {1}!", i, Integer.toString(i), url)</code>.
     216     *
     217     * @param singularText the singular text to translate.
     218     * Must be a string literal. (No constants or local vars.)
     219     * Can be broken over multiple lines.
     220     * An apostrophe ' must be quoted by another apostrophe.
     221     * @param pluralText the plural text to translate.
     222     * Must be a string literal. (No constants or local vars.)
     223     * Can be broken over multiple lines.
     224     * An apostrophe ' must be quoted by another apostrophe.
     225     * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
     226     * @param objects the parameters for the string.
     227     * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
     228     * @return the translated string.
     229     * @see #tr
     230     * @see #trc
     231     * @see #trnc
     232     */
     233    public static String trn(String singularText, String pluralText, long n, Object... objects) {
     234        return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
     235    }
     236
     237    /**
     238     * Translates some text in a context for the current locale and distinguishes between
     239     * {@code singularText} and {@code pluralText} depending on {@code n}.
     240     * There can be different translations for the same text within different contexts.
     241     *
     242     * @param context string that helps translators to find an appropriate
     243     * translation for {@code text}.
     244     * @param singularText the singular text to translate.
     245     * Must be a string literal. (No constants or local vars.)
     246     * Can be broken over multiple lines.
     247     * An apostrophe ' must be quoted by another apostrophe.
     248     * @param pluralText the plural text to translate.
     249     * Must be a string literal. (No constants or local vars.)
     250     * Can be broken over multiple lines.
     251     * An apostrophe ' must be quoted by another apostrophe.
     252     * @param n a number to determine whether {@code singularText} or {@code pluralText} is used.
     253     * @param objects the parameters for the string.
     254     * Mark occurrences in {@code singularText} and {@code pluralText} with <code>{0}</code>, <code>{1}</code>, ...
     255     * @return the translated string.
     256     * @see #tr
     257     * @see #trc
     258     * @see #trn
     259     */
     260    public static String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
     261        return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
     262    }
     263
     264    private static String gettext(String text, String ctx, boolean lazy) {
     265        int i;
     266        if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
     267            ctx = text.substring(2, i-1);
     268            text = text.substring(i+1);
     269        }
     270        if (strings != null) {
     271            String trans = strings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
     272            if (trans != null)
     273                return trans;
     274        }
     275        if (pstrings != null) {
     276            i = pluralEval(1);
     277            String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
     278            if (trans != null && trans.length > i)
     279                return trans[i];
     280        }
     281        return lazy ? gettext(text, null) : text;
     282    }
     283
     284    private static String gettext(String text, String ctx) {
     285        return gettext(text, ctx, false);
     286    }
     287
     288    /* try without context, when context try fails */
     289    private static String gettextLazy(String text, String ctx) {
     290        return gettext(text, ctx, true);
     291    }
     292
     293    private static String gettextn(String text, String plural, String ctx, long num) {
     294        int i;
     295        if (ctx == null && text.startsWith("_:") && (i = text.indexOf('\n')) >= 0) {
     296            ctx = text.substring(2, i-1);
     297            text = text.substring(i+1);
     298        }
     299        if (pstrings != null) {
     300            i = pluralEval(num);
     301            String[] trans = pstrings.get(ctx == null ? text : "_:"+ctx+'\n'+text);
     302            if (trans != null && trans.length > i)
     303                return trans[i];
     304        }
     305
     306        return num == 1 ? text : plural;
     307    }
     308
     309    public static String escape(String msg) {
     310        if (msg == null) return null;
     311        return msg.replace("\'", "\'\'").replace("{", "\'{\'").replace("}", "\'}\'");
     312    }
     313
     314    private static URL getTranslationFile(String lang) {
     315        return I18n.class.getResource("/data/"+lang.replace('@', '-')+".lang");
     316    }
     317
     318    /**
     319     * Get a list of all available JOSM Translations.
     320     * @return an array of locale objects.
     321     */
     322    public static Locale[] getAvailableTranslations() {
     323        Collection<Locale> v = new ArrayList<>(languages.size());
     324        if (getTranslationFile("en") != null) {
     325            for (String loc : languages.keySet()) {
     326                if (getTranslationFile(loc) != null) {
     327                    v.add(LanguageInfo.getLocale(loc));
     328                }
     329            }
     330        }
     331        v.add(Locale.ENGLISH);
     332        Locale[] l = new Locale[v.size()];
     333        l = v.toArray(l);
     334        Arrays.sort(l, Comparator.comparing(Locale::toString));
     335        return l;
     336    }
     337
     338    /**
     339     * Determines if a language exists for the given code.
     340     * @param code The language code
     341     * @return {@code true} if a language exists, {@code false} otherwise
     342     */
     343    public static boolean hasCode(String code) {
     344        return languages.containsKey(code);
     345    }
     346
     347    static void setupJavaLocaleProviders() {
     348        // Look up SPI providers first (for JosmDecimalFormatSymbolsProvider).
     349        // Enable CLDR locale provider on Java 8 to get additional languages, such as Khmer.
     350        // http://docs.oracle.com/javase/8/docs/technotes/guides/intl/enhancements.8.html#cldr
     351        // FIXME: This must be updated after we switch to Java 9.
     352        // See https://docs.oracle.com/javase/9/docs/api/java/util/spi/LocaleServiceProvider.html
     353        System.setProperty("java.locale.providers", "SPI,JRE,CLDR"); // Don't call Utils.updateSystemProperty to avoid spurious log at startup
     354    }
     355
     356    /**
     357     * I18n initialization.
     358     */
     359    public static void init() {
     360        setupJavaLocaleProviders();
    355361
    356362        /* try initial language settings, may be changed later again */
  • trunk/src/org/openstreetmap/josm/tools/Logging.java

    r12798 r12931  
    5252
    5353    static {
     54        // We need to be sure java.locale.providers system property is initialized by JOSM, not by JRE
     55        // The call to ConsoleHandler constructor makes the JRE access this property by side effect
     56        I18n.setupJavaLocaleProviders();
     57
    5458        LOGGER.setLevel(Level.ALL);
    5559        LOGGER.setUseParentHandlers(false);
Note: See TracChangeset for help on using the changeset viewer.