<?php
/**
 * Lightweight i18n compatibility helpers.
 *
 * These wrappers intentionally avoid calling __(), _n(), or _x() with variable
 * arguments to keep static analysis (Plugin Check / WPCS) clean.
 */

defined( 'ABSPATH' ) || exit;

if ( ! defined( 'SMART_CONVERT_I18N_DOMAIN' ) ) {
	define( 'SMART_CONVERT_I18N_DOMAIN', 'smart-convert-currency-unit-conversion' );
}

/**
 * Translate a runtime msgid using domain translations object.
 *
 * @param string $english_msgid English source string.
 * @return string
 */
function smart_convert_currency_unit_conversion_i18n_translate_runtime( $english_msgid ) {
	$translations = get_translations_for_domain( SMART_CONVERT_I18N_DOMAIN );
	$translated   = $translations->translate( (string) $english_msgid );

	return ( is_string( $translated ) && '' !== $translated ) ? $translated : (string) $english_msgid;
}

/**
 * Translate plural runtime strings using domain translations object.
 *
 * @param string $english_singular English singular source.
 * @param string $english_plural   English plural source.
 * @param int    $count            Quantity.
 * @return string
 */
function smart_convert_currency_unit_conversion_i18n_translate_runtime_plural( $english_singular, $english_plural, $count ) {
	$translations = get_translations_for_domain( SMART_CONVERT_I18N_DOMAIN );
	$translated   = $translations->translate_plural( (string) $english_singular, (string) $english_plural, (int) $count );

	if ( is_string( $translated ) && '' !== $translated ) {
		return $translated;
	}

	return ( 1 === (int) $count ) ? (string) $english_singular : (string) $english_plural;
}

/**
 * Translate runtime msgid with context using domain translations object.
 *
 * @param string $english_msgid English source string.
 * @param string $context       Context key.
 * @return string
 */
function smart_convert_currency_unit_conversion_i18n_translate_runtime_with_context( $english_msgid, $context ) {
	$translations = get_translations_for_domain( SMART_CONVERT_I18N_DOMAIN );
	$translated   = $translations->translate( (string) $english_msgid, (string) $context );

	return ( is_string( $translated ) && '' !== $translated ) ? $translated : (string) $english_msgid;
}
