Skip to content

Multi-language / translations #12

@danburzo

Description

@danburzo

Marcel needs to be built with multi-language websites in mind. Some things that need to be translated:

  • the website's content
  • strings in templates
  • date formats
  • what else?

Configuring languages

In marcel.config.js:

languages: ['en', 'ro'],
defaultLanguage: 'ro'

Translating content

Translations of content are linked together by sharing the same file name and location in the content folder. They are distinguished by separate language suffixes.

content
  - my-post.ro.md
  - my-post.en.md

These two refer to the same post. The language code suffix is ignored when generating the slug.

What if one of the languages needs a different slug? It can be overriden in the post's front matter (the slug property).

Generating permalinks for content

One idea from WordPress-land is to have urls in the form:

http://mysite.com/posts/my-post
http://mysite.com/en/posts/my-post-in-english

That is, the defaultLanguage does not include the language code in the URL, while others do.

Note: It should be possible to override the permalink scheme for multi-language content.

Translating strings

This will probably require two things:

  • a dictionary (keep separate files in a language folder?)
  • a filter in the nunjucks templates

How does the filter look?

<a href='#next'>{{ "Next" | translate }}</a>

If no string is found in the dictionary for the current language, the string is rendered as-is.

Links to translated content

The templates should have access to a languages object that contains an array of all available languages.

Should the post object be augmented with a translations property that holds the equivalent posts? (Full objects, so you have access to title, content, permalink etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    brainstormingDiscussing ideas around a concept and its implementation↑↑↑Priority: Essential

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions