Salome HOME
679ddec128bb86afe700411a2b01da5276da7c98
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / i18n / I18nUtils.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            Id: 
5  * Creation date   02.10.2012
6  * @author         Author: Maria KRUCHININA
7  * @version        Revision: 
8  *****************************************************************************/
9
10 package org.splat.i18n; 
11
12 import java.util.Locale;
13 import org.springframework.context.support.ResourceBundleMessageSource;
14
15 /**
16  * Resource bundle utility methods.
17  * 
18  * @author Maria KRUCHININA
19  *
20  */
21 public final class I18nUtils {
22
23         /**
24          * Contains the list of resources bundle. 
25          */
26         private static ResourceBundleMessageSource _resourceBundleMessageSource;
27         
28         /**
29          * .
30          * @param locale Locale
31          * @param code key
32          * @return message i18n
33          */
34         public static String getMessage(final Locale locale, final String code) {
35                 return getMessage(locale, code, new Object[0]);
36         }
37         
38         /**
39          * .
40          * @param locale Locale
41          * @param code key
42          * @param context args
43          * @return message i18n
44          */
45         public static String getMessage(final Locale locale, final String code, final Object... context) {
46                 return _resourceBundleMessageSource.getMessage(code, context, locale);
47         }
48         
49         
50         /**
51          * Return the translated message of a code with the language.
52          * @param language lowercase two-letter ISO-639 code
53          * @param code code
54          * @param context parameters
55          * @return Translated message
56          */
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);
60         }       
61         
62         
63         /**
64          * Return the translated message of a code with the locale default.
65          * @param code code
66          * @param context parameters
67          * @return Translated message
68          */
69         public static String getMessageLocaleDefault(final String code, final Object... context) {
70                 return getMessage(Locale.getDefault(), code, context);
71         }       
72         
73         
74         /**
75          * Get the resourceBundleMessageSource.
76          * @return the resourceBundleMessageSource
77          */
78         protected ResourceBundleMessageSource getResourceBundleMessageSource() {
79                 return _resourceBundleMessageSource;
80         }
81         /**
82          * Set the resourceBundleMessageSource.
83          * @param resourceBundleMessageSource the resourceBundleMessageSource to set
84          */
85         public void setResourceBundleMessageSource(
86                         final ResourceBundleMessageSource resourceBundleMessageSource) {
87                 _resourceBundleMessageSource = resourceBundleMessageSource;
88         }       
89         
90 }