# How to avoid automatic fallback for translations

**URL:** <https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 28, 2015, 9:24pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705 "2015-07-28T21:24:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamvdo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iamvdo/32/783_2.png) [@iamvdo](https://forum.getkirby.com/u/iamvdo)\
**Post date:** [July 28, 2015, 9:24pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/1 "2015-07-28T21:24:40Z")

</div>

Hey there.

I’ve a 2-lang website (FR and EN), the majority is in FR without translations. I don’t want that Kirby automatically shows FR articles when in EN.  
I can’t find any method to get available languages of a page. Is there ?

I find this [Find() page in specific language](http://forum.getkirby.com/t/find-page-in-specific-language/434) but

`$page->content('en')`

always returns true, even if only FR translation file is present.

`$page->language()`

is not documented and returns … nothing.

How am I supposed to do that ?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 28, 2015, 9:58pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/2 "2015-07-28T21:58:08Z")

</div>

You can check if content is available like this:

```php
 <?php if(site()->language()->code() == $page->language()->code()) { 
//do stuff, e.g.
echo $page->title() ;} 
?>

```

To filter articles based on available languages, you can use a custom filter:

```php
$articles = $page->children()->visible()->filter(function($child) {
     return site()->language()->code() == $child->language()->code();
});

```

This will only work for Kirby 2, btw. almost all solutions in this forum relate to Kirby 2.

---

<div class="post-metadata">

**Author:** ![iamvdo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iamvdo/32/783_2.png) [@iamvdo](https://forum.getkirby.com/u/iamvdo)\
**Post date:** [July 28, 2015, 10:06pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/3 "2015-07-28T22:06:01Z")

</div>

Yes, I am in Kirby 2. 😄  
But,

```
$page->language()->code()

```

doesn’t work. Always return empty string.

---

<div class="post-metadata">

**Author:** ![iamvdo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iamvdo/32/783_2.png) [@iamvdo](https://forum.getkirby.com/u/iamvdo)\
**Post date:** [July 28, 2015, 10:28pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/4 "2015-07-28T22:28:09Z")

</div>

I noticed that with Kirby 1, this method used to work: [https://www.texniq.de/en/texniq-u/kirby-multilingual-site](https://www.texniq.de/en/texniq-u/kirby-multilingual-site)

Something like:

```
$currentLang = c::get('lang.current');
if ($page->content($currentLang)) {
    // do stuff
}
```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 29, 2015, 6:12am UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/5 "2015-07-29T06:12:01Z")

</div>

Yes, you are right, `$page->language()->code()` does not work anymore, but

```php
<?php echo $page->content()->language()->code() ?>

```

does. I guess this was changed, because in an older installation, the first bit of code does in fact still work.

---

<div class="post-metadata">

**Author:** ![iamvdo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iamvdo/32/783_2.png) [@iamvdo](https://forum.getkirby.com/u/iamvdo)\
**Post date:** [July 29, 2015, 6:35am UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/6 "2015-07-29T06:35:12Z")

</div>

Thanks, but I get this error:

```
Fatal error: Call to a member function code() on boolean

```

However `$page->content()->language()` seems to work, but only on translated article and returns an empty string in other cases. I would expect to return the default lang?

I suppose I could deal with that though…

---

<div class="post-metadata">

**Author:** ![iamvdo](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/iamvdo/32/783_2.png) [@iamvdo](https://forum.getkirby.com/u/iamvdo)\
**Post date:** [July 29, 2015, 7:47am UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/7 "2015-07-29T07:47:24Z")

</div>

I managed to do it. Something like:

```
// get own language of page
$ownLang = $child->content()->language();
// if empty string, use default language
if ($ownLang == '') {
    $ownLang = $site->defaultLanguage()->code();
}
// page doesn't exist in current language
if ( $site->language()->code() != $ownLang ) {
    // do stuff
}

```

Thanks @texnixe. 😉

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:16pm UTC](https://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705/8 "2025-02-06T17:16:59Z")

</div>


