Dynamic collections / adding an item into the collection

I’m dealing with multilingual site and translations for a while. Found there is no language filter for the collection and untranslated pages are showing in its original language. I want to display translated articles only.

The way creating and disabling page in another languages is not a way (3lang and thousands of pages).
Showing a collection and specifying particular language will brake pagination plugin.

Think I’ve found is looping through the collection, selecting page language. But now how to create and dynamically add an item into the collection in the twig?

I was playing with merge (only for arrays?), add, addpage nothing worked for me.

Checked the API documentation, there are functions ready, but not sure if they are exposed to twig. Any ideas?

Or any other solution how to deal with multilang and non-translated articles?


Can you post some more details? Maybe snippets of Twig code you tried but didn’t work?

@ondrejv, Maybe the solution provided by @Netzhexe could of any help:

Still relevant: filter a page collection by language

Tried solution mentioned - and even using now. the “problem” it is - it breaks the pagination plugin. The collection contains all languages, but displaying particular lang decreases the number of articles in the collection, pagination can’t work correctly. Article display is ok.

My idea was something like this:
{% set collection = page.collection() %} <<< collection of all articles

{% for child in collection if child.language == html_lang %} <<< filter out lang specific articles
{% set lang_collection.addPage(child) %} <<< part of the API, not in twig (?)
{% endfor %}
{% for page in lang_collection %}
{{ page.content|raw }}
{% endfor %}

{% include ‘partials/pagination.html.twig’ with {‘base_url’: page.url, ‘pagination’: lang_collection.params.pagination} %} <<< display pagination for the new language specific collection

here is the API function to add the page into the collection https://learn.getgrav.org/16/api#class-grav-common-page-collection

this was just an idea of how to work around language collections, the downside is the performance because of the other extra loop. But I was playing with Grav 1.7, where the language functionality is present and work great - so I’ll wait for the 1.7 version rather tweaking 1.6