1   /**
2    * Copyright (c) 2000-2008 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[] arguments) {
49  
50          return getLanguage().format(locale, pattern, arguments);
51      }
52  
53      public static String format(
54          long companyId, Locale locale, String pattern, Object argument) {
55  
56          return getLanguage().format(companyId, locale, pattern, argument);
57      }
58  
59      public static String format(
60          long companyId, Locale locale, String pattern, Object[] arguments) {
61  
62          return getLanguage().format(companyId, locale, pattern, arguments);
63      }
64  
65      public static String format(
66          PageContext pageContext, String pattern, Object argument) {
67  
68          return getLanguage().format(pageContext, pattern, argument);
69      }
70  
71      public static String format(
72          PageContext pageContext, String pattern, Object argument,
73          boolean translateArguments) {
74  
75          return getLanguage().format(
76              pageContext, pattern, argument, translateArguments);
77      }
78  
79      public static String format(
80          PageContext pageContext, String pattern, Object[] arguments) {
81  
82          return getLanguage().format(pageContext, pattern, arguments);
83      }
84  
85      public static String format(
86          PageContext pageContext, String pattern, Object[] arguments,
87          boolean translateArguments) {
88  
89          return getLanguage().format(
90              pageContext, pattern, arguments, translateArguments);
91      }
92  
93      public static String format(
94          PageContext pageContext, String pattern, LanguageWrapper argument) {
95  
96          return getLanguage().format(pageContext, pattern, argument);
97      }
98  
99      public static String format(
100         PageContext pageContext, String pattern, LanguageWrapper argument,
101         boolean translateArguments) {
102 
103         return getLanguage().format(
104             pageContext, pattern, argument, translateArguments);
105     }
106 
107     public static String format(
108         PageContext pageContext, String pattern, LanguageWrapper[] arguments) {
109 
110         return getLanguage().format(pageContext, pattern, arguments);
111     }
112 
113     public static String format(
114         PageContext pageContext, String pattern, LanguageWrapper[] arguments,
115         boolean translateArguments) {
116 
117         return getLanguage().format(
118             pageContext, pattern, arguments, translateArguments);
119     }
120 
121     public static void init() {
122         getLanguage().init();
123     }
124 
125     public static String get(Locale locale, String key) {
126         return getLanguage().get(locale, key);
127     }
128 
129     public static String get(long companyId, Locale locale, String key) {
130         return getLanguage().get(companyId, locale, key);
131     }
132 
133     public static String get(
134         long companyId, Locale locale, String key, String defaultValue) {
135 
136         return getLanguage().get(companyId, locale, key, defaultValue);
137     }
138 
139     public static String get(PageContext pageContext, String key) {
140         return getLanguage().get(pageContext, key);
141     }
142 
143     public static String get(
144         PageContext pageContext, String key, String defaultValue) {
145 
146         return getLanguage().get(pageContext, key, defaultValue);
147     }
148 
149     public static Locale[] getAvailableLocales() {
150         return getLanguage().getAvailableLocales();
151     }
152 
153     public static String getCharset(Locale locale) {
154         return getLanguage().getCharset(locale);
155     }
156 
157     public static Language getLanguage() {
158         return _language;
159     }
160 
161     public static String getLanguageId(PortletRequest portletRequest) {
162         return getLanguage().getLanguageId(portletRequest);
163     }
164 
165     public static String getLanguageId(HttpServletRequest request) {
166         return getLanguage().getLanguageId(request);
167     }
168 
169     public static String getLanguageId(Locale locale) {
170         return getLanguage().getLanguageId(locale);
171     }
172 
173     public static Locale getLocale(String languageCode) {
174         return getLanguage().getLocale(languageCode);
175     }
176 
177     public static String getTimeDescription(
178         PageContext pageContext, Long milliseconds) {
179 
180         return getLanguage().getTimeDescription(pageContext, milliseconds);
181     }
182 
183     public static String getTimeDescription(
184         PageContext pageContext, long milliseconds) {
185 
186         return getLanguage().getTimeDescription(pageContext, milliseconds);
187     }
188 
189     public static boolean isAvailableLocale(Locale locale) {
190         return getLanguage().isAvailableLocale(locale);
191     }
192 
193     public static void updateCookie(
194         HttpServletResponse response, Locale locale) {
195 
196         getLanguage().updateCookie(response, locale);
197     }
198 
199     public void setLanguage(Language language) {
200         _language = language;
201     }
202 
203     private static Language _language;
204 
205 }