diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 11d8fd3d6..d0ec627d5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE Release with new features and bugfixes: +* https://github.com/devonfw/IDEasy/issues/2126[#2126]: Fix language dropdown in GUI * https://github.com/devonfw/IDEasy/issues/2176[#2176]: Support 7z archive extraction * https://github.com/devonfw/IDEasy/issues/2100[#2100]: Fix Python not available for Mac x64 diff --git a/gui/src/main/java/com/devonfw/ide/gui/MainController.java b/gui/src/main/java/com/devonfw/ide/gui/MainController.java index 11e0f4399..6728992af 100644 --- a/gui/src/main/java/com/devonfw/ide/gui/MainController.java +++ b/gui/src/main/java/com/devonfw/ide/gui/MainController.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; + import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; @@ -76,7 +77,6 @@ private void initialize() { } private void initLanguageComboBox() { - this.languageMap.clear(); selectedLanguage.getItems().clear(); diff --git a/gui/src/main/java/com/devonfw/ide/gui/nls/NlsService.java b/gui/src/main/java/com/devonfw/ide/gui/nls/NlsService.java index 1378bfc74..be9afc065 100644 --- a/gui/src/main/java/com/devonfw/ide/gui/nls/NlsService.java +++ b/gui/src/main/java/com/devonfw/ide/gui/nls/NlsService.java @@ -68,20 +68,23 @@ public class NlsService { * @param locale the preferred locale, or {@code null} to use persisted or default locale. */ public NlsService(Locale locale) { - + this.availableLocales = getAvailableLocales(); initialize(locale); } /** - * Initializes the service using an explicit, persisted, or system default locale. + * Initializes the service using an explicit, persisted, or system default locale (if applicable) or English as fallback. * * @param explicitLocale the locale requested by the caller, or {@code null}. */ private void initialize(Locale explicitLocale) { - Locale localeToApply = explicitLocale; if (localeToApply == null) { - localeToApply = Locale.getDefault(); + // Locale.getDefault() returns "de_DE" (for systems set to German) which isn't the same as "de" + localeToApply = Locale.of(Locale.getDefault().getLanguage()); + if (!availableLocales.contains(localeToApply)) { + localeToApply = Locale.ENGLISH; + } } applyLocale(localeToApply, false); } @@ -240,7 +243,10 @@ private void loadBundle() { } private ResourceBundle loadBundle(Locale locale) { - + // ResourceBundle.getBundle(...) with Locale.ENGLISH would return German properties on system locale = German + if (locale.equals(Locale.ENGLISH)) { + return ResourceBundle.getBundle(BUNDLE_NAME, Locale.ROOT); + } return ResourceBundle.getBundle(BUNDLE_NAME, locale); } diff --git a/gui/src/test/java/com/devonfw/ide/gui/nls/NlsServiceTest.java b/gui/src/test/java/com/devonfw/ide/gui/nls/NlsServiceTest.java index 4a59afb25..8b4ccf562 100644 --- a/gui/src/test/java/com/devonfw/ide/gui/nls/NlsServiceTest.java +++ b/gui/src/test/java/com/devonfw/ide/gui/nls/NlsServiceTest.java @@ -1,6 +1,7 @@ package com.devonfw.ide.gui.nls; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; import java.io.IOException; import java.io.InputStream; @@ -17,11 +18,15 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; +import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import com.devonfw.ide.gui.context.IdeGuiStateManager; @@ -56,16 +61,28 @@ public void tearDown() { } } - @Test - public void testGetInstanceWithLocale() { - - NlsService service = new NlsService(Locale.ENGLISH); + @ParameterizedTest + @MethodSource("localeProvider") + public void testGetInstanceWithLocale(Locale systemLocale, Locale providedLocal, Locale expectedServiceLocal, String expectedString) { + Locale.setDefault(systemLocale); + NlsService service = new NlsService(providedLocal); - assertThat(service.getLocale()).isEqualTo(Locale.ENGLISH); + assertThat(service.getLocale()).isEqualTo(expectedServiceLocal); assertThat(service.getResourceBundle()).isNotNull(); - assertThat(service.get("CurrentLanguage")).isEqualTo("English (en)"); + assertThat(service.get("CurrentLanguage")).isEqualTo(expectedString); } + static Stream localeProvider() { + return Stream.of( + arguments(Locale.GERMANY, Locale.ENGLISH, Locale.ENGLISH, "English (en)"), + arguments(Locale.GERMANY, Locale.GERMAN, Locale.GERMAN, "Deutsch (de)"), + arguments(Locale.GERMANY, null, Locale.GERMAN, "Deutsch (de)"), + arguments(Locale.UK, Locale.ENGLISH, Locale.ENGLISH, "English (en)"), + arguments(Locale.UK, Locale.GERMAN, Locale.GERMAN, "Deutsch (de)"), + arguments(Locale.UK, null, Locale.ENGLISH, "English (en)"), + arguments(Locale.FRANCE, null, Locale.ENGLISH, "English (en)") + ); + } @Test public void testSetLocale() { @@ -78,7 +95,6 @@ public void testSetLocale() { assertThat(service.get("CurrentLanguage")).isEqualTo("Deutsch (de)"); } - @Test public void testAllLocalizationBundlesContainExactlyTheEnglishKeys() throws IOException { @@ -147,7 +163,6 @@ public void testSetLocalePersistsSelectionInUserHomeIdeProperties() throws IOExc assertThat(properties.getProperty("IDE_OPTIONS")).isEqualTo("-Duser.language=de"); } - @Test public void testPersistLocaleUpdatesExistingUserLangInIdeOptions() throws IOException { @@ -314,6 +329,3 @@ private static void writeJarEntry(JarOutputStream jos, String name) throws IOExc } } - - -