Only show entries if they are in the correct language

languages

#1

Hi there,
I have a site that I am creating a German version of, and I wondered if there is a way to show only entries that have a translation?

The purpose of this is there is an events page, some will be in the UK (which I want to show on the UK site) and some in Germany (which I only want to show on the German site).

To be honest, throughout the site there’s areas where some content is relevant only to one site, so if there’s something universal I can do to only show content that is in the right language, that would be very useful.

Thanks in advance for your help!
Rach


#2

This is a bit tricky, because if you use the Panel, a content file in the default language is always created.

A pages method like this:

pages::$methods['onlyTranslated'] = function($pages) {
  return $pages->filter(function($page) {
    return $page->content(site()->language()->code())->exists();
  });
};

only works for the non-default pages.

One way to get around this issue, it to use a field you could filter by. You could then create a custom pages method that filters by this field. Or without custom field, check if the content is the same.

Another is to use the translation plugin by @flokosiol.


#3

Thank you very much for your help! I’ll have a look at the plugin but I suspect I will end up using a field.
Thanks,
Rach