Language variables with hooks

I’m experiencing an issue getting Custom language variables to work inside a Kirby page hook (@ config.php). A var_dump returns no any helpful information. I’m not sure that it is possible out-of-the-box to do so.


Page title gets generated based on parameters on page object. String inside title needs to change based on variable in languages/x.php

Simplified example (this does not seem to work):

// languages/sv.php
l::set('community', 'Gemenskap');

// config.php
elseif($page->content()->language() == 'sv') {
        'title' => l('community') // returns empty on save

Can’t seem to find much or a good solution to fix this. Any ideas?

Try using l::get('community') instead of l('community').

The language files and the whole multilang setup can only be loaded after the config.php as the multilang setup is defined there. Neither the current language nor the language variables are therefore available inside config.php.

Why are you running the code inside config.php after all? Maybe you could use a hook instead.

l() is a helper for l::get(), so this shouldn’t be the issue.

As I said, I’m currently using it within a hook. I generate a page title based on input from different fields. The user does not directly customise the title field.

Problem is the structure of said title field needs to be altered for a different language (in this case Swedish). Except for creating a custom field, if there no solution of using it in config.php and a hook?

Could you please post the full hook code?

l::get() will not work inside hooks, because even if you put it into a plugin file, the language configuration only get’s loaded after all plugins are loaded.

Edit: maybe instead of l::get() you can use c::get() and define what you need in the config.php file instead of a language file?