Android Language Get toLanguageTag(Locale locale)

Here you can find the source of toLanguageTag(Locale locale)

Description

to Language Tag

License

Open Source License

Declaration

public static String toLanguageTag(Locale locale) 

Method Source Code

//package com.java2s;
/* /*  w ww  .j  a  va  2  s .co  m*/
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

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);
    }
}

Related

  1. languagePrefix()
  2. defaultLanguageCode()
  3. languageByIntCode(int languageCode, int subLanguageCode)
  4. languageByCode(int languageCode, int subLanguageCode)
  5. getCurrentLanguage()