1 package org.apache.turbine.services.localization; 2 3 18 19 import java.util.Locale ; 20 import java.util.MissingResourceException ; 21 import java.util.ResourceBundle ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.turbine.services.pull.ApplicationTool; 26 import org.apache.turbine.util.RunData; 27 28 36 public class LocalizationTool implements ApplicationTool 37 { 38 39 private static Log log = LogFactory.getLog(LocalizationTool.class); 40 41 45 protected Locale locale; 46 47 50 private ResourceBundle bundle; 51 52 55 private String bundleName; 56 57 60 public LocalizationTool() 61 { 62 refresh(); 63 } 64 65 78 public String get(String key) 79 { 80 try 81 { 82 return Localization.getString(getBundleName(null), getLocale(), key); 83 } 84 catch (MissingResourceException noKey) 85 { 86 log.error(noKey); 87 return null; 88 } 89 } 90 91 96 public Locale getLocale() 97 { 98 return locale; 99 } 100 101 110 protected String getBundleName(Object data) 111 { 112 return Localization.getDefaultBundleName(); 113 } 114 115 116 118 122 public final void init(Object data) 123 { 124 if (data instanceof RunData) 125 { 126 locale = Localization.getLocale(((RunData) data).getRequest()); 129 bundleName = getBundleName(data); 130 } 131 } 132 133 136 public void refresh() 137 { 138 locale = null; 139 bundle = null; 140 bundleName = null; 141 } 142 } 143 | Popular Tags |