Exemple #1
0
def contact_information(info):
    """
    produce label, value pairs from contact info
    """
    try:
        return json.loads(info)[h.lang()]
    except Exception:
        return {}
Exemple #2
0
def contact_information(info):
    """
    produce label, value pairs from contact info
    """
    try:
        return json.loads(info)[h.lang()]
    except Exception:
        return {}
Exemple #3
0
def get_translated_t(data_dict, field):
    '''
    customized version of core get_translated helper that also looks
    for machine translated values (e.g. en-t-fr and fr-t-en)

    Returns translated_text, is_machine_translated (True/False)
    '''
    language = h.lang()
    try:
        return data_dict[field + '_translated'][language], False
    except KeyError:
        if field + '_translated' in data_dict:
            for l in data_dict[field + '_translated']:
                if l.startswith(language + '-t-'):
                    return data_dict[field + '_translated'][l], True
        val = data_dict.get(field, '')
        return (_(val) if val and isinstance(val, basestring) else val), False
Exemple #4
0
def get_translated_t(data_dict, field):
    '''
    customized version of core get_translated helper that also looks
    for machine translated values (e.g. en-t-fr and fr-t-en)

    Returns translated_text, is_machine_translated (True/False)
    '''

    language = h.lang()
    try:
        return data_dict[field+'_translated'][language], False
    except KeyError:
        if field+'_translated' in data_dict:
            for l in data_dict[field+'_translated']:
                if l.startswith(language + '-t-'):
                    return data_dict[field+'_translated'][l], True
        val = data_dict.get(field, '')
        return (_(val) if val and isinstance(val, basestring) else val), False
Exemple #5
0
def language_text_t(text, prefer_lang=None):
    '''
    customized version of scheming_language_text helper that also looks
    for machine translated values (e.g. en-t-fr and fr-t-en)

    Returns translated_text, is_machine_translated (True/False)
    '''
    if not text:
        return u'', False

    assert text != {}
    if hasattr(text, 'get'):
        try:
            if prefer_lang is None:
                prefer_lang = h.lang()
        except TypeError:
            pass  # lang() call will fail when no user language available
        else:
            try:
                return text[prefer_lang], False
            except KeyError:
                for l in text:
                    if l.startswith(prefer_lang + '-t-'):
                        return text[l], True
                pass

        default_locale = config.get('ckan.locale_default', 'en')
        try:
            return text[default_locale], False
        except KeyError:
            pass

        l, v = sorted(text.items())[0]
        return v, False

    t = gettext(text)
    if isinstance(t, str):
        return t.decode('utf-8'), False
    return t, False
Exemple #6
0
def language_text_t(text, prefer_lang=None):
    '''
    customized version of scheming_language_text helper that also looks
    for machine translated values (e.g. en-t-fr and fr-t-en)

    Returns translated_text, is_machine_translated (True/False)
    '''
    if not text:
        return u'', False

    assert text != {}
    if hasattr(text, 'get'):
        try:
            if prefer_lang is None:
                prefer_lang = h.lang()
        except TypeError:
            pass  # lang() call will fail when no user language available
        else:
            try:
                return text[prefer_lang], False
            except KeyError:
                for l in text:
                    if l.startswith(prefer_lang + '-t-'):
                        return text[l], True
                pass

        default_locale = config.get('ckan.locale_default', 'en')
        try:
            return text[default_locale], False
        except KeyError:
            pass

        l, v = sorted(text.items())[0]
        return v, False

    t = gettext(text)
    if isinstance(t, str):
        return t.decode('utf-8'), False
    return t, False
Exemple #7
0
def dataset_comments(pkg_id):
    if config.get('ckanext.canada.drupal_url'):
        return '/' + h.lang() + '/external-entity/ckan-' + pkg_id + '?_wrapper_format=ajax'
def lang():
    # access this function late in case ckan
    # is not set up fully when importing this module
    from ckantoolkit import h
    return h.lang()
Exemple #9
0
def adobe_analytics_lang():
    if h.lang() == 'en':
        return 'eng'
    elif h.lang() == 'fr':
        return 'fra'
Exemple #10
0
def lang():
    # access this function late in case ckan
    # is not set up fully when importing this module
    from ckantoolkit import h
    return h.lang()
def user_language():
    try:
        from ckantoolkit import h
        return h.lang()
    except TypeError:
        return None  # lang() call will fail when no user language available
Exemple #12
0
def dataset_comments_obd(pkg_id):
    if config.get('ckanext.canada.drupal_url'):
        return '/' + h.lang() + '/external-entity/ckan_obd-' + pkg_id + '?_wrapper_format=ajax'
def localized_date(date_string):
    d = datetime.strptime(date_string, '%Y%m%d')

    return format_date(d, format='long', locale=h.lang())
Exemple #14
0
def portal_url():
    url = PORTAL_URL_DEFAULT_FR if h.lang() == 'fr' else PORTAL_URL_DEFAULT_EN
    return str(config.get(PORTAL_URL_OPTION, url))
Exemple #15
0
 def lang(self):
     from ckantoolkit import h
     return h.lang()