config = $siteConfig; $this->projectRoot = $projectRoot !== '' ? $projectRoot : dirname(__DIR__, 3); $this->adminLanguage = $siteConfig['admin_language'] ?? ($siteConfig['language']['default'] ?? 'nl'); } /** * Inject the admin PluginManager so plugins can resolve their own * translations through the same fallback chain. */ public function setPluginManager(PluginManager $pm): void { $this->pluginManager = $pm; } /** * Get configuration value using dot notation. */ public function getConfig(string $key, $default = null) { $keys = explode('.', $key); $value = $this->config; foreach ($keys as $k) { if (!is_array($value) || !isset($value[$k])) { return $default; } $value = $value[$k]; } return $value; } /** * Get the project root directory. */ public function getProjectRoot(): string { return $this->projectRoot; } /** * Get the content directory path. */ public function getContentDir(): string { return $this->config['content_dir'] ?? ($this->projectRoot . '/content'); } /** * Get the plugins directory path. */ public function getPluginsDir(): string { return $this->projectRoot . '/plugins'; } /** * Get the list of enabled plugins. */ public function getEnabledPlugins(): array { return $this->config['enabled_plugins'] ?? []; } /** * Get the version info from version.php. */ public function getVersionInfo(): array { $versionFile = $this->projectRoot . '/version.php'; if (file_exists($versionFile)) { $data = include $versionFile; if (is_array($data)) { return $data; } } return ['version' => '0.0.0']; } /** * Get the active admin language code (e.g. 'nl', 'en'). * System plugins should use this to resolve their translations. */ public function getAdminLanguage(): string { return $this->adminLanguage; } /** * Get the translations for a plugin in the admin context. * * Fallback chain (handled by PluginManager): * requested language -> plugin default_language -> empty array. * * @param string $pluginName Plugin directory name * @param string|null $lang Override language; defaults to the active admin language * @return array Translations [key => value] */ public function getPluginTranslations(string $pluginName, ?string $lang = null): array { if ($this->pluginManager === null) { return []; } $lang = $lang ?? $this->adminLanguage; return $this->pluginManager->getPluginTranslations($pluginName, $lang, 'admin'); } /** * Translate a single key for a plugin in the admin context. * * @param string $key Translation key * @param string $pluginName Plugin directory name * @param string|null $lang Override language; defaults to the active admin language * @return string Translated string, or $key if not found */ public function t(string $key, string $pluginName, ?string $lang = null): string { $t = $this->getPluginTranslations($pluginName, $lang); return $t[$key] ?? $key; } }