Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Locale; public class Main { public static String toLanguageTag(Locale locale) { StringBuilder languageTag = new StringBuilder(); languageTag.append(locale.getLanguage()); if (!isNullOrEmpty(locale.getCountry())) { languageTag.append('-').append(locale.getCountry()); } if (!isNullOrEmpty(locale.getVariant())) { languageTag.append('-').append(locale.getVariant()); } return languageTag.toString(); } public static boolean isNullOrEmpty(String val) { return (val == null || val.length() == 0); } }