<?php 

class RsI18n {
    public static function init(): void
    {
        add_action('wp', [self::class, 'loadRouteBasedTextdomain']);
    }
    public static function loadRouteBasedTextdomain(): void
    {
        $lang = get_query_var('zoddak_lang');

        $map = [
            'es' => 'es_ES',
            'en' => 'en_US',
            'de' => 'de_DE',
            'da' => 'da_DK',
        ];

        if (!isset($map[$lang])) {
            return;
        }

        switch_to_locale($map[$lang]);

        load_plugin_textdomain(
            'resales.v2',
            false,
            dirname(ZODDAK_RESALES_PLUGIN_BASENAME) . '/languages/'
        );
    }
}