當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。