# Translation and config.php Bug?

**URL:** <https://forum.getkirby.com/t/translation-and-config-php-bug/6467>\
**Category:** Questions\
**Tags:** v2\
**Created:** [January 30, 2017, 4:48pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467 "2017-01-30T16:48:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gillesvauvarin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/gillesvauvarin/32/2351_2.png) [@gillesvauvarin](https://forum.getkirby.com/u/gillesvauvarin)\
**Post date:** [January 30, 2017, 4:48pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/1 "2017-01-30T16:48:26Z")

</div>

Hello,

In an option page, I’ve set a select field to let the user choose the language by default between ‘en’ and ‘fr’.

I get this value in my config file to set the default language.

This is the code in the config.php file but I’ve got a blank page on the front.

```auto
$language = 'en';
$languages = array();

$language = site()->generalOptionslanguage()->value();
//$language = 'fr';

switch ( $language ) {
  case 'en':
    $languages = array(
      array(
        'code' => 'en',
        'name' => 'English',
        'default' => true,
        'locale' => 'en_EN',
        'url' => '/',
      ),
      array(
        'code' => 'fr',
        'name' => 'French',
        'default' => false,
        'locale' => 'fr_FR',
        'url' => '/fr',
      ),
    );
    break;

  case 'fr':
    $languages = array(
      array(
        'code' => 'en',
        'name' => 'English',
        'default' => false,
        'locale' => 'en_EN',
        'url' => '/en',
      ),
      array(
        'code' => 'fr',
        'name' => 'French',
        'default' => true,
        'locale' => 'fr_FR',
        'url' => '/',
      ),
    );
    break;
  
}

c::set( 'languages' , $languages );

```

If I comment the line:

```auto
$language = site()->generalOptionslanguage()->value();

```

… and replace it by:

```auto
$language = 'fr';

```

It works fine.

I’ve var\_dump the line “site()-\>generalOptionslanguage()-\>value();” and it return ‘fr’ or ‘en’ as expected.

Is it a bug?

---

<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:** [January 30, 2017, 6:27pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/2 "2017-01-30T18:27:06Z")

</div>

Hm, I think you need to set the languages first. You could then try to change the default language depending on the value of the site setting.

Edit: I’m not so sure this is intended usage. If in doubt, you could file an issue on GitHub.

---

<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:** [April 9, 2017, 4:53pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/3 "2017-04-09T16:53:53Z")

</div>

It seems that this code `$language = site()->generalOptionslanguage()->value();` only gets the value from the default language. So you would have to define the default language first.

The multi-language features are only available after the configuration, extensions, plugins and the router have been loaded.

---

<div class="post-metadata">

**Author:** ![gillesvauvarin](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/gillesvauvarin/32/2351_2.png) [@gillesvauvarin](https://forum.getkirby.com/u/gillesvauvarin)\
**Post date:** [April 11, 2017, 7:06am UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/4 "2017-04-11T07:06:17Z")

</div>

I tried to define the default language first and then get the site option value:

```auto
$default_language = array(
				array(
			        'code' => 'fr',
			        'name' => 'French',
			        'default' => true,
			        'locale' => 'fr_FR',
			        'url' => '/',
				),
				array(
					'code' => 'en',
					'name' => 'English',
					'locale' => 'en_EN',
					'url' => '/en',
				),
			      
			);

c::set( 'languages' , $default_language );

$default_language = kirby()->site()->generalOptionslanguage()->value()';

switch ( $default_language ) {

  case 'en':
    $languages = array(
			      array(
			        'code' => 'en',
			        'name' => 'English',
			        'default' => true,
			        'locale' => 'en_EN',
			        'url' => '/',
			      ),
			      array(
			        'code' => 'fr',
			        'name' => 'French',
			        'locale' => 'fr_FR',
			        'url' => '/fr',
			      ),
			    );
  break;

  case 'fr':
    array(
				array(
			        'code' => 'fr',
			        'name' => 'French',
			        'default' => true,
			        'locale' => 'fr_FR',
			        'url' => '/',
				),
				array(
					'code' => 'en',
					'name' => 'English',
					'locale' => 'en_EN',
					'url' => '/en',
				),
			      
			);
  break;
  
}

c::set( 'languages' , $languages );

```

But it doesn’t work.

---

<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:** [April 11, 2017, 10:22pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/5 "2017-04-11T22:22:56Z")

</div>

Well, if you think about it, switching can only work if you define “en” as `generalOptionsLanguage` in the French site.txt file and vice versa. That’s because the value is taken from the default language.

Edit: I think what I would try to do is to create a dashboard widget that saves the language configuration to an external file and then read that file in the config.

But the safer way would be to give the users a preconfigured installation instead if trying to automate it. After all, you don’t know in advance, how many and which languages they need, which locales of a given language they want to use etc.

---

<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, 4:50pm UTC](https://forum.getkirby.com/t/translation-and-config-php-bug/6467/6 "2025-02-06T16:50:10Z")

</div>

Archived on February 6, 2025, 4:50pm UTC


