Add I18nUtil class

This commit is contained in:
Corey McKrill 2023-01-31 17:12:11 -08:00
parent f5bdbbaa20
commit 21bae97e82
No known key found for this signature in database
GPG Key ID: 84BBFE669C4D97B8
1 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* A class of utilities for dealing with internationalization.
*/
namespace Automattic\WooCommerce\Utilities;
final class I18nUtil {
/**
* @var array $units
*/
private static $units;
/**
* Get the translated label for a weight unit of measure.
*
* @param string $weight_unit
*
* @return string
*/
public static function get_weight_unit_label( $weight_unit ) {
if ( empty( self::$units ) ) {
self::$units = include WC()->plugin_path() . '/i18n/units.php';
}
$label = '';
if ( ! empty( self::$units['weight'][ $weight_unit ] ) ) {
$label = self::$units['weight'][ $weight_unit ];
}
return $label;
}
/**
* Get the translated label for a dimensions unit of measure.
*
* @param string $dimensions_unit
*
* @return string
*/
public static function get_dimensions_unit_label( $dimensions_unit ) {
if ( empty( self::$units ) ) {
self::$units = include WC()->plugin_path() . '/i18n/units.php';
}
$label = '';
if ( ! empty( self::$units['dimensions'][ $dimensions_unit ] ) ) {
$label = self::$units['dimensions'][ $dimensions_unit ];
}
return $label;
}
}