spanezz / staticsite

Static site generator
GNU General Public License v3.0
45 stars 7 forks source link

Multilanguage support #30

Open spanezz opened 4 years ago

spanezz commented 4 years ago

Ideas for multilanguage support, based on a conversation with @DonKult.

po4a

The text type (Locale::Po4a::Text) has partial markdown support. The support isn't perfect, but was good enough so far to translate a bunch of paragraphs more or less easily.

Maybe it's enough to play with multilanguage staticsite prototypes, and see where they'd lead.

Example invocations:

update-po: Impressum.md
        po4a-updatepo -M utf-8 -f text -o markdown -o tabs=verbatim -m Impressum.md -p po/en.po

translate-files-en: po/en.po
        po4a-translate -M utf-8 -f text -k 0 -o markdown -m Impressum.md -p $^ -l Imprint.md

Serving translated versions

Currently, only explicit interlinking of pages across different languages has been tested.

This bit in an html header would look nice, but it doesn't seem like mainstream browsers currently make use of that:

        {%- if page.meta.hreflang -%}
        <link rel="alternate" hreflang="x-default" href="{{ url_for(page) }}" />
        <link rel="alternate" hreflang="{{ page.meta.content_lang }}" href="{{ url_for(page) }}" />
        {%- for reflang in page.meta.hreflang -%}
        <link rel="alternate" hreflang="{{ reflang[0] }}" href="{{ url_for(reflang[1]) }}" />
        {%- endfor -%}

It's worth looking how lektor does it, since it claim multilingual support.

For convenience, two links to doing language content negotiation with apache and nginx:

Setting current locale

Generating site pages for one language would also require a setlocale call to generate things like dates correctly. See #22

spanezz commented 4 years ago

Lektor's documentation for multilingual support is here.

From what I have seen as a quick glance:

Content-wise, in lektor one needs to manually provide one copy of each page per language, and I haven't seen any support for potfile and the like.

I'd like, if possible, at least some content negotiation, then keep one file per page, and use potfiles to help with translations.

spanezz commented 4 years ago

Hugo has a few more multilingual features, including supporting different SITE_URL per language