Skip to content

Commit

Permalink
Code review corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
clinique committed Jan 16, 2025
1 parent 5634385 commit 78ef1e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,25 @@ private List<String> determineResourceNames() {
return getText(null, key, locale);
}

private @Nullable String getTranslatedText(String resourceName, String key, Locale locale) {
try {
// Modify the search order so that the following applies:
// 1.) baseName + "_" + language + "_" + country
// 2.) baseName + "_" + language
// 3.) baseName
// 4.) null -> leads to a default text
// Not using the default fallback strategy helps that not the default locale
// search order is applied between 2.) and 3.).
ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceName, locale, this.resourceClassLoader,
Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));

return resourceBundle.getString(key);
} catch (Exception ex) {
// nothing to do
private @Nullable String getTranslatedText(@Nullable String resourceName, @Nullable String key,
@Nullable Locale locale) {
if (resourceName != null && locale != null && key != null && !key.isEmpty()) {
try {
// Modify the search order so that the following applies:
// 1.) baseName + "_" + language + "_" + country
// 2.) baseName + "_" + language
// 3.) baseName
// 4.) null -> leads to a default text
// Not using the default fallback strategy helps that not the default locale
// search order is applied between 2.) and 3.).
ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceName, locale, this.resourceClassLoader,
Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));

return resourceBundle.getString(key);
} catch (NullPointerException ex) {
// nothing to do
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.core.internal.service;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.util.BundleResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
Expand All @@ -28,6 +29,7 @@
public class BundleResolverImpl implements BundleResolver {

@Override
@Nullable
public Bundle resolveBundle(Class<?> clazz) {
return FrameworkUtil.getBundle(clazz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.openhab.core.util;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.osgi.framework.Bundle;

/**
Expand All @@ -29,5 +30,6 @@ public interface BundleResolver {
* @param clazz the {@link Class} to resolve the bundle for.
* @return the bundle associated with the given {@link Class}.
*/
@Nullable
Bundle resolveBundle(Class<?> clazz);
}

0 comments on commit 78ef1e2

Please sign in to comment.