本文整理了Java中java.util.ResourceBundle.getBundle
方法的一些代码示例,展示了ResourceBundle.getBundle
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResourceBundle.getBundle
方法的具体详情如下:
包路径:java.util.ResourceBundle
类名称:ResourceBundle
方法名:getBundle
[英]Finds the named resource bundle for the default Locale and the caller's ClassLoader.
[中]查找默认语言环境和调用方的类加载器的命名资源包。
代码示例来源:origin: jenkinsci/jenkins
/**
* Gets a human readable message for the given Win32 error code.
*
* @return
* null if no such message is available.
*/
@CheckForNull
public static String getWin32ErrorMessage(int n) {
try {
ResourceBundle rb = ResourceBundle.getBundle("/hudson/win32errors");
return rb.getString("error"+n);
} catch (MissingResourceException e) {
LOGGER.log(Level.WARNING,"Failed to find resource bundle",e);
return null;
}
}
代码示例来源:origin: wildfly/wildfly
private static ResourceBundle getResourceBundle(Locale locale) {
if (locale == null) {
locale = Locale.getDefault();
}
return ResourceBundle.getBundle(RESOURCE_NAME, locale);
}
}
代码示例来源:origin: javax.xml.bind/jaxb-api
/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
return MessageFormat.format(text,args);
}
代码示例来源:origin: xalan/xalan
throws MissingResourceException
Locale locale = Locale.getDefault();
return (ListResourceBundle)ResourceBundle.getBundle(className, locale);
return (ListResourceBundle)ResourceBundle.getBundle(
className, new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles." + className, className, "");
代码示例来源:origin: javax.el/javax.el-api
locale = Locale.getDefault();
if (null == (rb = (ResourceBundle)
threadMap.get(locale.toString()))) {
rb = ResourceBundle.getBundle("javax.el.PrivateMessages",
locale);
threadMap.put(locale.toString(), rb);
result = rb.getString(messageId);
if (null != params) {
result = MessageFormat.format(result, params);
代码示例来源:origin: RipMeApp/ripme
/**
* Gets the ResourceBundle AKA language package.
* Used for choosing the language of the UI.
*
* @return Returns the default resource bundle using the language specified in the config file.
*/
public static ResourceBundle getResourceBundle(String langSelect) {
if (langSelect == null) {
if (!getConfigString("lang", "").equals("")) {
String[] langCode = getConfigString("lang", "").split("_");
LOGGER.info("Setting locale to " + getConfigString("lang", ""));
return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
}
} else {
String[] langCode = langSelect.split("_");
LOGGER.info("Setting locale to " + langSelect);
return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control());
}
try {
LOGGER.info("Setting locale to default");
return ResourceBundle.getBundle("LabelsBundle", Locale.getDefault(), new UTF8Control());
} catch (MissingResourceException e) {
LOGGER.info("Setting locale to root");
return ResourceBundle.getBundle("LabelsBundle", Locale.ROOT);
}
}
代码示例来源:origin: remkop/picocli
@Test
public void testSetResourceBundle_overwritesSubcommandBundle() {
Locale original = Locale.getDefault();
Locale.setDefault(Locale.ENGLISH);
try {
assertArgsHaveBundle(orig, help.getCommandSpec().positionalParameters());
ResourceBundle update = ResourceBundle.getBundle("picocli.I18nSuperclass_Messages");
assertNotSame(update, orig);
assertNotEquals(orig.getString("usage.header"), update.getString("usage.header"));
代码示例来源:origin: plutext/docx4j
/**
* Method init
*
* @param languageCode
* @param countryCode
*/
public static synchronized void init(String languageCode, String countryCode) {
if (alreadyInitialized) {
return;
}
I18n.resourceBundle =
ResourceBundle.getBundle(
Constants.exceptionMessagesResourceBundleBase,
new Locale(languageCode, countryCode)
);
alreadyInitialized = true;
}
代码示例来源:origin: robovm/robovm
if (cl != null) {
try {
return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
} catch (MissingResourceException ignored) {
if (cl != null) {
try {
return ResourceBundle.getBundle(resourceBundleName, Locale.getDefault(), cl);
} catch (MissingResourceException ignored) {
throw new MissingResourceException("Failed to load the specified resource bundle \"" +
resourceBundleName + "\"", resourceBundleName, null);
代码示例来源:origin: PebbleTemplates/pebble
@Override
public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context,
int lineNumber) {
String basename = (String) args.get("bundle");
String key = (String) args.get("key");
Object params = args.get("params");
Locale locale = context.getLocale();
ResourceBundle bundle = ResourceBundle.getBundle(basename, locale, new UTF8Control());
Object phraseObject = bundle.getObject(key);
if (params != null) {
if (params instanceof List) {
List<?> list = (List<?>) params;
return MessageFormat.format(phraseObject.toString(), list.toArray());
} else {
return MessageFormat.format(phraseObject.toString(), params);
}
}
return phraseObject;
}
代码示例来源:origin: robovm/robovm
return (XResourceBundle) ResourceBundle.getBundle(resourceName, locale);
return (XResourceBundle) ResourceBundle.getBundle(
XSLT_RESOURCE, new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles.", className, "");
代码示例来源:origin: pentaho/pentaho-kettle
/**
* Returns a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class. Falls-back
* on the ROOT {@link Locale}, if the {@code fallbackOnRoot} flag is true and the requested Locale is not available.
*
* @param locale the {@link Locale} for which the {@link ResourceBundle} is being requested
* @param packagePath
* @param resourceClass
* @param fallbackOnRoot if true, and a {@link ResourceBundle} cannot be found for the requested {@link Locale}, falls
* back on the ROOT {@link Locale}
* @return a {@link ResourceBundle} corresponding to the given {@link Locale} package and resource class
*/
public static ResourceBundle getBundle( final Locale locale, final String packagePath, final Class<?> resourceClass,
final boolean fallbackOnRoot ) {
final GlobalMessageControl control = new GlobalMessageControl( fallbackOnRoot );
final String resourceName = control.toResourceName( control.toBundleName( packagePath, locale ), "properties" );
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle( packagePath, locale, resourceClass.getClassLoader(),
new GlobalMessageControl( fallbackOnRoot ) );
} catch ( final MissingResourceException e ) {
final StringBuilder msg = new StringBuilder();
msg.append( "Unable to find properties file '" ).append( resourceName ).append( "': " ).append( e.toString() );
throw new MissingResourceException( msg.toString(), resourceClass.getName(), packagePath );
}
return bundle;
}
代码示例来源:origin: javax.xml.bind/jaxb-api
/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
return MessageFormat.format(text,args);
}
代码示例来源:origin: robovm/robovm
Locale locale = Locale.getDefault();
String suffix = getResourceSuffix(locale);
return (XPATHErrorResources) ResourceBundle.getBundle(className
+ suffix, locale);
return (XPATHErrorResources) ResourceBundle.getBundle(className,
new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles.", className, "");
代码示例来源:origin: checkstyle/checkstyle
/**
* Gets the check message 'as is' from appropriate 'messages.properties'
* file.
*
* @param messageBundle the bundle name.
* @param messageKey the key of message in 'messages.properties' file.
* @param arguments the arguments of message in 'messages.properties' file.
* @return The message of the check with the arguments applied.
*/
private static String internalGetCheckMessage(
String messageBundle, String messageKey, Object... arguments) {
final ResourceBundle resourceBundle = ResourceBundle.getBundle(
messageBundle,
Locale.getDefault(),
Thread.currentThread().getContextClassLoader(),
new LocalizedMessage.Utf8Control());
final String pattern = resourceBundle.getString(messageKey);
final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
return formatter.format(arguments);
}
代码示例来源:origin: javamelody/javamelody
String getRequestByName(String requestName) {
return ResourceBundle.getBundle(RESOURCE_BUNDLE_BASE_NAME).getString(requestName);
}
代码示例来源:origin: org.postgresql/postgresql
private GT() {
try {
//JCP! if mvn.project.property.postgresql.jdbc.spec < "JDBC4.1"
//JCP> _bundle = ResourceBundle.getBundle("org.postgresql.translation.messages");
//JCP! else
_bundle = ResourceBundle.getBundle("org.postgresql.translation.messages", Locale.getDefault(Locale.Category.DISPLAY));
//JCP! endif
} catch (MissingResourceException mre) {
// translation files have not been installed
_bundle = null;
}
}
代码示例来源:origin: languagetool-org/languagetool
/**
* Gets the resource bundle for the specified language.
* @param languageCode lowercase two-letter ISO-639 code.
* @return the resource bundle for the specified language.
*/
public static ResourceBundle getMessages(String languageCode) {
if (languageCode.length() > 3) {
throw new RuntimeException("Use a character code (ISO-639 code), not a full language name: " + languageCode);
}
ResourceBundle messages = ResourceBundle.getBundle(
JLanguageTool.MESSAGE_BUNDLE, new Locale(languageCode));
return messages;
}
代码示例来源:origin: javax.xml.bind/jaxb-api
/** Loads a string resource and formats it with specified arguments. */
static String format( String property, Object[] args ) {
String text = ResourceBundle.getBundle(Messages.class.getName()).getString(property);
return MessageFormat.format(text,args);
}
代码示例来源:origin: robovm/robovm
Locale locale = Locale.getDefault();
String suffix = getResourceSuffix(locale);
return (XSLTErrorResources) ResourceBundle.getBundle(className
+ suffix, locale);
return (XSLTErrorResources) ResourceBundle.getBundle(className,
new Locale("en", "US"));
throw new MissingResourceException(
"Could not load any resource bundles.", className, "");
内容来源于网络,如有侵权,请联系作者删除!