]> git.basschouten.com Git - openhab-addons.git/blob
9be5226db68fd56f951752173a8b4e0e674e99c3
[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.enphase.internal;
14
15 import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.ERROR_NODATA;
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 import org.osgi.framework.FrameworkUtil;
23
24 /**
25  * Class to get the message for the enphase message code.
26  *
27  * @author Hilbrand Bouwkamp - Initial contribution
28  */
29 @NonNullByDefault
30 public class MessageTranslator {
31
32     private final LocaleProvider localeProvider;
33     private final TranslationProvider i18nProvider;
34     private final Bundle bundle;
35
36     public MessageTranslator(LocaleProvider localeProvider, TranslationProvider i18nProvider) {
37         this.localeProvider = localeProvider;
38         this.i18nProvider = i18nProvider;
39         bundle = FrameworkUtil.getBundle(this.getClass());
40     }
41
42     /**
43      * Gets the message text for the enphase message code.
44      *
45      * @param key the enphase message code
46      * @return translated key
47      */
48     public @Nullable String translate(String key) {
49         return i18nProvider.getText(bundle, key, ERROR_NODATA, localeProvider.getLocale());
50     }
51 }