View | Details | Raw Unified | Return to bug 61050
Collapse All | Expand All

(-)src/core/org/apache/jmeter/util/JMeterUtils.java (-2 / +43 lines)
Lines 34-39 Link Here
34
import java.net.URL;
34
import java.net.URL;
35
import java.net.UnknownHostException;
35
import java.net.UnknownHostException;
36
import java.util.ArrayList;
36
import java.util.ArrayList;
37
import java.util.Arrays;
38
import java.util.Collections;
39
import java.util.Enumeration;
37
import java.util.LinkedHashMap;
40
import java.util.LinkedHashMap;
38
import java.util.List;
41
import java.util.List;
39
import java.util.Locale;
42
import java.util.Locale;
Lines 509-517 Link Here
509
        String resString = null;
512
        String resString = null;
510
        try {
513
        try {
511
            ResourceBundle bundle = resources;
514
            ResourceBundle bundle = resources;
512
            if(forcedLocale != null) {
515
            if (forcedLocale != null || bundle == null) {
513
                bundle = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", forcedLocale); // $NON-NLS-1$
516
                bundle = getBundle(forcedLocale);
514
            }
517
            }
518
            
515
            if (bundle.containsKey(resKey)) {
519
            if (bundle.containsKey(resKey)) {
516
                resString = bundle.getString(resKey);
520
                resString = bundle.getString(resKey);
517
            } else {
521
            } else {
Lines 532-537 Link Here
532
    }
536
    }
533
537
534
    /**
538
    /**
539
     * Try to get a {@link ResourceBundle} for the given {@code forcedLocale}.
540
     * If none is found try to fallback to the bundle for the set {@link Locale}
541
     * 
542
     * @param forcedLocale the {@link Locale} which should be used first
543
     * @return the resolved {@link ResourceBundle} or {@code null}, if none could be found
544
     */
545
    private static ResourceBundle getBundle(Locale forcedLocale) {
546
        for (Locale locale: Arrays.asList(forcedLocale, getLocale())) {
547
            if(locale != null) {
548
                ResourceBundle bundle = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", locale); // $NON-NLS-1$
549
                if (bundle == null) {
550
                    log.warn("Could not resolve ResourceBundle for Locale [{}]", locale);
551
                } else {
552
                    return bundle;
553
                }
554
            }
555
        }
556
        return new DummyResourceBundle();
557
    }
558
559
    /**
560
     * Simple {@link ResourceBundle}, that handles questions for every key, by giving the key back as an answer.
561
     */
562
    private static class DummyResourceBundle extends ResourceBundle {
563
564
        @Override
565
        protected Object handleGetObject(String key) {
566
            return "[" + key + "]";
567
        }
568
569
        @Override
570
        public Enumeration<String> getKeys() {
571
            return Collections.emptyEnumeration();
572
        }
573
    };
574
575
    /**
535
     * To get I18N label from properties file
576
     * To get I18N label from properties file
536
     * 
577
     * 
537
     * @param key
578
     * @param key

Return to bug 61050