2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.modbus.helioseasycontrols.internal;
15 import java.util.Locale;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.core.i18n.LocaleProvider;
20 import org.openhab.core.i18n.TranslationProvider;
21 import org.osgi.framework.Bundle;
22 import org.osgi.framework.BundleContext;
23 import org.osgi.service.component.annotations.Activate;
24 import org.osgi.service.component.annotations.Component;
25 import org.osgi.service.component.annotations.Reference;
28 * This class provides translated texts
30 * @author Bernhard Bauer - Initial contribution
33 @Component(service = HeliosEasyControlsTranslationProvider.class)
34 public class HeliosEasyControlsTranslationProvider {
36 private final Bundle bundle;
37 private final TranslationProvider i18nProvider;
38 private final LocaleProvider localeProvider;
41 public HeliosEasyControlsTranslationProvider(@Reference TranslationProvider i18nProvider,
42 @Reference LocaleProvider localeProvider, BundleContext context) {
43 this.bundle = context.getBundle();
44 this.i18nProvider = i18nProvider;
45 this.localeProvider = localeProvider;
48 public HeliosEasyControlsTranslationProvider(final HeliosEasyControlsTranslationProvider other) {
49 this.bundle = other.bundle;
50 this.i18nProvider = other.i18nProvider;
51 this.localeProvider = other.localeProvider;
54 public String getText(String key, @Nullable Object... arguments) {
56 Locale locale = localeProvider.getLocale();
57 String message = i18nProvider.getText(bundle, key, this.getDefaultText(key), locale, arguments);
58 if (message != null) {
61 } catch (IllegalArgumentException e) {
63 return "Unable to load message for key " + key;
66 public @Nullable String getDefaultText(String key) {
67 return i18nProvider.getText(bundle, key, key, Locale.ENGLISH);