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 <lg.hc@free.fr>
pull/3343/head
lolodomo 2023-01-28 14:18:58 +01:00 committed by GitHub
parent c079f2cfaf
commit 14bae356c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -85,7 +85,7 @@ public class KarafAddonService implements AddonService {
@Override
public List<Addon> 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

View File

@ -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;
}
}

View File

@ -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

View File

@ -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