diff options
author | Dirk Fauth | 2013-04-18 09:32:29 +0000 |
---|---|---|
committer | Tom Schindl | 2013-04-18 09:32:29 +0000 |
commit | 089a7edd831006839e0c256962eacc0656563874 (patch) | |
tree | 14506f6fd087b6b97d6ffb88cd1e4e2bb4a5cef2 | |
parent | 1fbfddbcd5235a2a01b8eae7ba2aa771335b8add (diff) | |
download | org.eclipse.e4.tools-089a7edd831006839e0c256962eacc0656563874.tar.gz org.eclipse.e4.tools-089a7edd831006839e0c256962eacc0656563874.tar.xz org.eclipse.e4.tools-089a7edd831006839e0c256962eacc0656563874.zip |
Bug 405935 - Errors in new message extension for handling not foundI20130418-0745I20130418-0645
resources
2 files changed, 106 insertions, 11 deletions
diff --git a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleHelper.java b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleHelper.java index fb3f017e..2201ab5d 100644 --- a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleHelper.java +++ b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleHelper.java @@ -21,6 +21,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.List; import java.util.Locale; +import java.util.MissingResourceException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import java.util.ResourceBundle.Control; @@ -208,18 +209,33 @@ public class ResourceBundleHelper { //there is a equinox.root.locale configured that matches the specified locale //so the special search order is used //to achieve this we first search without a fallback to the default locale - resourceBundle = ResourceBundle.getBundle(baseName, locale, loader, - ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT)); + try { + resourceBundle = ResourceBundle.getBundle(baseName, locale, loader, + ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT)); + } + catch (MissingResourceException e) { + //do nothing + } //if there is no ResourceBundle found for that path, we will now search for the default locale ResourceBundle if (resourceBundle == null) { - resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), loader, - ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT)); + try { + resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), loader, + ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT)); + } + catch (MissingResourceException e) { + //do nothing + } } } else { //there is either no equinox.root.locale configured or it does not match the specified locale // -> use the default search order - resourceBundle = ResourceBundle.getBundle(baseName, locale, loader); + try { + resourceBundle = ResourceBundle.getBundle(baseName, locale, loader); + } + catch (MissingResourceException e) { + //do nothing + } } return resourceBundle; @@ -227,7 +243,8 @@ public class ResourceBundleHelper { /** * This method searches for the {@link ResourceBundle} in a modified way by inspecting the configuration option - * <code>equinox.root.locale</code>. + * <code>equinox.root.locale</code>. It uses the {@link BundleResourceBundleControl} to load the resources out + * of a {@link Bundle}. * <p><b>Note: This method will only search for ResourceBundles based on properties files.</b></p> * <p> * If the value for this system property is set to an empty String the default search order for ResourceBundles is used: @@ -267,6 +284,53 @@ public class ResourceBundleHelper { * @see ResourceBundle#getBundle(String, Locale, Control) */ public static ResourceBundle getEquinoxResourceBundle(String baseName, Locale locale, Bundle bundle) { + return getEquinoxResourceBundle(baseName, locale, + new BundleResourceBundleControl(bundle, true), new BundleResourceBundleControl(bundle, false)); + } + + /** + * This method searches for the {@link ResourceBundle} in a modified way by inspecting the configuration option + * <code>equinox.root.locale</code>. + * <p><b>Note: This method will only search for ResourceBundles based on properties files.</b></p> + * <p> + * If the value for this system property is set to an empty String the default search order for ResourceBundles is used: + * <ul> + * <li>bn + Ls + "_" + Cs + "_" + Vs</li> + * <li>bn + Ls + "_" + Cs</li> + * <li>bn + Ls</li> + * <li>bn + Ld + "_" + Cd + "_" + Vd</li> + * <li>bn + Ld + "_" + Cd</li> + * <li>bn + Ld</li> + * <li>bn</li> + * </ul> + * Where bn is this bundle's localization basename, Ls, Cs and Vs are the specified locale (language, country, variant) and + * Ld, Cd and Vd are the default locale (language, country, variant). + * </p> + * <p> + * If Ls equals the value of <code>equinox.root.locale</code> then the following search order is used: + * <ul> + * <li>bn + Ls + "_" + Cs + "_" + Vs</li> + * <li>bn + Ls + "_" + Cs</li> + * <li>bn + Ls</li> + * <li>bn</li> + * <li>bn + Ld + "_" + Cd + "_" + Vd</li> + * <li>bn + Ld + "_" + Cd</li> + * <li>bn + Ld</li> + * <li>bn</li> + * </ul> + * </p> + * If <code>equinox.root.locale=en</code> and en_XX or en is asked for then this allows the root file to be used instead of + * falling back to the default locale. + * + * @param baseName the base name of the resource bundle, a fully qualified class name + * @param locale the locale for which a resource bundle is desired + * @param withFallback The {@link Control} that uses the default locale fallback on searching for resource bundles. + * @param withoutFallback The {@link Control} that doesn't use the default locale fallback on searching for resource bundles. + * @return a resource bundle for the given base name and locale + * + * @see ResourceBundle#getBundle(String, Locale, Control) + */ + public static ResourceBundle getEquinoxResourceBundle(String baseName, Locale locale, Control withFallback, Control withoutFallback) { ResourceBundle resourceBundle = null; String equinoxLocale = getEquinoxRootLocale(); @@ -276,16 +340,31 @@ public class ResourceBundleHelper { //there is a equinox.root.locale configured that matches the specified locale //so the special search order is used //to achieve this we first search without a fallback to the default locale - resourceBundle = ResourceBundle.getBundle(baseName, locale, new BundleResourceBundleControl(bundle, false)); + try { + resourceBundle = ResourceBundle.getBundle(baseName, locale, withoutFallback); + } + catch (MissingResourceException e) { + //do nothing + } //if there is no ResourceBundle found for that path, we will now search for the default locale ResourceBundle if (resourceBundle == null) { - resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), new BundleResourceBundleControl(bundle, false)); + try { + resourceBundle = ResourceBundle.getBundle(baseName, Locale.getDefault(), withoutFallback); + } + catch (MissingResourceException e) { + //do nothing + } } } else { //there is either no equinox.root.locale configured or it does not match the specified locale // -> use the default search order - resourceBundle = ResourceBundle.getBundle(baseName, locale, new BundleResourceBundleControl(bundle, true)); + try { + resourceBundle = ResourceBundle.getBundle(baseName, locale, withFallback); + } + catch (MissingResourceException e) { + //do nothing + } } return resourceBundle; diff --git a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleTranslationProvider.java b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleTranslationProvider.java index 163087b0..6cd9fd88 100644 --- a/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleTranslationProvider.java +++ b/bundles/org.eclipse.e4.tools.services/src/org/eclipse/e4/tools/services/impl/ResourceBundleTranslationProvider.java @@ -33,7 +33,7 @@ public class ResourceBundleTranslationProvider { * modified by prefixing and suffixing it with "!" when calling translate(String). */ public ResourceBundleTranslationProvider(ResourceBundle resourceBundle) { - this.resourceBundle = resourceBundle; + this.setResourceBundle(resourceBundle); } /** @@ -57,7 +57,9 @@ public class ResourceBundleTranslationProvider { if (this.resourceBundle == null) { result = "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ } - result = resourceBundle.getString(key); + else { + result = this.resourceBundle.getString(key); + } } catch (MissingResourceException e) { if (key.contains("_")) { //$NON-NLS-1$ result = translate(key.replace('_', '.')); @@ -67,4 +69,18 @@ public class ResourceBundleTranslationProvider { } return result; } + + /** + * @return The {@link ResourceBundle} that is used for translations. + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + /** + * @param resourceBundle The {@link ResourceBundle} to use for translations. + */ + public void setResourceBundle(ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + } } |