(msg_id, verified_number=None, context=None, domain=None, language=None)
return msg
Translates the message according to the user's and domain's preferences.

    msg_id - one of the MSG_* constants above
    verified_number - pass in the PhoneNumber of a contact in order to
                      use this contact's domain and language to translate
    context - some messages require additional parameters; pass them as a
              tuple or list
    domain - if the contact doesn't have a verified number, pass the domain
             in here to use this domain's translation doc
    language - if the contact doesn't have a verified number, pass the language
               code in here to use this language
Translates the message according to the user's and domain's preferences.
Translates the message according to the user s and domain s preferences .
def get_message(msg_id, verified_number=None, context=None, domain=None, language=None):
    """
    Translates the message according to the user's and domain's preferences.

    msg_id - one of the MSG_* constants above
    verified_number - pass in the PhoneNumber of a contact in order to
                      use this contact's domain and language to translate
    context - some messages require additional parameters; pass them as a
              tuple or list
    domain - if the contact doesn't have a verified number, pass the domain
             in here to use this domain's translation doc
    language - if the contact doesn't have a verified number, pass the language
               code in here to use this language
    """
    default_msg = _MESSAGES.get(msg_id, "")

    if domain:
        translations = SMSTranslations.objects.filter(domain=domain).first()
    elif verified_number:
        translations = SMSTranslations.objects.filter(domain=verified_number.domain).first()
    else:
        translations = None

    if language:
        user_lang = language
    else:
        try:
            user_lang = verified_number.owner.get_language_code()
        except:
            user_lang = None

    def get_translation(lang):
        return translations.translations.get(lang, {}).get(msg_id, None)

    def domain_msg_user_lang():
        if translations and user_lang in translations.langs:
            return get_translation(user_lang)
        else:
            return None

    def domain_msg_domain_lang():
        if translations and translations.default_lang:
            return get_translation(translations.default_lang)
        else:
            return None

    def global_msg_user_lang():
        result = None
        if user_lang:
            with localize(user_lang):
                result = _(default_msg)
        return result if result != default_msg else None

    def global_msg_domain_lang():
        result = None
        if translations and translations.default_lang:
            with localize(translations.default_lang):
                result = _(default_msg)
        return result if result != default_msg else None

    msg = (
        domain_msg_user_lang() or
        domain_msg_domain_lang() or
        global_msg_user_lang() or
        global_msg_domain_lang() or
        default_msg
    )

    if context:
        msg = msg.format(*context)

    return msg
def get_message ( msg_id , verified_number = None , context = None , domain = None , language = None ) : default_msg = _MESSAGES . get ( msg_id , "" ) if domain : translations = SMSTranslations . objects . filter ( domain = domain ) . first ( ) elif verified_number : translations = SMSTranslations . objects . filter ( domain = verified_number . domain ) . first ( ) else : translations = None if language : user_lang = language else : try : user_lang = verified_number . owner . get_language_code ( ) except : user_lang = None def get_translation ( lang ) : return translations . translations . get ( lang , { } ) . get ( msg_id , None ) def domain_msg_user_lang ( ) : if translations and user_lang in translations . langs : return get_translation ( user_lang ) else : return None def domain_msg_domain_lang ( ) : if translations and translations . default_lang : return get_translation ( translations . default_lang ) else : return None def global_msg_user_lang ( ) : result = None if user_lang : with localize ( user_lang ) : result = _ ( default_msg ) return result if result != default_msg else None def global_msg_domain_lang ( ) : result = None if translations and translations . default_lang : with localize ( translations . default_lang ) : result = _ ( default_msg ) return result if result != default_msg else None msg = ( domain_msg_user_lang ( ) or domain_msg_domain_lang ( ) or global_msg_user_lang ( ) or global_msg_domain_lang ( ) or default_msg ) if context : msg = msg . format ( * context ) return msg