]> git.basschouten.com Git - openhab-addons.git/blob
48e14c7ec797f7f0c37255f7e9eedeb28150b5a4
[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.mielecloud.internal.util;
14
15 import java.util.Locale;
16 import java.util.MissingResourceException;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Utility for validating locales.
22  *
23  * @author Björn Lange - Initial Contribution
24  */
25 @NonNullByDefault
26 public final class LocaleValidator {
27     private LocaleValidator() {
28         throw new UnsupportedOperationException();
29     }
30
31     /**
32      * Checks whether the given string is a valid two letter language code.
33      *
34      * @param language The string to check.
35      * @return Whether it is a valid language.
36      */
37     public static boolean isValidLanguage(String language) {
38         try {
39             String iso3Language = new Locale(language).getISO3Language();
40             return iso3Language != null && !iso3Language.isEmpty();
41         } catch (MissingResourceException e) {
42             return false;
43         }
44     }
45 }