1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.language;
16  
17  import java.util.Locale;
18  
19  import javax.portlet.PortletConfig;
20  import javax.portlet.PortletRequest;
21  
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  import javax.servlet.jsp.PageContext;
25  
26  /**
27   * <a href="LanguageUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class LanguageUtil {
32  
33      public static String format(
34          Locale locale, String pattern, Object argument) {
35  
36          return getLanguage().format(locale, pattern, argument);
37      }
38  
39      public static String format(
40          Locale locale, String pattern, Object argument,
41          boolean translateArguments) {
42  
43          return getLanguage().format(
44              locale, pattern, argument, translateArguments);
45      }
46  
47      public static String format(
48          Locale locale, String pattern, Object[] arguments) {
49  
50          return getLanguage().format(locale, pattern, arguments);
51      }
52  
53      public static String format(
54          Locale locale, String pattern, Object[] arguments,
55          boolean translateArguments) {
56  
57          return getLanguage().format(
58              locale, pattern, arguments, translateArguments);
59      }
60  
61      /**
62       * @deprecated
63       */
64      public static String format(
65          long companyId, Locale locale, String pattern, Object argument) {
66  
67          return getLanguage().format(locale, pattern, argument);
68      }
69  
70      /**
71       * @deprecated
72       */
73      public static String format(
74          long companyId, Locale locale, String pattern, Object argument,
75          boolean translateArguments) {
76  
77          return getLanguage().format(
78              locale, pattern, argument, translateArguments);
79      }
80  
81      /**
82       * @deprecated
83       */
84      public static String format(
85          long companyId, Locale locale, String pattern, Object[] arguments) {
86  
87          return getLanguage().format(locale, pattern, arguments);
88      }
89  
90      /**
91       * @deprecated
92       */
93      public static String format(
94          long companyId, Locale locale, String pattern, Object[] arguments,
95          boolean translateArguments) {
96  
97          return getLanguage().format(
98              locale, pattern, arguments, translateArguments);
99      }
100 
101     public static String format(
102         PageContext pageContext, String pattern, LanguageWrapper argument) {
103 
104         return getLanguage().format(pageContext, pattern, argument);
105     }
106 
107     public static String format(
108         PageContext pageContext, String pattern, LanguageWrapper argument,
109         boolean translateArguments) {
110 
111         return getLanguage().format(
112             pageContext, pattern, argument, translateArguments);
113     }
114 
115     public static String format(
116         PageContext pageContext, String pattern, LanguageWrapper[] arguments) {
117 
118         return getLanguage().format(pageContext, pattern, arguments);
119     }
120 
121     public static String format(
122         PageContext pageContext, String pattern, LanguageWrapper[] arguments,
123         boolean translateArguments) {
124 
125         return getLanguage().format(
126             pageContext, pattern, arguments, translateArguments);
127     }
128 
129     public static String format(
130         PageContext pageContext, String pattern, Object argument) {
131 
132         return getLanguage().format(pageContext, pattern, argument);
133     }
134 
135     public static String format(
136         PageContext pageContext, String pattern, Object argument,
137         boolean translateArguments) {
138 
139         return getLanguage().format(
140             pageContext, pattern, argument, translateArguments);
141     }
142 
143     public static String format(
144         PageContext pageContext, String pattern, Object[] arguments) {
145 
146         return getLanguage().format(pageContext, pattern, arguments);
147     }
148 
149     public static String format(
150         PageContext pageContext, String pattern, Object[] arguments,
151         boolean translateArguments) {
152 
153         return getLanguage().format(
154             pageContext, pattern, arguments, translateArguments);
155     }
156 
157     public static String format(
158         PortletConfig portletConfig, Locale locale, String pattern,
159         Object argument) {
160 
161         return getLanguage().format(portletConfig, locale, pattern, argument);
162     }
163 
164     public static String format(
165         PortletConfig portletConfig, Locale locale, String pattern,
166         Object argument, boolean translateArguments) {
167 
168         return getLanguage().format(
169             portletConfig, locale, pattern, argument, translateArguments);
170     }
171 
172     public static String format(
173         PortletConfig portletConfig, Locale locale, String pattern,
174         Object[] arguments) {
175 
176         return getLanguage().format(portletConfig, locale, pattern, arguments);
177     }
178 
179     public static String format(
180         PortletConfig portletConfig, Locale locale, String pattern,
181         Object[] arguments, boolean translateArguments) {
182 
183         return getLanguage().format(
184             portletConfig, locale, pattern, arguments, translateArguments);
185     }
186 
187     public static String get(Locale locale, String key) {
188         return getLanguage().get(locale, key);
189     }
190 
191     public static String get(Locale locale, String key, String defaultValue) {
192         return getLanguage().get(locale, key, defaultValue);
193     }
194 
195     /**
196      * @deprecated
197      */
198     public static String get(long companyId, Locale locale, String key) {
199         return getLanguage().get(locale, key);
200     }
201 
202     /**
203      * @deprecated
204      */
205     public static String get(
206         long companyId, Locale locale, String key, String defaultValue) {
207 
208         return getLanguage().get(locale, key, defaultValue);
209     }
210 
211     public static String get(PageContext pageContext, String key) {
212         return getLanguage().get(pageContext, key);
213     }
214 
215     public static String get(
216         PageContext pageContext, String key, String defaultValue) {
217 
218         return getLanguage().get(pageContext, key, defaultValue);
219     }
220 
221     public static String get(
222         PortletConfig portletConfig, Locale locale, String key) {
223 
224         return getLanguage().get(portletConfig, locale, key);
225     }
226 
227     public static String get(
228         PortletConfig portletConfig, Locale locale, String key,
229         String defaultValue) {
230 
231         return getLanguage().get(portletConfig, locale, key, defaultValue);
232     }
233 
234     public static Locale[] getAvailableLocales() {
235         return getLanguage().getAvailableLocales();
236     }
237 
238     public static String getCharset(Locale locale) {
239         return getLanguage().getCharset(locale);
240     }
241 
242     public static Language getLanguage() {
243         return _language;
244     }
245 
246     public static String getLanguageId(HttpServletRequest request) {
247         return getLanguage().getLanguageId(request);
248     }
249 
250     public static String getLanguageId(Locale locale) {
251         return getLanguage().getLanguageId(locale);
252     }
253 
254     public static String getLanguageId(PortletRequest portletRequest) {
255         return getLanguage().getLanguageId(portletRequest);
256     }
257 
258     public static Locale getLocale(String languageCode) {
259         return getLanguage().getLocale(languageCode);
260     }
261 
262     public static String getTimeDescription(
263         PageContext pageContext, long milliseconds) {
264 
265         return getLanguage().getTimeDescription(pageContext, milliseconds);
266     }
267 
268     public static String getTimeDescription(
269         PageContext pageContext, Long milliseconds) {
270 
271         return getLanguage().getTimeDescription(pageContext, milliseconds);
272     }
273 
274     public static void init() {
275         getLanguage().init();
276     }
277 
278     public static boolean isAvailableLocale(Locale locale) {
279         return getLanguage().isAvailableLocale(locale);
280     }
281 
282     public static boolean isDuplicateLanguageCode(String languageCode) {
283         return getLanguage().isDuplicateLanguageCode(languageCode);
284     }
285 
286     public static void resetAvailableLocales(long companyId) {
287         getLanguage().resetAvailableLocales(companyId);
288     }
289 
290     public static void updateCookie(
291         HttpServletRequest request, HttpServletResponse response,
292         Locale locale) {
293 
294         getLanguage().updateCookie(request, response, locale);
295     }
296 
297     public void setLanguage(Language language) {
298         _language = language;
299     }
300 
301     private static Language _language;
302 
303 }