Bug 433890 - Use the converted Locale instead of the Locale String
parameter to avoid invalid Locale values in the context

Change-Id: I1d535f0c4a81004030eee4c7a6055d9203b922dd
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
index 790a065..dab54ce 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
@@ -37,6 +37,7 @@
 import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.e4.core.contexts.RunAndTrack;
 import org.eclipse.e4.core.internal.services.EclipseAdapter;
+import org.eclipse.e4.core.internal.services.ResourceBundleHelper;
 import org.eclipse.e4.core.services.adapter.Adapter;
 import org.eclipse.e4.core.services.contributions.IContributionFactory;
 import org.eclipse.e4.core.services.log.ILoggerProvider;
@@ -538,8 +539,13 @@
 		});
 
 		// translation
-		String locale = Locale.getDefault().toString();
-		appContext.set(TranslationService.LOCALE, locale);
+		String defaultLocaleString = Locale.getDefault().toString();
+
+		// ensure the default Locale value is correct
+		Locale transformedLocale = ResourceBundleHelper.toLocale(
+				defaultLocaleString, Locale.ENGLISH);
+
+		appContext.set(TranslationService.LOCALE, transformedLocale.toString());
 		TranslationService bundleTranslationProvider = TranslationProviderFactory
 				.bundleTranslationService(appContext);
 		appContext.set(TranslationService.class, bundleTranslationProvider);
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java
index 4a16f1f..ee517fc 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/LocaleChangeServiceImpl.java
@@ -76,7 +76,9 @@
 			Locale locale = ResourceBundleHelper.toLocale(localeString);
 
 			// set the locale to the application context
-			this.application.getContext().set(TranslationService.LOCALE, localeString);
+			// use the resolved locale instead of the given locale string to avoid invalid locales
+			// in context
+			this.application.getContext().set(TranslationService.LOCALE, locale.toString());
 
 			// update model
 			updateLocalization(this.application.getChildren());