Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PHP error - Call to a member function addTranslationFile() on null #18699

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

use Glpi\Application\View\TemplateRenderer;
use Glpi\Cache\CacheManager;
use Glpi\Cache\I18nCache;
use Glpi\Dashboard\Grid;
use Glpi\Marketplace\Controller as MarketplaceController;
use Glpi\Marketplace\View as MarketplaceView;
Expand Down Expand Up @@ -476,6 +477,17 @@ public static function loadLang($plugin_key, $forcelang = '', $coretrytoload = '
}
}

if (!defined('TU_USER')) {
$i18n_cache = new I18nCache((new CacheManager())->getTranslationsCacheInstance());
$TRANSLATE = new class ($i18n_cache) extends Laminas\I18n\Translator\Translator {
public function __construct(?I18nCache $cache)
{
$this->cache = $cache;
}
};
$TRANSLATE->setLocale($coretrytoload);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the listener change is effective, this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this code, the initial error comes back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works on my side, but only after deleting the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for me too by emptying the folder _cache

if ($mofile !== false) {
$TRANSLATE->addTranslationFile(
'gettext',
Expand Down
Loading