Esempio n. 1
0
def available_language(node, value):
    """Checks that given language is available
    """
    try:
        get_language_title(value)
    except UnknownLocaleError:
        raise Invalid(node,
                      _(u"${lang} is not a valid language",
                        mapping={'lang': value}))
Esempio n. 2
0
def translation_dropdown(context, request):
    languages = api.get_languages(request)
    translations = api.get_translations(context)
    translatable_into = []

    for lang in languages:
        if lang['id'] in translations or lang['id'] == context.language:
            continue
        translated_parent = find_parent(
            context.__parent__,
            lambda item: lang['id'] in api.get_translations(item))
        if translated_parent is None:
            continue
        container = api.get_translations(translated_parent).get(lang['id'])
        url = request.resource_url(
            container,
            'add-translation',
            query={'id': context.id}
        )

        if has_permission('add', container, request):
            translatable_into.append({
                'language': lang['id'],
                'title': lang['title'],
                'url': url
            })
    translations = [
        {
            'language': tr.language,
            'title': api.get_language_title(tr.language),
            'url': request.resource_url(tr),
        } for tr in translations.values()
    ]
    return {
        'translations': translations,
        'translatable_into': translatable_into
    }
Esempio n. 3
0
def test_get_language_title(root):
    from kotti_multilingual.api import get_language_title

    assert get_language_title(u'en') == u'English'