automad
automad copied to clipboard
Multi-language support
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 @>
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.
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!');
/**
- The paragraph block.
- @author Marc Anton Dahmen
- @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de
- @license MIT license - https://automad.org/license
/
class Paragraph extends AbstractBlock {
/*
-
Render a paragraph block.
-
@param object $data
-
@param Automad $Automad
-
@return string the rendered HTML */ public static function render(object $data, Automad $Automad) { $classes = array(); $text = htmlspecialchars_decode($data->text);
if (!empty($data->large)) { $classes[] = 'am-paragraph-large'; }
if (!empty($data->alignment)) { if ($data->alignment == 'center') { $classes[] = 'am-center'; } }
$class = self::classAttr($classes);
return "<p $class>$text
"; } }
-
combined with your approach this could look like this:
class Paragraph extends AbstractBlock {
/**
* Render a paragraph block.
*
* @param object $data
* @param Automad $Automad
* @return string the rendered HTML
*/
public static function render(object $data, Automad $Automad) {
$classes = array();
$text = htmlspecialchars_decode($data->text);
if (!empty($data->large)) {
$classes[] = 'am-paragraph-large';
}
if (!empty($data->alignment)) {
if ($data->alignment == 'center') {
$classes[] = 'am-center';
}
}
$class = self::classAttr($classes);
return "<p $class>
<@ if @{ %lang } = 'de' and @{ textGerman } @> @{ textGerman | markdown }
<@ else @> @{ textEnglish | markdown } <@ end @>
</p>";
}
}
then somewhere where the input field is being generated, there should be a query where additional fields are generated for all specified languages in the multi-language variable.
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.