<?php
if (!defined('ABSPATH')) exit;

if (!function_exists('custausu_admin_locale')) {
  function custausu_admin_locale(): string {
    $loc = function_exists('get_user_locale')
      ? (string) get_user_locale()
      : (string) get_locale();

    return $loc !== '' ? $loc : 'en_US';
  }
}

if (!function_exists('custausu_admin_lang')) {
  function custausu_admin_lang(): string {
    $loc = custausu_admin_locale();
    $lang = strtolower((string) (explode('_', $loc)[0] ?? 'en'));
    $lang = sanitize_key($lang);

    return $lang !== '' ? $lang : 'en';
  }
}

if (!function_exists('custausu_admin_is_it')) {
  function custausu_admin_is_it(): bool {
    return custausu_admin_lang() === 'it';
  }
}

if (!function_exists('custausu_admin_t')) {
  function custausu_admin_t(string $en, string $it): string {
    return custausu_admin_is_it() ? $it : $en;
  }
}