1 2 package org.apache.turbine.services.localization; 3 4 19 20 import java.util.Locale ; 21 import java.util.ResourceBundle ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 25 import org.apache.turbine.services.TurbineServices; 26 import org.apache.turbine.util.RunData; 27 28 53 public abstract class Localization 54 { 55 61 public static String getString(String bundleName, Locale locale, 62 String key) 63 { 64 return getService().getString(bundleName, locale, key); 65 } 66 67 78 public static String getString(String key) 79 { 80 return getService().getString(null, null, key); 81 } 82 83 88 public static String getString(String key, Locale locale) 89 { 90 return getService().getString(null, locale, key); 91 } 92 93 106 public static String getString(String key, HttpServletRequest req) 107 { 108 return getService().getString(null, getLocale(req), key); 109 } 110 111 121 public static String getString(String key, String lang) 122 { 123 return getString(getDefaultBundleName(), new Locale (lang, ""), key); 124 } 125 126 132 public static ResourceBundle getBundle(String bundleName) 133 { 134 return getService().getBundle(bundleName); 135 } 136 137 145 public static ResourceBundle getBundle(String bundleName, 146 String languageHeader) 147 { 148 return getService().getBundle(bundleName, languageHeader); 149 } 150 151 158 public static ResourceBundle getBundle(HttpServletRequest req) 159 { 160 return getService().getBundle(req); 161 } 162 163 171 public static ResourceBundle getBundle(String bundleName, 172 HttpServletRequest req) 173 { 174 return getService().getBundle(bundleName, req); 175 } 176 177 185 public static ResourceBundle getBundle(String bundleName, Locale locale) 186 { 187 return getService().getBundle(bundleName, locale); 188 } 189 190 195 public static void setBundle(String defaultBundle) 196 { 197 getService().setBundle(defaultBundle); 198 } 199 200 208 public static Locale getLocale(HttpServletRequest req) 209 { 210 return getService().getLocale(req); 211 } 212 213 220 public static Locale getLocale(String languageHeader) 221 { 222 return getService().getLocale(languageHeader); 223 } 224 225 228 public static String getDefaultBundleName() 229 { 230 return getService().getDefaultBundleName(); 231 } 232 233 238 protected static final LocalizationService getService() 239 { 240 return (LocalizationService) TurbineServices.getInstance() 241 .getService(LocalizationService.SERVICE_NAME); 242 } 243 244 247 public static String getString(RunData data, String key) 248 { 249 return getBundle(data.getRequest()).getString(key); 250 } 251 252 255 public static ResourceBundle getBundle(String bundleName, RunData data) 256 { 257 return getBundle(bundleName, data.getRequest()); 258 } 259 } 260 | Popular Tags |