]> git.basschouten.com Git - openhab-addons.git/blob
1b9fd1821283a83f00ce1965dca82ac28fb15b04
[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.androidtv.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.i18n.LocaleProvider;
18 import org.openhab.core.i18n.TranslationProvider;
19 import org.osgi.framework.Bundle;
20 import org.osgi.framework.FrameworkUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * {@link AndroidTVTranslationProvider} provides i18n message lookup.
26  * 
27  * @author Ben Rosenblum - Initial contribution
28  */
29 @NonNullByDefault
30 public class AndroidTVTranslationProvider {
31
32     private final Bundle bundle;
33     private final TranslationProvider i18nProvider;
34     private final LocaleProvider localeProvider;
35     private final Logger logger = LoggerFactory.getLogger(AndroidTVTranslationProvider.class);
36
37     public AndroidTVTranslationProvider(TranslationProvider i18nProvider, LocaleProvider localeProvider) {
38         this.bundle = FrameworkUtil.getBundle(this.getClass());
39         this.i18nProvider = i18nProvider;
40         this.localeProvider = localeProvider;
41     }
42
43     public String getText(String key, @Nullable Object... arguments) {
44         @Nullable
45         String text = i18nProvider.getText(bundle, key, null, localeProvider.getLocale(), arguments);
46         if (text != null) {
47             logger.trace("Translated: {} as {}", key, text);
48             return text;
49         } else {
50             logger.trace("Failed to translate: {}", key);
51             return key;
52         }
53     }
54 }