Bug 433895 - Changed value type of context value
TranslationService.LOCALE from String to Locale
Change-Id: I94013e1a69cab411b8b0ca72d815965b900d0570
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
index fd3159f..41b853a 100644
--- a/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.core.services/META-INF/MANIFEST.MF
@@ -4,7 +4,7 @@
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
-Bundle-Version: 1.3.0.qualifier
+Bundle-Version: 2.0.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: javax.annotation;version="1.1.0",
diff --git a/bundles/org.eclipse.e4.core.services/pom.xml b/bundles/org.eclipse.e4.core.services/pom.xml
index df59e5c..50b15c4 100644
--- a/bundles/org.eclipse.e4.core.services/pom.xml
+++ b/bundles/org.eclipse.e4.core.services/pom.xml
@@ -19,6 +19,6 @@
</parent>
<groupId>org.eclipse.e4</groupId>
<artifactId>org.eclipse.e4.core.services</artifactId>
- <version>1.3.0-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/BundleTranslationProvider.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/BundleTranslationProvider.java
index 3d37dab..cad658f 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/BundleTranslationProvider.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/BundleTranslationProvider.java
@@ -29,7 +29,7 @@
try {
ResourceBundle resourceBundle = ResourceBundleHelper.getResourceBundleForUri(
- contributorURI, ResourceBundleHelper.toLocale(locale), provider);
+ contributorURI, locale, provider);
return getResourceString(key, resourceBundle);
} catch (Exception e) {
// an error occurred on trying to retrieve the translation for the given key
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/TranslationObjectSupplier.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/TranslationObjectSupplier.java
index 141c529..33af24a 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/TranslationObjectSupplier.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/internal/services/TranslationObjectSupplier.java
@@ -83,15 +83,8 @@
* The {@link Locale} to use for creating the message instances.
*/
@Inject
- public void setLocale(@Optional @Named(TranslationService.LOCALE) String locale) {
- try {
- this.locale = locale == null ? Locale.getDefault() : ResourceBundleHelper
- .toLocale(locale);
- } catch (Exception e) {
- // parsing the locale String to a Locale failed, so we use the default Locale
- ResourceBundleHelper.logInvalidFormat(locale, logService);
- this.locale = Locale.getDefault();
- }
+ public void setLocale(@Optional @Named(TranslationService.LOCALE) Locale locale) {
+ this.locale = locale == null ? Locale.getDefault() : locale;
// update listener
updateMessages();
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
index 6e04eb4..44e6c92 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/nls/Message.java
@@ -157,7 +157,7 @@
/**
* @return optional parameter to point to resource bundles in a different location
* @see Message
- * @since 1.3
+ * @since 2.0
*/
String contributionURI() default "";
}
diff --git a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/translation/TranslationService.java b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/translation/TranslationService.java
index 351ea58..349e922 100644
--- a/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/translation/TranslationService.java
+++ b/bundles/org.eclipse.e4.core.services/src/org/eclipse/e4/core/services/translation/TranslationService.java
@@ -11,6 +11,7 @@
******************************************************************************/
package org.eclipse.e4.core.services.translation;
+import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javax.inject.Inject;
@@ -38,7 +39,7 @@
@Inject
@Named(LOCALE)
- protected String locale;
+ protected Locale locale;
@Inject
public TranslationService() {
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java
index 0c1b954..3625c2c 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/nls/NLSTest.java
@@ -63,7 +63,7 @@
public void testSimpleMessages() {
//ensure the en Locale is set for this test
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context);
//test all values are set
@@ -86,7 +86,7 @@
public void testSimpleMessagesDifferentLocale() {
//set Locale to de
- this.context.set(TranslationService.LOCALE, "de");
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context);
//test all values are set
@@ -117,7 +117,7 @@
//get german translations as the default locale is set to "de_DE"
//with checking the equinox.root.locale in the system properties the fallback is skipped as it tells
//that the root properties file is for locale en.
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context);
//test all values are set
@@ -144,7 +144,7 @@
Locale.setDefault(new Locale("de"));
//set a locale for which no resource bundle is set
- this.context.set(TranslationService.LOCALE, "fr");
+ this.context.set(TranslationService.LOCALE, Locale.FRENCH);
TestSimpleObject o = ContextInjectionFactory.make(TestSimpleObject.class, this.context);
//test all values are set
@@ -168,7 +168,7 @@
public void testMessages() {
//ensure the en Locale is set for this test
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context);
//test all values are set
@@ -191,7 +191,7 @@
public void testMessagesDifferentLocale() {
//set Locale to de
- this.context.set(TranslationService.LOCALE, "de");
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context);
//test all values are set
@@ -222,7 +222,7 @@
//get german translations as the default locale is set to "de_DE"
//with checking the equinox.root.locale in the system properties the fallback is skipped as it tells
//that the root properties file is for locale en.
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context);
//test all values are set
@@ -249,7 +249,7 @@
Locale.setDefault(new Locale("de"));
//set a locale for which no resource bundle is set
- this.context.set(TranslationService.LOCALE, "fr");
+ this.context.set(TranslationService.LOCALE, Locale.FRENCH);
TestMessagesObject o = ContextInjectionFactory.make(TestMessagesObject.class, this.context);
//test all values are set
@@ -273,7 +273,7 @@
public void testBundleMessages() {
//ensure the en Locale is set for this test
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context);
//test all values are set
@@ -296,7 +296,7 @@
public void testBundleMessagesDifferentLocale() {
//set Locale to de
- this.context.set(TranslationService.LOCALE, "de");
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context);
//test all values are set
@@ -327,7 +327,7 @@
//get german translations as the default locale is set to "de_DE"
//with checking the equinox.root.locale in the system properties the fallback is skipped as it tells
//that the root properties file is for locale en.
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context);
//test all values are set
@@ -354,7 +354,7 @@
Locale.setDefault(new Locale("de"));
//set a locale for which no resource bundle is set
- this.context.set(TranslationService.LOCALE, "fr");
+ this.context.set(TranslationService.LOCALE, Locale.FRENCH);
TestBundleObject o = ContextInjectionFactory.make(TestBundleObject.class, this.context);
//test all values are set
@@ -378,7 +378,7 @@
public void testClassBasedResourceBundle() {
//ensure the en Locale is set for this test
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context);
//test all values are set
@@ -401,7 +401,7 @@
public void testClassBasedResourceBundleDifferentLocale() {
//set Locale to de
- this.context.set(TranslationService.LOCALE, "de");
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context);
//test all values are set
@@ -432,7 +432,7 @@
//get german translations as the default locale is set to "de_DE"
//with checking the equinox.root.locale in the system properties the fallback is skipped as it tells
//that the root properties file is for locale en.
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context);
//test all values are set
@@ -459,7 +459,7 @@
Locale.setDefault(new Locale("de"));
//set a locale for which no resource bundle is set
- this.context.set(TranslationService.LOCALE, "fr");
+ this.context.set(TranslationService.LOCALE, Locale.FRENCH);
TestResourceBundleClassObject o = ContextInjectionFactory.make(TestResourceBundleClassObject.class, this.context);
//test all values are set
@@ -483,7 +483,7 @@
public void testResourcesBundle() {
//ensure the en Locale is set for this test
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context);
//test all values are set
@@ -506,7 +506,7 @@
public void testResourcesBundleDifferentLocale() {
//set Locale to de
- this.context.set(TranslationService.LOCALE, "de");
+ this.context.set(TranslationService.LOCALE, Locale.GERMAN);
TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context);
//test all values are set
@@ -537,7 +537,7 @@
//get german translations as the default locale is set to "de_DE"
//with checking the equinox.root.locale in the system properties the fallback is skipped as it tells
//that the root properties file is for locale en.
- this.context.set(TranslationService.LOCALE, "en");
+ this.context.set(TranslationService.LOCALE, Locale.ENGLISH);
TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context);
//test all values are set
@@ -564,7 +564,7 @@
Locale.setDefault(new Locale("de"));
//set a locale for which no resource bundle is set
- this.context.set(TranslationService.LOCALE, "fr");
+ this.context.set(TranslationService.LOCALE, Locale.FRENCH);
TestResourcesBundleObject o = ContextInjectionFactory.make(TestResourcesBundleObject.class, this.context);
//test all values are set