KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > common > i18n > Translate


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Nicolas Modrzyk.
20  * Contributor(s): Emmanuel Cecchet.
21  */

22
23 package org.continuent.sequoia.common.i18n;
24
25 import java.text.MessageFormat JavaDoc;
26 import java.util.MissingResourceException JavaDoc;
27 import java.util.ResourceBundle JavaDoc;
28
29 /**
30  * Class to translate the different messages of Sequoia.
31  *
32  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
33  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
34  * @version 1.0
35  */

36
37 public final class Translate
38 {
39   private static final String JavaDoc BUNDLE_NAME = "org.continuent.sequoia.common.i18n.messages"; //$NON-NLS-1$
40

41   private static final ResourceBundle JavaDoc RESOURCE_BUNDLE = ResourceBundle
42                                                           .getBundle(BUNDLE_NAME);
43
44   /**
45    * Class is not meant to be instantiated.
46    */

47   private Translate()
48   {
49   }
50   
51   /**
52    * Returns the translation for the given &lt;code&gt;key&lt;/code&gt;
53    *
54    * @param key the translation key
55    * @return the translation or &lt;code&gt;'!' + key + '!'&lt;/code&gt; if
56    * there is no translation for the given key
57    */

58   public static String JavaDoc get(String JavaDoc key)
59   {
60     try
61     {
62       return RESOURCE_BUNDLE.getString(key);
63     }
64     catch (MissingResourceException JavaDoc e)
65     {
66       return '!' + key + '!';
67     }
68   }
69   
70   /**
71    * Returns the translation for the given &lt;code&gt;key&lt;/code&gt;
72    *
73    * @param key the translation key
74    * @param args array of &lt;code&gt;Objects&lt;/code&gt; used by the
75    * translation
76    * @return the translation or &lt;code&gt;'!' + key + '!'&lt;/code&gt; if
77    * there is no translation for the given key
78    */

79   public static String JavaDoc get(String JavaDoc key, Object JavaDoc[] args)
80   {
81     try
82     {
83       return MessageFormat.format(RESOURCE_BUNDLE.getString(key), args);
84     }
85     catch (MissingResourceException JavaDoc e)
86     {
87       return '!' + key + '!';
88     }
89   }
90
91   // all methods below are convenience methods which
92
// delegate to get(String key, Object[] args)
93

94   /**
95    * @see #get(String, Object[])
96    */

97   public static String JavaDoc get(String JavaDoc key, boolean parameter)
98   {
99     return get(key, new Object JavaDoc[]{Boolean.valueOf(parameter)});
100   }
101
102   /**
103    * @see #get(String, Object[])
104    */

105   public static String JavaDoc get(String JavaDoc key, int parameter)
106   {
107     return get(key, new Object JavaDoc[]{Integer.toString(parameter)});
108   }
109
110   /**
111    * @see #get(String, Object[])
112    */

113   public static String JavaDoc get(String JavaDoc key, long parameter)
114   {
115     return get(key, new Object JavaDoc[]{Long.toString(parameter)});
116   }
117
118   /**
119    * @see #get(String, Object[])
120    */

121   public static String JavaDoc get(String JavaDoc key, Object JavaDoc param1, Object JavaDoc param2)
122   {
123     return get(key, new Object JavaDoc[]{param1, param2});
124   }
125
126   /**
127    * @see #get(String, Object[])
128    */

129   public static String JavaDoc get(String JavaDoc key, Object JavaDoc parameter)
130   {
131     return get(key, new Object JavaDoc[]{parameter});
132   }
133 }
Popular Tags