1 package org.apache.fulcrum.localization; 2 3 56 57 import java.util.Locale ; 58 import java.util.ResourceBundle ; 59 60 import javax.servlet.http.HttpServletRequest ; 61 62 import org.apache.fulcrum.TurbineServices; 63 import org.apache.turbine.services.yaaficomponent.YaafiComponentService; 64 65 90 public abstract class Localization 91 { 92 private static LocalizationService localizationService; 93 104 public static String getString(String key) 105 { 106 return getService().getBundle().getString(key); 107 } 108 109 112 public static String getString(Locale locale, String key) 113 { 114 return getService().getString(null, locale, key); 115 } 116 117 123 public static String getString(String bundleName, Locale locale, 124 String key) 125 { 126 return getService().getString(bundleName, locale, key); 127 } 128 129 138 public static String getString(HttpServletRequest req, String key) 139 { 140 return getService().getBundle(req).getString(key); 141 } 142 143 153 public static String getString(String key, String lang) 154 { 155 return getBundle(getDefaultBundleName(), new Locale (lang, "")) 156 .getString(key); 157 } 158 159 165 public static ResourceBundle getBundle(String bundleName) 166 { 167 return getService().getBundle(bundleName); 168 } 169 170 178 public static ResourceBundle getBundle(String bundleName, 179 String languageHeader) 180 { 181 return getService().getBundle(bundleName, languageHeader); 182 } 183 184 191 public static ResourceBundle getBundle(HttpServletRequest req) 192 { 193 return getService().getBundle(req); 194 } 195 196 204 public static ResourceBundle getBundle(String bundleName, 205 HttpServletRequest req) 206 { 207 return getService().getBundle(bundleName, req); 208 } 209 210 218 public static ResourceBundle getBundle(String bundleName, Locale locale) 219 { 220 return getService().getBundle(bundleName, locale); 221 } 222 223 229 public static void setBundle(String defaultBundle) 230 { 231 getService().setBundle(defaultBundle); 232 } 233 234 237 public static Locale getLocale(HttpServletRequest req) 238 { 239 return getService().getLocale(req); 240 } 241 242 249 public static Locale getLocale(String languageHeader) 250 { 251 return getService().getLocale(languageHeader); 252 } 253 254 257 public static String getDefaultBundleName() 258 { 259 return getService().getDefaultBundleName(); 260 } 261 262 265 public static String getDefaultCountry() 266 { 267 return getService().getDefaultCountry(); 268 } 269 270 273 public static String getDefaultLanguage() 274 { 275 return getService().getDefaultLanguage(); 276 } 277 278 283 protected static final LocalizationService getService() 284 { 285 if (localizationService==null) 286 { 287 try{ 288 YaafiComponentService yaafi = (YaafiComponentService) TurbineServices.getInstance().getService( 289 YaafiComponentService.SERVICE_NAME); 290 localizationService = (LocalizationService) yaafi.lookup(LocalizationService.class.getName()); 291 } 292 catch (Exception e) 293 { 294 throw new RuntimeException ("Problem looking up localization service: " + e.getMessage()); 295 } 296 } 297 return localizationService; 298 } 299 300 public static void setLocalizationService(LocalizationService service){ 301 localizationService = service; 302 } 303 304 307 public static String format(String bundleName, Locale locale, 308 String key, Object arg1) 309 { 310 return getService().format(bundleName, locale, key, arg1); 311 } 312 313 316 public static String format(String bundleName, Locale locale, 317 String key, Object arg1, Object arg2) 318 { 319 return getService().format(bundleName, locale, key, arg1, arg2); 320 } 321 322 325 public static String format(String bundleName, Locale locale, 326 String key, Object [] args) 327 { 328 return getService().format(bundleName, locale, key, args); 329 } 330 331 332 334 337 public static String getString(String key, Locale locale) 338 { 339 return getString(locale, key); 340 } 341 342 343 346 public static String getString(String key, HttpServletRequest req) 347 { 348 return getString(req, key); 349 } 350 } 351 | Popular Tags |