Multilanguage Website with Contexts and Contentblocks

Hi there,
I’ve done a few multilingual websites in the past. In general, each language is a context, connected via Babel, and a router plugin redirects to that context based on the domain. The content is organised into Resources and ContentBlocks. This works well.

Let me give you an example: I have a site in four languages (de, en, fr, cz). Each language is a Context (de, en, fr, cz). Each language can have a different site structure based on the resource tree. So I start creating a new resource, define the structure via ContentBlocks (different elements and layouts for a landing page) and fill in the first language (de). Then I duplicate it for all the other languages and replace the text with the translation. Weeks later I have to change the layout (move some content). So I have to do this four times for each resource. Here I had to rethink the problem.

One idea was to add setting fields for each language on each element (default is [[+value]], so add a setting [[+value_en]] for english and so on). In the chunk I can output it like [[+value[[+lang:before=_]]]]). So the german resource is the main resource that holds all the translations. The connected resources need to output the content from the main resource [[#[[+babel_main_id]].content]] (via FastField tags or something). This might work, but adding another translation is a lot to extend.

Another idea is to use BabelTranslate from @jako and CopyContent from @seda.digital to automate the translation. This is good on first creation, but when making changes this get overriden on automatic translation.

I think I heard that ContentBlocks 2.0 could be a game changer for this @markh?

Does anyone have another solution to avoid multiple changes when using contexts for languages and ContentBlocks?

I don’t think there are any good solutions for this with the current version of ContentBlocks. (I don’t know anything about ContentBlocks 2.0.)

ContentBlocks stores the block structure together with the data directly in the resource (db-table modx_site_content → column “property”).
For your use case, you need a block structure, that is uncoupled from the actual block values, so it can be reused in multiple resources.


You could theoretically add a plugin, that tries to detect changes to the block structure (on the events OnBeforeDocFormSave, OnDocFormSave, maybe ContentBlocks_RenderContent) and replicate the changes to other resources.

But I guess that would be quite hard to properly implement. As far as I can tell the blocks don’t have a unique ID, so I don’t think all changes can be detected.
The format ContentBlocks uses is also quite complicated to directly interact with. (For example everything is stored twice in the JSON, once in “content” and once in “linear”.)


Maybe another extra would be better for this use case.
PageBlocks seems to have “multilingual blocks”. But I have never used PageBlocks, so I can’t say if it would work.

hej @halftrainedharry,
thanks for your great input!

I post another Idea above: Another idea is to use BabelTranslate from @jako and CopyContent from @seda.digital to automate the translation. This is good on first creation, but when making changes this get overriden on automatic translation.

You could theoretically add a plugin …

Thats an interesting idea, but modifing the ContentBlocks JSON is complicated as i know.

Maybe another extra would be better for this use case.
PageBlocks seems to have “multilingual blocks”. But I have never used PageBlocks , so I can’t say if it would work.

Oh, maybe i give this a try. But it looks not so nice like the Backend with ContentBlocks (elements in layouts).