]> git.basschouten.com Git - openhab-addons.git/blob
fa29131430fce5eba66ae0bb8df462e04041fe2b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.hdpowerview.internal;
14
15 import java.util.Locale;
16
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
23 /**
24  * {@link HDPowerViewTranslationProvider} provides i18n message lookup
25  *
26  * @author Jacob Laursen - Initial contribution
27  */
28 @NonNullByDefault
29 public class HDPowerViewTranslationProvider {
30
31     private final Bundle bundle;
32     private final TranslationProvider i18nProvider;
33     private final LocaleProvider localeProvider;
34
35     public HDPowerViewTranslationProvider(Bundle bundle, TranslationProvider i18nProvider,
36             LocaleProvider localeProvider) {
37         this.bundle = bundle;
38         this.i18nProvider = i18nProvider;
39         this.localeProvider = localeProvider;
40     }
41
42     public String getText(String key, @Nullable Object... arguments) {
43         String text = i18nProvider.getText(bundle, key, key, localeProvider.getLocale(), arguments);
44         if (text != null) {
45             return text;
46         }
47         return key;
48     }
49
50     public Locale getLocale() {
51         return localeProvider.getLocale();
52     }
53 }