Serve different downloads on multi language site


I got a bilingual page (german and english) and some PDF downloads that are listed with this snippet

<div class="filelist-content">
        <?php foreach($page->files() as $f) : ?>
            <div class="file">
                <div class="left-column">
                    <a title="<?php l::get('download_file') ?>" href="<?php echo $site->url().'/get/'.$f->filename() ?>" target="_blank">
                        <h2 id="<?php echo $f->name() ?>"><?php e($f->title()->empty(), $f->filename(), $f->title()->kirbytextRaw()); ?></h2>
                        <p class="file-info">
                            <?php e(!$f->title()->empty(), $f->filename().'<br>') ?>
                            <span class="filesize"><?php echo $f->niceSize(); ?></span><br>
                <div class="right-column">
                    <?php echo $f->description()->kt(); ?>
            <div class="clear-fix"></div>
        <?php endforeach ?>

I.e. all files in the page folder are listed and the description is fetched from the file.pdf.en.txt or Now I want to who only some files depending on the current language or different versions like and file.en.pdf. Is there a built in way to do this?

If theres no build in way I guess I could create a custom filter but I don’t know how … so any help on that will be appreciated too!

You could filter by string contained in the file name with a custom filter, see this thread

Thanks! Actually I already found this thread but wanted to wait if there’s a built in way which is not the case as I conclude from your answer …

Is it possible to make this filter “global” so I can say filterBy('language') and it automatically detects the current language? It would be perfect if the filter works like this:

FILE                  DE   EN
------------------------------       X
example1.en.pdf            X
example2.en.pdf            X
example3.pdf          X    X       X
example4.en.pdf            X
COLL. OF … FILES      3    4

I’m too tired, I think you don’t even need a custom filter, you can simply do sth like this (no tested though)

$files = $page->files()->filterBy('filename', '*=', $site->language()->code());

The custom filter is only necessary if you want to achieve the opposite, i.e. filter by files that do not contain a specific string.

Thanks, but this won’t cover the case where a single file (example3.pdf) should be available to all languages …

True, I missed that, but all you need is add an or condition

How can I add an or condition? And how should I code the condition “has no language suffix”?

(In the mean time I decided another way to go fur my current project, but it would be interesting to know how this works, though …)