/var/www/html_us/wp-content/plugins/woocommerce/src/Utilities/I18nUtil.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
 * A class of utilities for dealing with internationalization.
 */

namespace Automattic\WooCommerce\Utilities;

/**
 * A class of utilities for dealing with internationalization.
 */
final class I18nUtil {
    
/**
     * A cache for the i18n units data.
     *
     * @var array $units
     */
    
private static $units;

    
/**
     * Get the translated label for a weight unit of measure.
     *
     * This will return the original input string if it isn't found in the units array. This way a custom unit of
     * measure can be used even if it's not getting translated.
     *
     * @param string $weight_unit The abbreviated weight unit in English, e.g. kg.
     *
     * @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 $weight_unit;

        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.
     *
     * This will return the original input string if it isn't found in the units array. This way a custom unit of
     * measure can be used even if it's not getting translated.
     *
     * @param string $dimensions_unit The abbreviated dimension unit in English, e.g. cm.
     *
     * @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 $dimensions_unit;

        if ( ! empty( 
self::$units['dimensions'][ $dimensions_unit ] ) ) {
            
$label self::$units['dimensions'][ $dimensions_unit ];
        }

        return 
$label;
    }
}