Here you can find the source of getMessage(Locale locale, String key, String... args)
public static String getMessage(Locale locale, String key, String... args)
//package com.java2s; /*/*from w ww.j a v a2 s .c o m*/ * Copyright (C) 2010 Viettel Telecom. All rights reserved. * VIETTEL PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.text.MessageFormat; import java.util.ResourceBundle; import java.util.Locale; public class Main { /** * RESOURCE. */ //private static final String RESOURCE = "com/viettel/config/ "; private static final String RESOURCE = "com/viettel/config/message/Language"; private static final String RESOURCEMESSAGE = "com/viettel/config/message/Message"; /** * local. */ private static Locale local = null; /** * languageRb. */ private static ResourceBundle languageRb = null; private static ResourceBundle messageRb = null; public static String getMessage(Locale locale, String key, String... args) { if (locale != null) { messageRb = ResourceBundle.getBundle(RESOURCEMESSAGE, locale); } else { messageRb = ResourceBundle.getBundle(RESOURCEMESSAGE); } MessageFormat msgFormat = new MessageFormat(messageRb.getString(key)); Object[] arguments = new Object[args.length]; int i = 0; for (Object obj : args) { String arg = (String) obj; try { arg = messageRb.getString((String) obj); } catch (Exception e) { System.out.println(e.getMessage()); } finally { arguments[i++] = arg; } } String output = msgFormat.format(arguments); return output; } /** * getString * * @param key String * @return value */ public static String getString(String key) { if (local != null) { languageRb = ResourceBundle.getBundle(RESOURCE, local); } else { languageRb = ResourceBundle.getBundle(RESOURCE); } try { return languageRb.getString(key); } catch (Exception ex) { return key; } } public static String getString(Locale locale, String key) { if (locale != null) { languageRb = ResourceBundle.getBundle(RESOURCE, locale); } else { languageRb = ResourceBundle.getBundle(RESOURCE); } return languageRb.getString(key); } public static String getString(String key, String... args) { if (local != null) { languageRb = ResourceBundle.getBundle(RESOURCE, local); } else { languageRb = ResourceBundle.getBundle(RESOURCE); } MessageFormat msgFormat = new MessageFormat(languageRb.getString(key)); Object[] arguments = new Object[args.length]; int i = 0; for (Object obj : args) { String arg = (String) obj; try { arg = languageRb.getString((String) obj); } catch (Exception e) { System.out.println(e.getMessage()); } finally { arguments[i++] = arg; } } String output = msgFormat.format(arguments); return output; } public static String getString(Locale locale, String key, String... args) { if (locale != null) { languageRb = ResourceBundle.getBundle(RESOURCE, locale); } else { languageRb = ResourceBundle.getBundle(RESOURCE); } MessageFormat msgFormat = new MessageFormat(languageRb.getString(key)); Object[] arguments = new Object[args.length]; int i = 0; for (Object obj : args) { String arg = (String) obj; try { arg = languageRb.getString((String) obj); } catch (Exception e) { System.out.println(e.getMessage()); } finally { arguments[i++] = arg; } } String output = msgFormat.format(arguments); return output; } }