Ejemplo n.º 1
0
def langfiles_for_path(path):
    """
    Find and return any extra lang files specified in templates or python
    source files, or the first entry in the DOTLANG_FILES setting if none.

    :param path: path to a file containing strings to translate
    :return: list of langfile names.
    """
    lang_files = None

    if is_template(path):
        # If the template explicitly specifies lang files, use those
        lang_files = parse_template(join(settings.ROOT, path))
        # Otherwise, normalize the path name to a lang file
        if not lang_files:
            lang_files = [get_l10n_path(path)]
    elif is_python(path):
        # If the python file explicitly specifies lang files, use those
        lang_files = parse_python(join(settings.ROOT, path))

    if not lang_files:
        # All other sources use the first main file
        lang_files = settings.DOTLANG_FILES[:1]

    return lang_files
Ejemplo n.º 2
0
def _get_template_tag_set(lang, path):
    lang_files = [get_l10n_path(path)]
    template = get_template(path)
    lang_files.extend(parse_template(template.template.filename))
    tag_set = set()
    for lf in lang_files:
        tag_set |= lang_file_tag_set(lf, lang)
    return tag_set
Ejemplo n.º 3
0
def translations_for_template(template_name):
    """
    Return the list of available translations for the template.

    :param template_name: name of the template passed to render.
    :return: list, like ['en-US', 'fr']
    """
    lang_files = [get_l10n_path(template_name)]
    template = get_template(template_name)
    lang_files.extend(parse_template(template.template.filename))
    active_translations = []
    for lf in lang_files:
        active_translations.extend(get_translations_for_langfile(lf))

    return active_translations
Ejemplo n.º 4
0
def test_get_l10n_path():
    assert get_l10n_path('/apps/foo/templates/foo/bar.html') == 'foo/bar'
    assert get_l10n_path('/templates/foo.html') == 'foo'
    assert get_l10n_path('/foo/bar.html') == 'foo/bar'
Ejemplo n.º 5
0
def test_get_l10n_path():
    assert get_l10n_path("/apps/foo/templates/foo/bar.html") == "foo/bar"
    assert get_l10n_path("/templates/foo.html") == "foo"
    assert get_l10n_path("/foo/bar.html") == "foo/bar"