marcantondahmen / automad

A flat-file content management system and template engine
https://automad.org
MIT License
625 stars 37 forks source link

Multi-language support #64

Open LaserStefan opened 1 year ago

LaserStefan commented 1 year ago

Thanks for this fantastic CMS. However, I would like to reopen the language support issue. The documentation on sessions still lacks a few precise hints on where to put the code.

Can I edit the main theme templates (like light/project) with the two blocks of code (see below)? Will this be reflected in the visual (hero and main) live editor, or can the content then only be changed through hard coding? And how do I ensure that multi-language options appear in the menu?

<@ if @{ ?lang } @> <@ set { %lang: @{ ?lang } } @> <@ end @>

<@ if @{ %lang } = 'de' and @{ textGerman } @> @{ textGerman | markdown } <@ else @> @{ textEnglish | markdown } <@ end @>

LaserStefan commented 1 year ago

Implementing an interactive/a visual mode for the internalisation seems to be too complicated, I've decided to set up two sites with a link to the other in the header. Works fine.

evij-g commented 1 year ago

I think to get a real multi-language support, there should be a global setting, where you define your supported languages. then each Block (text, image, etc.) should reflect these settings and extend its input fields.

here is some example from: https://github.com/marcantondahmen/automad-theme-skeleton/blob/master/session.php

`<@ if @{ %lang } != "de" @> This template illustrates the use of session data to build a multilingual website. Click on a language button below to switch between English and German content or use the language stored in the session data array. Click the "Use Session Setting" button to see that the selected language persits even though there is no "lang" parameter within the URL.

<@ else @>

Dieses Template verdeutlicht die Nutzung von Sessions, um eine multilinguale Website zu erstellen. Klicke auf einen der Buttons unten, um zwischen Englisch und Deutsch zu wechseln, oder die Spracheinstellung aus dem Session Array zu laden. Klicke auf den "Use Session Setting" Button, um zu sehen, dass die ausgewählte Sprache auch angezeigt wird, wenn die URL keinen "lang" Parameter hat.

<@ end @>`

and for example the basic "paragraph"-block: https://github.com/marcantondahmen/automad/blob/v2/automad/src/server/Blocks/Paragraph.php

namespace Automad\Blocks;

use Automad\Core\Automad;

defined('AUTOMAD') or die('Direct access not permitted!');

/**

combined with your approach this could look like this:

class Paragraph extends AbstractBlock { /**

marcantondahmen commented 5 months ago

The second alpha of Automad 2 has been released yesterday. You can enable the new language router in the system settings in order to serve pages based on a vistor's language.