<?php 

class I18n {
    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(
            'new-devs.v2',
            false,
            dirname(ZODDAK_PLUGIN_BASENAME) . '/languages/'
        );
    }
}