diff options
-rw-r--r-- | src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java | 39 | ||||
-rw-r--r-- | src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java | 22 |
2 files changed, 39 insertions, 22 deletions
diff --git a/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java b/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java index 7ef0e36..c592502 100644 --- a/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java +++ b/src/net/java/sip/communicator/impl/resources/ResourceManagementServiceImpl.java @@ -23,6 +23,7 @@ import org.osgi.framework.*; * * @author Damian Minkov * @author Yana Stamcheva + * @author Lubomir Marinov */ public class ResourceManagementServiceImpl implements ResourceManagementService, @@ -37,8 +38,16 @@ public class ResourceManagementServiceImpl private Map<String, String> imageResources; private ResourcePack imagePack = null; + private Map<String, String> languageResources; private LanguagePack languagePack = null; + /** + * The {@link Locale} of <code>languageResources</code> so that the caching + * of the latter can be used when a string with the same <code>Locale</code> + * is requested. + */ + private Locale languageLocale; + private Map<String, String> settingsResources; private ResourcePack settingsPack = null; @@ -70,6 +79,12 @@ public class ResourceManagementServiceImpl (LanguagePack) getDefaultResourcePack(LanguagePack.class.getName(), LanguagePack.RESOURCE_NAME_DEFAULT_VALUE); + if (languagePack != null) + { + languageLocale = Locale.getDefault(); + languageResources = languagePack.getResources(languageLocale); + } + settingsPack = getDefaultResourcePack(SettingsPack.class.getName(), SettingsPack.RESOURCE_NAME_DEFAULT_VALUE); @@ -178,6 +193,8 @@ public class ResourceManagementServiceImpl else if(resourcePack instanceof LanguagePack && languagePack == null) { languagePack = (LanguagePack) resourcePack; + languageLocale = Locale.getDefault(); + languageResources = resources; } else if(resourcePack instanceof SettingsPack && settingsPack == null) { @@ -408,8 +425,15 @@ public class ResourceManagementServiceImpl */ public String getI18NString(String key, String[] params, Locale locale) { - Map<String, String> stringResources - = languagePack.getResources(locale); + Map<String, String> stringResources; + if ((locale != null) && locale.equals(languageLocale)) + { + stringResources = languageResources; + } + else + { + stringResources = languagePack.getResources(locale); + } String resourceString = stringResources.get(key); @@ -456,8 +480,15 @@ public class ResourceManagementServiceImpl */ public char getI18nMnemonic(String key, Locale locale) { - Map<String,String> stringResources - = languagePack.getResources(locale); + Map<String, String> stringResources; + if ((locale != null) && locale.equals(languageLocale)) + { + stringResources = languageResources; + } + else + { + stringResources = languagePack.getResources(locale); + } String resourceString = stringResources.get(key); diff --git a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java index 6ec249b..980147a 100644 --- a/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java +++ b/src/net/java/sip/communicator/plugin/defaultresourcepack/DefaultLanguagePackImpl.java @@ -8,7 +8,6 @@ package net.java.sip.communicator.plugin.defaultresourcepack; import java.util.*; import net.java.sip.communicator.service.resources.*; -import net.java.sip.communicator.util.*; /** * @@ -17,8 +16,6 @@ import net.java.sip.communicator.util.*; public class DefaultLanguagePackImpl implements LanguagePack { - private Logger logger = Logger.getLogger(DefaultLanguagePackImpl.class); - private static final String DEFAULT_RESOURCE_PATH = "resources.languages.resources"; @@ -31,17 +28,7 @@ public class DefaultLanguagePackImpl */ public Map<String, String> getResources() { - ResourceBundle resourceBundle - = ResourceBundle.getBundle( DEFAULT_RESOURCE_PATH, - Locale.getDefault()); - - Map<String, String> resources = new TreeMap<String, String>(); - - this.initResources(resourceBundle, resources); - - this.initPluginResources(resources, Locale.getDefault()); - - return resources; + return getResources(Locale.getDefault()); } /** @@ -94,17 +81,16 @@ public class DefaultLanguagePackImpl * * @param resourceBundle The initial <tt>ResourceBundle</tt>, corresponding * to the "main" properties file. - * @param locale The locale we're looking for. * @param resources A <tt>Map</tt> that would store the data. */ private void initResources( ResourceBundle resourceBundle, Map<String, String> resources) { - Enumeration colorKeys = resourceBundle.getKeys(); + Enumeration<String> colorKeys = resourceBundle.getKeys(); while (colorKeys.hasMoreElements()) { - String key = (String) colorKeys.nextElement(); + String key = colorKeys.nextElement(); String value = resourceBundle.getString(key); resources.put(key, value); @@ -126,7 +112,7 @@ public class DefaultLanguagePackImpl { String resourceBundleName = pluginProperties.next(); - if (resourceBundleName.indexOf("_") == -1) + if (resourceBundleName.indexOf('_') == -1) { ResourceBundle resourceBundle = ResourceBundle.getBundle( |