From 14bae356c29aead14815e3a1fd9267b05688bb82 Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sat, 28 Jan 2023 14:18:58 +0100 Subject: [PATCH] Consider language in KarafAddonService when creating Addon (#3341) * [REST] Consider language when retrieving installed addons Fix openhab/openhab-webui#1666 Signed-off-by: Laurent Garnier --- .../openhab/core/karaf/internal/KarafAddonService.java | 8 ++++---- .../org/openhab/core/internal/addon/AddonI18nUtil.java | 4 ++-- .../OH-INF/i18n/acmeweather_de.properties | 4 ++-- .../OH-INF/i18n/acmeweather_nl.properties | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/KarafAddonService.java b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/KarafAddonService.java index 30dde29598..6bcbda82e4 100644 --- a/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/KarafAddonService.java +++ b/bundles/org.openhab.core.karaf/src/main/java/org/openhab/core/karaf/internal/KarafAddonService.java @@ -85,7 +85,7 @@ public class KarafAddonService implements AddonService { @Override public List getAddons(@Nullable Locale locale) { try { - return Arrays.stream(featuresService.listFeatures()).filter(this::isAddon).map(this::getAddon) + return Arrays.stream(featuresService.listFeatures()).filter(this::isAddon).map(f -> getAddon(f, locale)) .sorted(Comparator.comparing(Addon::getLabel)).toList(); } catch (Exception e) { logger.error("Exception while retrieving features: {}", e.getMessage()); @@ -103,7 +103,7 @@ public class KarafAddonService implements AddonService { Feature feature; try { feature = featuresService.getFeature(FeatureInstaller.PREFIX + id); - return getAddon(feature); + return getAddon(feature, locale); } catch (Exception e) { logger.error("Exception while querying feature '{}'", id); return null; @@ -124,7 +124,7 @@ public class KarafAddonService implements AddonService { }; } - private Addon getAddon(Feature feature) { + private Addon getAddon(Feature feature, @Nullable Locale locale) { String name = getName(feature.getName()); String type = getType(feature.getName()); String uid = type + Addon.ADDON_SEPARATOR + name; @@ -133,7 +133,7 @@ public class KarafAddonService implements AddonService { Addon.Builder addon = Addon.create(uid).withType(type).withId(name).withContentType(ADDONS_CONTENT_TYPE) .withVersion(feature.getVersion()).withAuthor(ADDONS_AUTHOR, true).withInstalled(isInstalled); - AddonInfo addonInfo = addonInfoRegistry.getAddonInfo(uid); + AddonInfo addonInfo = addonInfoRegistry.getAddonInfo(uid, locale); if (isInstalled && addonInfo != null) { // only enrich if this add-on is installed, otherwise wrong data might be added diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/addon/AddonI18nUtil.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/addon/AddonI18nUtil.java index d28d67ac6e..adb8c1a956 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/addon/AddonI18nUtil.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/addon/AddonI18nUtil.java @@ -48,7 +48,7 @@ public class AddonI18nUtil { return localizedText != null ? localizedText : defaultLabel; } - private String inferKey(String bindingId, String lastSegment) { - return "binding." + bindingId + "." + lastSegment; + private String inferKey(String addonId, String lastSegment) { + return "addon." + addonId + "." + lastSegment; } } diff --git a/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_de.properties b/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_de.properties index 5a3e76b78d..b5591c43fd 100644 --- a/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_de.properties +++ b/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_de.properties @@ -1,2 +1,2 @@ -binding.acmeweather.name = ACME Wetter Binding -binding.acmeweather.description = Das ACME Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom ACME Wetterdienst bereit +addon.acmeweather.name = ACME Wetter Binding +addon.acmeweather.description = Das ACME Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom ACME Wetterdienst bereit diff --git a/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_nl.properties b/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_nl.properties index 14702e328a..48c2dcce9b 100644 --- a/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_nl.properties +++ b/itests/org.openhab.core.addon.xml.tests/src/main/resources/test-bundle-pool/acmeweather.bundle/OH-INF/i18n/acmeweather_nl.properties @@ -1,2 +1,2 @@ -binding.acmeweather.name = ACME Weer Binding -binding.acmeweather.description = De ACME Weer Binding biedt verschillende meteorologische gegevens zoals temperatuur, vochtigheid en luchtdruk voor configureerbare locaties uit ACME weerdienst klaar +addon.acmeweather.name = ACME Weer Binding +addon.acmeweather.description = De ACME Weer Binding biedt verschillende meteorologische gegevens zoals temperatuur, vochtigheid en luchtdruk voor configureerbare locaties uit ACME weerdienst klaar