<?php

namespace Storeplugin\PDFInvoice;

defined('ABSPATH') || exit;

use Storeplugin\PDFInvoice\Framework\Contracts\ServiceInterface;

/**
 * Define the internationalization functionality.
 *
 * @since      1.0.0
 */
class I18n implements ServiceInterface
{
	/**
	 * Register the service by adding hooks.
	 *
	 * @return void
	 * @since 1.0.0
	 */
	public function register(): void
	{
		add_action('plugins_loaded', [$this, 'loadPluginTextdomain']);
	}

	/**
	 * Load the plugin text domain for translation.
	 *
	 * @return void
	 * @since 1.0.0
	 */
	public function loadPluginTextdomain(): void
	{
		// WordPress 6.7+ loads translations automatically
		if (version_compare(get_bloginfo('version'), '6.7', '>=')) {
			return;
		}

		// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- Required for WP < 6.7
		load_plugin_textdomain(
			Config::name(),
			false,
			dirname(plugin_basename(NXTPDF_PATH)) . '/languages/'
		);
	}
}
