PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / utils / i18n.php

i18n.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/utils/i18n.php

58 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Utils;
4
5 /** @define "STOREENGINE_ROOT_DIR_PATH" "./../../" */
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * A class of utilities for dealing with internationalization.
13 */
14 final class I18n {
15 /**
16 * A cache for the i18n units data.
17 *
18 * @var ?array $units
19 */
20 private static ?array $units = null;
21
22 public static function get_units() {
23 if ( null === self::$units ) {
24 self::$units = apply_filters( 'storeengine/units', include STOREENGINE_ROOT_DIR_PATH . 'i18n/units.php' );
25 }
26
27 return self::$units;
28 }
29
30 /**
31 * Get the translated label for a weight unit of measure.
32 *
33 * This will return the original input string if it isn't found in the units array. This way a custom unit of
34 * measure can be used even if it's not getting translated.
35 *
36 * @param string $weight_unit The abbreviated weight unit in English, e.g. kg.
37 *
38 * @return string
39 */
40 public static function get_weight_unit_label( string $weight_unit ): string {
41 return self::get_units()['weight'][ $weight_unit ] ?? $weight_unit;
42 }
43
44 /**
45 * Get the translated label for a dimensions unit of measure.
46 *
47 * This will return the original input string if it isn't found in the units array. This way a custom unit of
48 * measure can be used even if it's not getting translated.
49 *
50 * @param string $dimensions_unit The abbreviated dimension unit in English, e.g. cm.
51 *
52 * @return string
53 */
54 public static function get_dimensions_unit_label( string $dimensions_unit ): string {
55 return self::get_units()['dimensions'][ $dimensions_unit ] ?? $dimensions_unit;
56 }
57 }
58