Multi-lang site with documents

Hi all,

I have a site that has documents (PDFs) that need to be linked to depending on which language is selected. I’ve searched around but I can’t find anyone with a similar issue. Can anyone think of an elegant solution before I hard-code some hack-y string concatenation in?

Thanks :tophat:

Hi @broskoski,

do you mean on the frontend? Possibilities:

  • if the filename contains a language string, you could filter by that
  • use meta data to assign the language to the file, then filter by that
  • store the files in different subfolders of a page
  • use a multi-select or structure field to select the files that belong to a language version
1 Like

@texnixe just following up here (and I forgot to say thank you!)

I’m doing this:

<? if($site()->language()->code() === 'en'): ?>
  <?php $pr = $page->documents()->findBy('press_release', true) ?>
<? else: ?>
  <?php $lang = $site()->language()->code() ?>
  <?php $pr = $page->documents()->findBy('press_release_' + $lang, true) ?>
<? endif; ?>

but it seems that findBy always returns the first result no matter what. My blueprint looks like:

press_release:
  label: Press Release
  type: checkbox
  text: Is this the English press release?
press_release_cn:
  label: Press Release
  type: checkbox
  text: Is this the Chinese press release?
press_release_es:
  label: Press Release
  type: checkbox
  text: Is this the Spanish press release?

Thank you!

Yes, findBy() only finds the first element. Use filterBy() instead.

I wonder if using 3 different checkboxes is really the best solution.

Why not use a select field instead:

pr_language:
  label: Select language of this press release
  type: select
  options:
    en: English
    cn: Chinese
    es: Spanish

Then in template:

<?php 
$lang = $site->language()->code();
$pr   = $page->documents()->findBy('pr_language', $lang);
?>