Java 8 MessageFormat - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 MessageFormat class.

This code example shows how to use the following methods: applyPattern, setLocale, toPattern
        String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4}  E {1,choice,0#off|1#on} F {0, date}";
        format1 = new MessageFormat(pattern);
    } 
 
    public void test_applyPatternLjava_lang_String_AndroidFailure() { 
        MessageFormat format = new MessageFormat("test");
        format.setLocale(Locale.FRENCH); // use French since English has the
        // same LONG and FULL time patterns 
        format.applyPattern("{0,time, Full}");
        assertEquals("Wrong full time pattern", "{0,time,full}", format
                .toPattern());
    } 
 
    public void test_formatToCharacterIteratorLjava_lang_Object() { 
        // Test for method formatToCharacterIterator(java.lang.Object) 
        new Support_MessageFormat( 
                "test_formatToCharacterIteratorLjava_lang_Object") 
                .t_formatToCharacterIterator(); 
 
        try { 
Full Snippet Info
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format
        } 
 
        if (args == null) {
            return formatString;
        } else { 
            MessageFormat formatter = new MessageFormat(formatString);
            return formatter.format(args);
        } 
    } 
 
    private static String getExceptionMessage(RhinoException ex)
    { 
        String msg;
        if (ex instanceof JavaScriptException) {
            msg = getMessage("msg.uncaughtJSException", ex.details());
        } else if (ex instanceof EcmaError) {
            msg = getMessage("msg.uncaughtEcmaError", ex.details());
        } else if (ex instanceof EvaluatorException) {
            msg = ex.details();
        } else { 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: applyPattern, setLocale, toPattern
        String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4}  E {1,choice,0#off|1#on} F {0, date}";
        format1 = new MessageFormat(pattern);
    } 
 
    public void test_applyPatternLjava_lang_String_AndroidFailure() { 
        MessageFormat format = new MessageFormat("test");
        format.setLocale(Locale.FRENCH); // use French since English has the
        // same LONG and FULL time patterns 
        format.applyPattern("{0,time, Full}");
        assertEquals("Wrong full time pattern", "{0,time,full}", format
                .toPattern());
    } 
 
    public void test_formatToCharacterIteratorLjava_lang_Object() { 
        // Test for method formatToCharacterIterator(java.lang.Object) 
        new Support_MessageFormat( 
                "test_formatToCharacterIteratorLjava_lang_Object") 
                .t_formatToCharacterIterator(); 
 
        try { 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format, applyPattern, setLocale
    } 
 
    public static String getLangueMessageFormatter ( String key,  Object[] messageArguments ) {    	
    	String str = Utilities.getLangueMessage( key ) ; 
    	 
        MessageFormat formatter = new MessageFormat("");      
        formatter.setLocale(Utilities.currentLocale);
 
        formatter.applyPattern(str);
        return formatter.format(messageArguments);
    } 
     
    public static String retourLigne()
    { 
        return "\r\n"; 
    } 
} 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format, applyPattern, setLocale
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format, applyPattern, setLocale
	public static String getString(String key, Object[] params){
		try{ 
			ResourceBundle res = ResourceBundle.getBundle("resource/smartworksMessage", new Locale(SmartUtil.getCurrentUser().getLocale()));
			String pattern = res.getString(key);
			if(SmartUtil.isBlankObject(params)) return pattern;
			MessageFormat mf = new MessageFormat("");
			mf.setLocale(new Locale(SmartUtil.getCurrentUser().getLocale()));
			mf.applyPattern(pattern);
			return mf.format(params);
		}catch(Exception e){
			 
		} 
		return ""; 
	} 
	 
	public static String[] getStringArray(String key){
		try{ 
			ResourceBundle res = ResourceBundle.getBundle("resource/smartworksMessage", new Locale(SmartUtil.getCurrentUser().getLocale()));
			return res.getStringArray(key);
		}catch(Exception e){
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format, applyPattern, setFormats, setLocale
    public static String msg(String msgKey, Object... msgArgs) {
        return msg(RESOURCE_BUNDLE, msgKey, msgArgs);
    } 
     
    static String msgCompilerErrors(int numErrors) {
        MessageFormat fmt = new MessageFormat("");
        fmt.setLocale(Locale.getDefault());
        double[] limits = {1, 2};
        String[] keys = {RESOURCE_BUNDLE.getString("compile.errors.one"), 
                RESOURCE_BUNDLE.getString("compile.errors.several")};
        ChoiceFormat choice = new ChoiceFormat(limits, keys);
        fmt.applyPattern(RESOURCE_BUNDLE.getString("compile.errors.pattern"));
        Format[] formats = {choice, NumberFormat.getInstance()};
        fmt.setFormats(formats);
        return fmt.format(new Object[]{numErrors});
    } 
     
    static String msgSystemError() {
        return msg("error.system")  
                + msg("error.report.url") 
Full Snippet Info
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
    } 
 
    public void t_format_with_FieldPosition() { 
 
        String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
        MessageFormat format = new MessageFormat(pattern, Locale.US);
 
        Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
        Integer hamburgers = new Integer(8);
        Object[] objects = new Object[] { hamburgers, new Double(3.5),
                hamburgers, date, date };
 
        super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!"; 
 
        // test with MessageFormat.Field.ARGUMENT 
        t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
 
        // test other format fields that are included in the formatted text 
        t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0,
                0); 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: format, setLocale
        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();
    } 
 
    // -------------------------------------------------------------- 
    // STATIC SUPPORT METHODS 
    // -------------------------------------------------------------- 
 
    private static Hashtable<String, StringManager> managers =
        new Hashtable<String, StringManager>();
 
    /** 
     * Get the StringManager for a particular package. If a manager for 
     * a package already exists, it will be reused, else a new 
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
String result = getKeyMessage(key, defaultMessage);
	    Object rarg[] = {
		arg
	    }; 
	    return new MessageFormat(result).format(rarg);
	} 
     
    public String getFormattedKeyMessage(String key,
					 String defaultMessage,
					 Object arg1, Object arg2)
	{ 
	    String result = getKeyMessage(key, defaultMessage);
	    Object arg[] = {
		arg1, arg2
	    }; 
	    return new MessageFormat(result).format(arg);
	} 
     
    public String getFormattedKeyMessage(String key,
Full Snippet Info
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 MessageFormat Questions & Answers:

See Code Examples for Java 8 MessageFormat Methods: