当前位置: 首页>>代码示例>>Java>>正文


Java MessageFormat.setLocale方法代码示例

本文整理汇总了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);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:LocalizedMessage.java

示例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();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:StringManager.java

示例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();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:StringManager.java

示例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();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:18,代码来源:StringManager.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:StringManager.java

示例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();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:18,代码来源:StringManager.java

示例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();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:23,代码来源:StringManager.java


注:本文中的java.text.MessageFormat.setLocale方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。