Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation #419

Open
zkostadinov opened this issue Jan 1, 2021 · 5 comments
Open

Translation #419

zkostadinov opened this issue Jan 1, 2021 · 5 comments

Comments

@zkostadinov
Copy link

zkostadinov commented Jan 1, 2021

Hello dear all

This is kind of a feature request, but I am afraid I am not able to fully specify it, yet...

I would like to have my gallery supporting two languages. More precisely, if I want to have Russian language for example, I would like to be able to have in my index.md files values like:

title = My album
title_ru = Мой албум

I imagine for every album there would be a file index.html and also index_ru.html
I do not imagine yet how to enable switching the displayed language... Any idea would be appreciated.

@zkostadinov
Copy link
Author

zkostadinov commented Jan 1, 2021

I am a Python developer myself, so I assume I would be able to contribute to the project, but I would like to have a better understanding of what is the best approach to take.

@zkostadinov
Copy link
Author

zkostadinov commented Jan 13, 2021

I would like to be able to have in my index.md files values like:

title: My album
title_ru: Мой албум

I was able to translate my whole project this way, apart from the breadcrumb, for which I had to add a new property like this:

def breadcrumb_albums(album: Album):
    """
    Builds a breadcrumb list of (url, album_info) for the underlying album
    """
    if album.path == '.':
        return []

    path = album.path
    breadcrumb = [((album.url_ext or '.'), album)]

    while True:
        path = os.path.normpath(os.path.join(path, '..'))
        if path == '.':
            break

        url = (url_from_path(os.path.relpath(path, album.path)) + '/' + album.url_ext)
        breadcrumb.append((url, album.gallery.albums[path]))

    breadcrumb.reverse()
    return breadcrumb


def build_sigal():
    Album.breadcrumb_albums = property(breadcrumb_albums)
    gallery = Gallery(conf)
    gallery.build()

So I basically add a breadcrumb_albums property that is like the original breadcrumb one, but contains the actual Album objects instead of their titles, and later in the template I read it like this:

        {% for url, parent in album.breadcrumb_albums %}
        <a class="breadcrumb-link" href="{{ url }}">
            <span class="translation translation-ru"> / {{ parent.title }}</span>
            <span class="translation translation-en"> / {{ parent.meta.title_en | first }} </span>
        </a>
        {% endfor %}

I hope this helps anyone else that would like to have his gallery translated

@saimn
Copy link
Owner

saimn commented Jan 15, 2021

Glad that you found a solution. I'm not sure exactly what should be done in sigal to support this better. It might be interesting to look at other projects like pelican, which has been a great inspiration when I started sigal.

@zkostadinov
Copy link
Author

I'm not sure exactly what should be done in sigal to support this better.

Well, I would say sigal almost supports in-browser translations already through the Jinja templates. The only thing I had to do is to create this breadcrumb_albums property. It fits well in my project, as it has a small python script anyway, but for non-programmers maybe would be nice to have a solution for the breadcrumb. Personally I am not positive what would be best - having the Album.breadcrumb changed to contain the actual albums or introducing a new property like Album.breadcrumb_albums. But if you find it useful, it looks like a small change that people may benefit from in the future.

@saimn
Copy link
Owner

saimn commented Jan 17, 2021

Yes, passing the album object directly to the template seems a useful change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants