本文整理汇总了Java中java.text.MessageFormat.setLocale方法的典型用法代码示例。如果您正苦于以下问题:Java MessageFormat.setLocale方法的具体用法?Java MessageFormat.setLocale怎么用?Java MessageFormat.setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.MessageFormat
的用法示例。
在下文中一共展示了MessageFormat.setLocale方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatWithTimeZone
import java.text.MessageFormat; //导入方法依赖的package包/类
protected String formatWithTimeZone(
String template,
Object[] arguments,
Locale locale,
TimeZone timezone)
{
MessageFormat mf = new MessageFormat(" ");
mf.setLocale(locale);
mf.applyPattern(template);
if (!timezone.equals(TimeZone.getDefault()))
{
Format[] formats = mf.getFormats();
for (int i = 0; i < formats.length; i++)
{
if (formats[i] instanceof DateFormat)
{
DateFormat temp = (DateFormat) formats[i];
temp.setTimeZone(timezone);
mf.setFormat(i,temp);
}
}
}
return mf.format(arguments);
}
示例2: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format
* it with the given set of arguments.
*
* @param key
* @param args
*/
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
value = key;
}
MessageFormat mf = new MessageFormat(value);
mf.setLocale(locale);
return mf.format(args, new StringBuffer(), null).toString();
}
示例3: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format
* it with the given set of arguments.
*
* @param key The key for the required message
* @param args The values to insert into the message
*
* @return The request string formatted with the provided arguments or the
* key if the key was not found.
*/
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
value = key;
}
MessageFormat mf = new MessageFormat(value);
mf.setLocale(locale);
return mf.format(args, new StringBuffer(), null).toString();
}
示例4: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format
* it with the given set of arguments.
*
* @param key
* @param args
*/
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
value = key;
}
MessageFormat mf = new MessageFormat(value);
mf.setLocale(this.locale);
return mf.format(args, new StringBuffer(), null).toString();
}
示例5: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format
* it with the given set of arguments.
*
* @param key
* @param args
*/
public String getString(String key, Object[] args) {
String iString = null;
String value = getString(key);
// this check for the runtime exception is some pre 1.1.6
// VM's don't do an automatic toString() on the passed in
// objects and barf out
try {
// ensure the arguments are not null so pre 1.2 VM's don't barf
if(args==null){
args = new Object[1];
}
Object[] nonNullArgs = args;
for (int i=0; i<args.length; i++) {
if (args[i] == null) {
if (nonNullArgs==args){
nonNullArgs=(Object[])args.clone();
}
nonNullArgs[i] = "null";
}
}
if( value==null ) value=key;
MessageFormat mf = new MessageFormat(value);
mf.setLocale(locale);
iString = mf.format(nonNullArgs, new StringBuffer(), null).toString();
} catch (IllegalArgumentException iae) {
StringBuffer buf = new StringBuffer();
buf.append(value);
for (int i = 0; i < args.length; i++) {
buf.append(" arg[" + i + "]=" + args[i]);
}
iString = buf.toString();
}
return iString;
}
示例6: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format it with the
* given set of arguments.
*
* @param key
* @param args
*/
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
value = key;
}
MessageFormat mf = new MessageFormat(value);
mf.setLocale(locale);
return mf.format(args, new StringBuffer(), null).toString();
}
示例7: getString
import java.text.MessageFormat; //导入方法依赖的package包/类
/**
* Get a string from the underlying resource bundle and format it with the
* given set of arguments.
*
* @param key
* The key for the required message
* @param args
* The values to insert into the message
*
* @return The request string formatted with the provided arguments or the
* key if the key was not found.
*/
public String getString(final String key, final Object... args) {
String value = getString(key);
if (value == null) {
value = key;
}
MessageFormat mf = new MessageFormat(value);
mf.setLocale(locale);
return mf.format(args, new StringBuffer(), null).toString();
}