aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/LanguageUtils.java
blob: f0229e785c34079dcb04e0e2b159a1be7cdcf94d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package de.pixart.messenger.utils;

import com.google.common.collect.ImmutableMap;

import java.util.Locale;
import java.util.Map;

public class LanguageUtils {
    private static final Map<String, String> LANGUAGE_MAP;

    static {
        ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
        builder.put("german", "de");
        builder.put("deutsch", "de");
        builder.put("english", "en");
        builder.put("russian", "ru");
        LANGUAGE_MAP = builder.build();
    }

    public static String convert(final String in) {
        if (in == null) {
            return null;
        }
        final String out = LANGUAGE_MAP.get(in.toLowerCase(Locale.US));
        return out == null ? in : out;
    }
}