1 /*****************************************************************************
5 * Creation date 02.10.2012
6 * @author Author: Maria KRUCHININA
8 *****************************************************************************/
10 package org.splat.i18n;
12 import java.util.Locale;
13 import org.springframework.context.support.ResourceBundleMessageSource;
16 * Resource bundle utility methods.
18 * @author Maria KRUCHININA
21 public final class I18nUtils {
24 * Contains the list of resources bundle.
26 private static ResourceBundleMessageSource _resourceBundleMessageSource;
30 * @param locale Locale
32 * @return message i18n
34 public static String getMessage(final Locale locale, final String code) {
35 return getMessage(locale, code, new Object[0]);
40 * @param locale Locale
43 * @return message i18n
45 public static String getMessage(final Locale locale, final String code, final Object... context) {
46 return _resourceBundleMessageSource.getMessage(code, context, locale);
51 * Return the translated message of a code with the language.
52 * @param language lowercase two-letter ISO-639 code
54 * @param context parameters
55 * @return Translated message
57 public static String getMessage(final String language, final String code, final Object... context) {
58 Locale locale = new Locale(language);
59 return getMessage(locale, code, context);
64 * Return the translated message of a code with the locale default.
66 * @param context parameters
67 * @return Translated message
69 public static String getMessageLocaleDefault(final String code, final Object... context) {
70 return getMessage(Locale.getDefault(), code, context);
75 * Get the resourceBundleMessageSource.
76 * @return the resourceBundleMessageSource
78 protected ResourceBundleMessageSource getResourceBundleMessageSource() {
79 return _resourceBundleMessageSource;
82 * Set the resourceBundleMessageSource.
83 * @param resourceBundleMessageSource the resourceBundleMessageSource to set
85 public void setResourceBundleMessageSource(
86 final ResourceBundleMessageSource resourceBundleMessageSource) {
87 _resourceBundleMessageSource = resourceBundleMessageSource;