How to access site blueprint field (site.fr.txt) in config.php in multilingual site?

I wanted to do the same thing as described in this issue: access the value of site field from the panel inside config.php.

So I applied the same suggested code as here:

But in a multilingual setup, the default language site info is then used in every languages. Seems doing this breaks something (in the order in which things are loaded maybe?) specifically in multilingual sites.

Is there a way to do this?
The use case is simply to have a config.php value store API key for some services and let client the possibility to update this value from the panel.

And the API key is “translated”, i.e. different in the translations? Not sure I understand the problem. Please post your code.

Basically, here is what it looks like.

My website is french by default and has english as second language.
I translated the menu and other infos from site.fr.txt to site.en.txt (tokens are the same of course)
When the following config.php code is used with a multilingual site the data from site.en.txt is ignored. For example the menu defined in this blueprint is showed in french in both english and french versions of the website and panel… even though when I open the site.en.txt file with a text editor I can still see that it is in english.

That’s obviously caused by the 'ready' => function () { part but either it’s a bug or a faulty implementation on my part.

In any case here is what I want to do when I say “define APIs keys in the config.php file and use this info in the config.php file”:

(maybe that’s not possible with Kirby, I don’t know yet, so I tried)

# site.yml
title: Site
tabs:
  pages:  
    icon: folder-structure
    sections:
      pages:
        # pages section content
      subpages:
        # other pages section content
  separator:
    label: "|"
  blog:
    label: News
    icon: megaphone
    sections:
      news:
      # other pages type section content
  products:
    label: Produits
    icon: glass
    sections:
      # yet another pages type section content
  separator2:
    label: "|"

  Menu:
# menu content
    label: Menu
    icon: grid-top
    fields:
      primaryMenu: fields/menufields

      secondaryMenu:
        type: structure
        fields:
          secondaryMenuTitle:
            type: text
            label: Mainmenu item
          secondaryMenuLink:
            type: url
            label: Lien
          secondaryMenuTarget:
            type: toggle
            label: Nouvel onglet
      socialIcons:
        type: info
        theme: passive 

  Footer:
    icon: grid-bottom
      bottom_footer:
        label: Footer content
        type: textarea

  Settings:
    icon: cog
    type: fields
    fields:
      InstagramAccessToken:
        type: text
      hCaptchaSecret:
        type: text
      DeeplAPISecret:
        type: text
// config.php
return [
    'debug' => false,

    'languages' => true,

    'tobimori.icon-field' => [
      'cache' => false,
      'folder' => 'assets/icons'
    ],

    'sylvainjule.matomo' => [
      'url' => 'https://analytics.example.com',
      'id' => '11',
      'token' => 'xyz', // a token directly in the config.php file
      'disableCookies' => true,
    ],

    'ready' => function () {
      return [
        'johannschopplich.content-translator' => [
          // API key for the DeepL free or pro plan
          'DeepL' => [
              'apiKey' => site()->DeeplAPISecret()
          ]
        ],
  
        'owebstudio.instagram-feed' => [
          'accessToken' => site()->InstagramAccessToken(),
          'cache' => true,
          'store' => true,
          'debug' => false,
          'expire' => 480, // 3 hours
          'limit' => 12 // fetch limit 
        ],
  
        'hcaptcha' => [
          'secret' => site()->hCaptchaSecret()
        ]
      ];
    },

Ok, I can reproduce this, you can work around this issue by explicitely calling the content in the default language in your config:

    'ready' => function () {
	    return [
		    'johannschopplich.content-translator' => [
			    // API key for the DeepL free or pro plan
			    'DeepL' => [
				    'apiKey' => site()->content('fr')->DeeplAPISecret()->value()
			    ]
		    ],

		    'owebstudio.instagram-feed' => [
			    'accessToken' => site()->content('fr')->InstagramAccessToken()->value(),
			    'cache' => true,
			    'store' => true,
			    'debug' => false,
			    'expire' => 480, // 3 hours
			    'limit' => 12 // fetch limit
		    ],

		    'hcaptcha' => [
			    'secret' => site()->content('fr')->hCaptchaSecret()->value()
		    ]
	    ];
    },

I’d also recommend to set those token/secret fields to translate: false, you don’t want users to translate them into different languages.

Indeed it works this way!

I have to admit I forgot about the translate: field parameter. Fixed it! Thanks!