1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.kernel.language;
24  
25  import java.util.Locale;
26  
27  import javax.portlet.PortletRequest;
28  
29  import javax.servlet.http.HttpServletRequest;
30  import javax.servlet.http.HttpServletResponse;
31  import javax.servlet.jsp.PageContext;
32  
33  /**
34   * <a href="LanguageUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class LanguageUtil {
40  
41      public static String format(
42          Locale locale, String pattern, Object argument) {
43  
44          return getLanguage().format(locale, pattern, argument);
45      }
46  
47      public static String format(
48          Locale locale, String pattern, Object argument,
49          boolean translateArguments) {
50  
51          return getLanguage().format(
52              locale, pattern, argument, translateArguments);
53      }
54  
55      public static String format(
56          Locale locale, String pattern, Object[] arguments) {
57  
58          return getLanguage().format(locale, pattern, arguments);
59      }
60  
61      public static String format(
62          long companyId, Locale locale, String pattern, Object argument) {
63  
64          return getLanguage().format(companyId, locale, pattern, argument);
65      }
66  
67      public static String format(
68          long companyId, Locale locale, String pattern, Object argument,
69          boolean translateArguments) {
70  
71          return getLanguage().format(
72              companyId, locale, pattern, argument, translateArguments);
73      }
74  
75      public static String format(
76          long companyId, Locale locale, String pattern, Object[] arguments) {
77  
78          return getLanguage().format(companyId, locale, pattern, arguments);
79      }
80  
81      public static String format(
82          long companyId, Locale locale, String pattern, Object[] arguments,
83          boolean translateArguments) {
84  
85          return getLanguage().format(
86              companyId, locale, pattern, arguments, translateArguments);
87      }
88  
89      public static String format(
90          PageContext pageContext, String pattern, Object argument) {
91  
92          return getLanguage().format(pageContext, pattern, argument);
93      }
94  
95      public static String format(
96          PageContext pageContext, String pattern, Object argument,
97          boolean translateArguments) {
98  
99          return getLanguage().format(
100             pageContext, pattern, argument, translateArguments);
101     }
102 
103     public static String format(
104         PageContext pageContext, String pattern, Object[] arguments) {
105 
106         return getLanguage().format(pageContext, pattern, arguments);
107     }
108 
109     public static String format(
110         PageContext pageContext, String pattern, Object[] arguments,
111         boolean translateArguments) {
112 
113         return getLanguage().format(
114             pageContext, pattern, arguments, translateArguments);
115     }
116 
117     public static String format(
118         PageContext pageContext, String pattern, LanguageWrapper argument) {
119 
120         return getLanguage().format(pageContext, pattern, argument);
121     }
122 
123     public static String format(
124         PageContext pageContext, String pattern, LanguageWrapper argument,
125         boolean translateArguments) {
126 
127         return getLanguage().format(
128             pageContext, pattern, argument, translateArguments);
129     }
130 
131     public static String format(
132         PageContext pageContext, String pattern, LanguageWrapper[] arguments) {
133 
134         return getLanguage().format(pageContext, pattern, arguments);
135     }
136 
137     public static String format(
138         PageContext pageContext, String pattern, LanguageWrapper[] arguments,
139         boolean translateArguments) {
140 
141         return getLanguage().format(
142             pageContext, pattern, arguments, translateArguments);
143     }
144 
145     public static void init() {
146         getLanguage().init();
147     }
148 
149     public static String get(Locale locale, String key) {
150         return getLanguage().get(locale, key);
151     }
152 
153     public static String get(long companyId, Locale locale, String key) {
154         return getLanguage().get(companyId, locale, key);
155     }
156 
157     public static String get(
158         long companyId, Locale locale, String key, String defaultValue) {
159 
160         return getLanguage().get(companyId, locale, key, defaultValue);
161     }
162 
163     public static String get(PageContext pageContext, String key) {
164         return getLanguage().get(pageContext, key);
165     }
166 
167     public static String get(
168         PageContext pageContext, String key, String defaultValue) {
169 
170         return getLanguage().get(pageContext, key, defaultValue);
171     }
172 
173     public static Locale[] getAvailableLocales() {
174         return getLanguage().getAvailableLocales();
175     }
176 
177     public static String getCharset(Locale locale) {
178         return getLanguage().getCharset(locale);
179     }
180 
181     public static Language getLanguage() {
182         return _language;
183     }
184 
185     public static String getLanguageId(PortletRequest portletRequest) {
186         return getLanguage().getLanguageId(portletRequest);
187     }
188 
189     public static String getLanguageId(HttpServletRequest request) {
190         return getLanguage().getLanguageId(request);
191     }
192 
193     public static String getLanguageId(Locale locale) {
194         return getLanguage().getLanguageId(locale);
195     }
196 
197     public static Locale getLocale(String languageCode) {
198         return getLanguage().getLocale(languageCode);
199     }
200 
201     public static String getTimeDescription(
202         PageContext pageContext, Long milliseconds) {
203 
204         return getLanguage().getTimeDescription(pageContext, milliseconds);
205     }
206 
207     public static String getTimeDescription(
208         PageContext pageContext, long milliseconds) {
209 
210         return getLanguage().getTimeDescription(pageContext, milliseconds);
211     }
212 
213     public static boolean isAvailableLocale(Locale locale) {
214         return getLanguage().isAvailableLocale(locale);
215     }
216 
217     public static void updateCookie(
218         HttpServletRequest request, HttpServletResponse response,
219         Locale locale) {
220 
221         getLanguage().updateCookie(request, response, locale);
222     }
223 
224     public void setLanguage(Language language) {
225         _language = language;
226     }
227 
228     private static Language _language;
229 
230 }