def get_primary_language(lang):
    """
    A language code may come in two parts as per ISO 639-1. For the case of
    pt-BR, the first part would be the primary language (pt) and the second
    one, the country code. This function retruns the primary language part of
    the language code.

    """
    if len(lang) <= 2:          # Already only the primary language
        return lang
    else:
        # lang is something like pt-BR
        # Split the lang code into two parts (pt, BR)
        # And return the first part (pt)
        return lang.\
            split("-")\
            [0]