1 /*****************************************************************************
5 * Creation date 02.10.2012
6 * @author Author: Maria KRUCHININA
8 *****************************************************************************/
10 package org.splat.i18n;
12 import java.util.Locale;
14 import org.springframework.context.support.ResourceBundleMessageSource;
17 * Resource bundle utility methods.
19 * @author Maria KRUCHININA
22 public final class I18nUtils {
25 * Contains the list of resources bundle.
27 private static ResourceBundleMessageSource resourceBundleMessageSource;
31 * @param locale Locale
33 * @return message i18n
35 public static String getMessage(final Locale locale, final String code) {
36 return getMessage(locale, code, new Object[0]);
41 * @param locale Locale
44 * @return message i18n
46 public static String getMessage(final Locale locale, final String code, final Object... context) {
47 return resourceBundleMessageSource.getMessage(code, context, locale);
52 * Return the translated message of a code with the language.
53 * @param language lowercase two-letter ISO-639 code
55 * @param context parameters
56 * @return Translated message
58 public static String getMessage(final String language, final String code, final Object... context) {
59 Locale locale = new Locale(language);
60 return getMessage(locale, code, context);
65 * Return the translated message of a code with the locale default.
67 * @param context parameters
68 * @return Translated message
70 public static String getMessageLocaleDefault(final String code, final Object... context) {
71 return getMessage(Locale.getDefault(), code, context);
76 * Get the resourceBundleMessageSource.
77 * @return the resourceBundleMessageSource
79 protected ResourceBundleMessageSource getResourceBundleMessageSource() {
80 return resourceBundleMessageSource;
83 * Set the resourceBundleMessageSource.
84 * @param aResourceBundleMessageSource the resourceBundleMessageSource to set
86 public void setResourceBundleMessageSource(
87 final ResourceBundleMessageSource aResourceBundleMessageSource) {
88 resourceBundleMessageSource = aResourceBundleMessageSource;