Get a bundle JSON using the supplied Locale.
@param baseName The bundle base name.
@param locale The Locale.
@return The bundle JSON.
@throws MissingResourceException Missing resource bundle.
426228
public static @Nonnull JSONObject getBundle(@Nonnull String baseName, @Nonnull Locale locale) throws MissingResourceException {
        String bundleKey = baseName + ":" + locale.toString();
        JSONObject bundleJSON = bundles.get(bundleKey);

        if (bundleJSON != null) {
            return bundleJSON;
        }

        ResourceBundle bundle = getBundle(baseName, locale, Jenkins.class.getClassLoader());
        if (bundle == null) {
            // Not in Jenkins core. Check the plugins.
            Jenkins jenkins = Jenkins.getInstance(); // will never return null
            if (jenkins != null) {
                for (PluginWrapper plugin : jenkins.getPluginManager().getPlugins()) {
                    bundle = getBundle(baseName, locale, plugin.classLoader);
                    if (bundle != null) {
                        break;
                    }
                }
            }
        }
        if (bundle == null) {
            throw new MissingResourceException("Can't find bundle for base name "
                    + baseName + ", locale " + locale, baseName + "_" + locale, "");
        }

        bundleJSON = toJSONObject(bundle);
        bundles.put(bundleKey, bundleJSON);

        return bundleJSON;
    }
1340100
private static final void addLocaleIDsFromIndexBundle(String baseName,
            ClassLoader root, Set<String> locales) {
        ICUResourceBundle bundle;
        try {
            bundle = (ICUResourceBundle) UResourceBundle.instantiateBundle(baseName, ICU_RESOURCE_INDEX, root, true);
            bundle = (ICUResourceBundle) bundle.get(INSTALLED_LOCALES);
        } catch (MissingResourceException e) {
            if (DEBUG) {
                System.out.println("couldn't find " + baseName + '/' + ICU_RESOURCE_INDEX + ".res");
                Thread.dumpStack();
            }
            return;
        }
        UResourceBundleIterator iter = bundle.getIterator();
        iter.reset();
        while (iter.hasNext()) {
            String locstr = iter.next(). getKey();
            locales.add(locstr);
        }
    }
531579
@Override
    protected MessageFormat resolveCode(String code, Locale locale) {
        MessageFormat messageFormat = null;
        for (int i = 0; messageFormat == null && i < this.basenames.length; i++) {
            ResourceBundle bundle = getResourceBundle(this.basenames[i], locale);
            if (bundle != null) {
                messageFormat = getMessageFormat(bundle, code, locale);
            }
        }
        return messageFormat;
    }
1245720
public Properties getProperties(final Locale locale) {
        Resource url = this.baseResourcesResource;
        Properties properties = null;
        if(url != null) {
            StaticResourceLoader resourceLoader = new StaticResourceLoader();
            resourceLoader.setBaseResource(url);
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
            try {
                // first load all properties
                Resource[] resources = resolver.getResources('*' + PROPERTIES_EXTENSION);
                resources = resources.length > 0 ? filterResources(resources, locale) : resources;
                if(resources.length > 0) {
                    properties = new Properties();

                    // message bundles are locale specific. The more underscores the locale has the more specific the locale
                    // so we order by the number of underscores present so that the most specific appears
                    Arrays.sort(resources, (o1, o2) -> {
                        String f1 = o1.getFilename();
                        String f2 = o2.getFilename();

                        int firstUnderscoreCount = StringUtils.countOccurrencesOf(f1, "_");
                        int secondUnderscoreCount = StringUtils.countOccurrencesOf(f2, "_");

                        if(firstUnderscoreCount == secondUnderscoreCount) {
                            return 0;
                        }
                        else {
                            return firstUnderscoreCount > secondUnderscoreCount ?  1 : -1;
                        }
                    });

                    loadFromResources(properties, resources);
                }
            } catch (IOException e) {
                return null;
            }
        }
        return properties;
    }
579019
public EditableResourceBundle getResourceBundle(Locale locale) {
		EditableResourceBundle localeBundle = bundles.get(locale);
		if(localeBundle==null) {
			ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, locale);
			if(!resourceBundle.getLocale().equals(locale)) throw new AssertionError("ResourceBundle not for this locale: "+locale);
			if(!(resourceBundle instanceof EditableResourceBundle)) throw new AssertionError("ResourceBundle is not a EditableResourceBundle: "+resourceBundle);
			localeBundle = (EditableResourceBundle)resourceBundle;
			if(localeBundle.getBundleSet()!=this) throw new AssertionError("EditableResourceBundle not for this EditableResourceBundleSet: "+localeBundle);
			if(!localeBundle.getBundleLocale().equals(locale)) throw new AssertionError("EditableResourceBundle not for this locale: "+locale);
			// EditableResourceBundle will have added the bundle to the bundles map.
		}
		return localeBundle;
	}
21228
static ResourceBundle getMessageBundle(Language lang) {
    try {
      ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocaleWithCountryAndVariant());
      if (!isValidBundleFor(lang, bundle)) {
        bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, lang.getLocale());
        if (!isValidBundleFor(lang, bundle)) {
          // happens if 'xx' is requested but only a MessagesBundle_xx_YY.properties exists:
          Language defaultVariant = lang.getDefaultLanguageVariant();
          if (defaultVariant != null && defaultVariant.getCountries().length > 0) {
            Locale locale = new Locale(defaultVariant.getShortCode(), defaultVariant.getCountries()[0]);
            bundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, locale);
          }
        }
      }
      ResourceBundle fallbackBundle = ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
      return new ResourceBundleWithFallback(bundle, fallbackBundle);
    } catch (MissingResourceException e) {
      return ResourceBundle.getBundle(MESSAGE_BUNDLE, Locale.ENGLISH);
    }
  }
1211232
private static final String getNlsKey(String resourceBundle, Locale locale) {
        return new StringBuffer(resourceBundle).append("#").append(locale.toString()).toString();
    }
784668
public static LocalizationContext getLocalizationContext(PageContext pc, String basename) {

        LocalizationContext locCtxt = null;
        ResourceBundle bundle = null;

        if ((basename == null) || basename.equals("")) {
            return new LocalizationContext();
        }

        // Try preferred locales
        Locale pref = getLocale(pc, javax.servlet.jsp.jstl.core.Config.FMT_LOCALE);
        if (pref != null) {
            // Preferred locale is application-based
            bundle = findMatch(basename, pref);
            if (bundle != null) {
                locCtxt = new LocalizationContext(bundle, pref);
            }
        }

        if (locCtxt == null) {
            // No match found with preferred locales, try using fallback locale
            locCtxt = BundleSupport.getLocalizationContext(pc, basename);
        } else {
            // set response locale
            if (locCtxt.getLocale() != null) {
                setResponseLocale(pc, locCtxt.getLocale());
            }
        }

        return locCtxt;
    }
681919
public static final Object getObject(Locale locale, String key)
   {
      ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale);
      return (bundle.getObject(key));
   }
977216
public static String get(String bundleName, String key, Object[] args) {
        return get(bundleName, getLocale(), key, args);
    }
984536
public static ResourceBundle getResourceBundle(String bundleName, Locale locale)
    {
        return ResourceBundle.getBundle(bundleName, locale);
    }
282593
public static ResourceBundle getResourceBundle(String bundleName, Locale locale) {
        ResourceBundle bundle = null;

        boolean isDev = false;
        if (Ameba.getApp() != null) {
            isDev = Ameba.getApp().getMode().isDev();
            BUNDLE_CONTROL.noCache = isDev;
        }
        if (!isDev) {
            bundle = RESOURCE_BUNDLES.get(bundleName, locale);
        }
        if (bundle == null) {
            try {
                bundle = ResourceBundle.getBundle(
                        bundleName,
                        locale,
                        ClassUtils.getContextClassLoader(),
                        BUNDLE_CONTROL
                );
            } catch (MissingResourceException e) {
                // no op
            }
        }

        if (bundle != null && !isDev) {
            RESOURCE_BUNDLES.put(bundleName, locale, bundle);
        }

        return bundle;
    }
1106017
@Route(method = HttpMethod.GET, uri = "i18n/bundles/{file<.+>}.json")
    public Result getBundleResourceForI18Next(@QueryParameter("locales") String listOfLocales,
                                              @HttpParameter(HeaderNames.IF_NONE_MATCH) String ifNoneMatch) {
        // Parse the list of locale
        List<Locale> locales = new ArrayList<>();
        if (!Strings.isNullOrEmpty(listOfLocales)) {
            String[] items = listOfLocales.split(" ");
            for (String item : items) {
                // Manage the 'dev' value (it's the default locale used by i18next
                if ("dev".equalsIgnoreCase(item)) {
                    locales.add(InternationalizationService.DEFAULT_LOCALE);
                } else {
                    locales.add(Locale.forLanguageTag(item));
                }
            }
        }

        String etag;
        StringBuilder builder = new StringBuilder();
        for (Locale locale : locales) {
            builder.append(service.etag(locale));
        }
        etag = builder.toString();

        if (ifNoneMatch != null && ifNoneMatch.equals(etag)) {
            return new Result(Status.NOT_MODIFIED);
        }

        // i18next use a specific Json Format
        ObjectNode result = json.newObject();
        for (Locale locale : locales) {
            ObjectNode lang = json.newObject();
            ObjectNode translation = json.newObject();
            lang.set("translation", translation);
            Collection<ResourceBundle> bundles = service.bundles(locale);
            for (ResourceBundle bundle : bundles) {
                for (String key : bundle.keySet()) {
                    populateJsonResourceBundle(translation, key, bundle.getString(key));
                }
            }
            String langName = locale.toLanguageTag();
            if (locale.equals(InternationalizationService.DEFAULT_LOCALE)) {
                langName = "dev";
            }
            result.set(langName, lang);
        }
        return ok(result).with(HeaderNames.ETAG, etag);
    }
207784
@Override
	public Reader getResource(JoinableResourceBundle bundle, String resourceName) throws ResourceNotFoundException {

		return getResource(bundle, resourceName, false);
	}
272035
protected Option<TextBundle> loadJavaBundle(String bundleName, Locale locale) {
    Properties properties = new Properties();
    String resource = toJavaResourceName(bundleName, locale);
    try {
      InputStream is = ClassLoaders.getResourceAsStream(resource, getClass());
      if (null == is) return Option.none();
      properties.load(is);
      is.close();
    } catch (IOException e) {
      return Option.none();
    } finally {
    }
    return Option.<TextBundle> from(new DefaultTextBundle(locale, resource, properties));
  }
346046
public String getString(String key) throws MissingResourceException {
        // Error Checking Trace.  Ensure that we got a valid key
        if (key == null) {
            if (tc.isEventEnabled()) {

                // DGH20040823: Begin fix for defect 218797 - Source provided by Tom Musta
                // String msg = messages.getString("NLS.nullKey",
                //                                 "Null lookup key passed to NLS");
                String msg = getMessages().getString("NLS.nullKey",
                                                     "Null lookup key passed to NLS");
                // DGH20040823: End fix for defect 218797 - Source provided by Tom Musta
                Tr.warning(tc, msg);
            }
            return null;
        }
        // Error Checking Trace.  Ensure that we got a valid bundle.
        if (bundle == null) {
            if (tc.isEventEnabled()) {
                // DGH20040823: Begin fix for defect 218797 - Source provided by Tom Musta
                // String msg = messages.getString("NLS.noBundles",
                //                                 "Encountered an internal error. No valid bundles.");
                String msg = getMessages().getString("NLS.noBundles",
                                                     "Encountered an internal error. No valid bundles.");
                // DGH20040823: End fix for defect 218797 - Source provided by Tom Musta
                Tr.warning(tc, msg);
            }
            throw new MissingResourceException(bundleName, bundleName, key);
        }
        // Return Code.
        String rtn = null;
        // Get the resource (string).
        rtn = bundle.getString(key);
        return rtn;
    }
361822
public static JSONObject parseFromResourceBundle(ResourceBundle bundle) {
		JSONObject jsonObject = new JSONObject();
		Enumeration<String> keys = bundle.getKeys();
		while (keys.hasMoreElements()) {
			String key = keys.nextElement();
			if (key != null) {
				InternalJSONUtil.propertyPut(jsonObject, key, bundle.getString(key));
			}
		}
		return jsonObject;
	}