<?php

if (! defined('ABSPATH')) {
    exit;
} final class PufferGo_Frontend_I18n
{
    public const TEXT_DOMAIN = 'puffergo-frontend';

    public const MO_SUBDIR = 'languages/frontend';

    public const CPT_ARCHIVE_LABELS = array('puffergo_product' => 'Products', 'puffergo_solution' => 'Solutions', 'puffergo_case' => 'Case Studies', 'puffergo_testimonial' => 'Testimonials', 'post' => 'Blog', );

    public static function init(): void
    {
        add_action('init', array(__CLASS__, 'load_textdomain'), 1);
        add_filter('gettext', array(__CLASS__, 'filter_gettext'), 10, 3);
    }

    public static function load_textdomain(): void
    {
        if (is_admin()) {
            return;
        } $locale = function_exists('determine_locale') ? determine_locale() : get_locale();
        $mofile = PUFFERGO_PLUGIN_DIR . '/' . self::MO_SUBDIR . '/puffergo-frontend-' . $locale . '.mo';

        if (is_readable($mofile)) {
            load_textdomain(self::TEXT_DOMAIN, $mofile);
        }
    }

    public static function filter_gettext($translation, $text, $domain)
    {
        if (is_admin() || 'puffergo' !== $domain || ! is_textdomain_loaded(self::TEXT_DOMAIN)) {
            return $translation;
        } $ui = translate($text, self::TEXT_DOMAIN);

        if (is_string($ui) && $ui !== $text) {
            return $ui;
        }

return $translation;
    }

    public static function cpt_archive_label(string $post_type): string
    {
        if (! isset(self::CPT_ARCHIVE_LABELS[ $post_type ])) {
            return '';
        }

return __(self::CPT_ARCHIVE_LABELS[ $post_type ], 'puffergo');
    }
}
