]> git.basschouten.com Git - openhab-addons.git/blob
ebe51b78359ce3beff1658d051d47e18bbb0540d
[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.knx.internal.i18n;
14
15 import static java.util.Map.entry;
16
17 import java.text.MessageFormat;
18 import java.util.Locale;
19 import java.util.Map;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.core.i18n.TranslationProvider;
24 import org.osgi.framework.Bundle;
25
26 /**
27  * Translation provider for unit tests.
28  *
29  * @author Jacob Laursen - Initial contribution
30  * @author Holger Friedrich - Imported from hdpowerview, adapted
31  */
32 @NonNullByDefault
33 public class MockedTranslationProvider implements TranslationProvider {
34
35     private static final Map<String, String> TEXTS = Map.ofEntries(entry("binding.knx.name", "KNX Binding"),
36             entry("error.knx-unknown-ip-connection-type", "Unknown IP connection type: {0}."),
37             entry("exception.KNXException", "Translated KNX Exception"));
38
39     public MockedTranslationProvider() {
40     }
41
42     @Nullable
43     public String getText(@Nullable Bundle bundle, @Nullable String key, @Nullable String defaultText,
44             @Nullable Locale locale) {
45         return "";
46     }
47
48     @Nullable
49     public String getText(@Nullable Bundle bundle, @Nullable String key, @Nullable String defaultText,
50             @Nullable Locale locale, @Nullable Object @Nullable... arguments) {
51         String text = TEXTS.get(key);
52         return MessageFormat.format(text != null ? text : key, arguments);
53     }
54 }