• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / CLDR / 15865804447

25 Jun 2025 02:21AM UTC coverage: 95.929% (-1.3%) from 97.22%
15865804447

push

github

olvlvl
Add LanguageId and LocaleId

204 of 227 new or added lines in 18 files covered. (89.87%)

1296 of 1351 relevant lines covered (95.93%)

36.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.55
/src/Core/TransformLocaleExtensions.php
1
<?php
2

3
namespace ICanBoogie\CLDR\Core;
4

5
/**
6
 * @link https://www.unicode.org/reports/tr35/tr35-75/tr35.html#BCP47_T_Extension
7
 */
8
final class TransformLocaleExtensions
9
{
10
    private const MAP_PREFIX_TO_PROPERTY = [
11
        'm0' => 'transform_extension_mechanism',
12
        's0' => 'transform_source',
13
        'd0' => 'transform_destination',
14
        'i0' => 'input_method_engine_transform',
15
        'k0' => 'keyboard_transform',
16
        't0' => 'machine_translation',
17
        'h0' => 'hybrid_locale_identifiers',
18
        'x0' => 'private_use',
19
    ];
20

21
    private const REGEXP_EXTENSION = '/([msdikthx]0)-([a-z\d]{3,8})/';
22

23
    /**
24
     * @param string $transform_ext
25
     *     A Transform Locale Extension (-t-) format (defined in BCP 47).
26
     */
27
    public static function parse(string $transform_ext): self
28
    {
29
        if (str_starts_with($transform_ext, 't-')) {
3✔
30
            $transform_ext = substr($transform_ext, 2);
1✔
31
        }
32

33
        preg_match_all(self::REGEXP_EXTENSION, $transform_ext, $matches, PREG_SET_ORDER);
3✔
34

35
        $properties = [];
3✔
36

37
        foreach ($matches as [, $prefix, $value]) {
3✔
38
            $property = self::MAP_PREFIX_TO_PROPERTY[$prefix]
3✔
39
                ?? throw new InvalidTransformLocaleExtensions(
3✔
40
                    "Invalid extension prefix '$prefix' in '$transform_ext'",
3✔
41
                );
3✔
42

43
            $properties[$property] = $value;
3✔
44
        }
45

46
        return new self(...$properties);
3✔
47
    }
48

49
    /**
50
     * @param string|null $transform_extension_mechanism
51
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform.json}
52
     * @param string|null $transform_source
53
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform-destination.json}
54
     * @param string|null $transform_destination
55
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform-destination.json}
56
     * @param string|null $input_method_engine_transform
57
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform_ime.json}
58
     * @param string|null $keyboard_transform
59
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform_keyboard.json}
60
     * @param string|null $machine_translation
61
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform_mt.json}
62
     * @param string|null $hybrid_locale_identifiers
63
     *     {@link
64
     *     https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform_hybrid.json}
65
     * @param string|null $private_use
66
     *     {@link https://github.com/unicode-org/cldr-json/blob/47.0.0/cldr-json/cldr-bcp47/bcp47/transform_private_use.json}
67
     */
68
    public function __construct(
69
        public readonly ?string $transform_extension_mechanism = null,
70
        public readonly ?string $transform_source = null,
71
        public readonly ?string $transform_destination = null,
72
        public readonly ?string $input_method_engine_transform = null,
73
        public readonly ?string $keyboard_transform = null,
74
        public readonly ?string $machine_translation = null,
75
        public readonly ?string $hybrid_locale_identifiers = null,
76
        public readonly ?string $private_use = null,
77
    ) {
78
    }
23✔
79

80
    /**
81
     * @return array<string, ?string>
82
     */
83
    public function to_array(): array
84
    {
NEW
85
        return [
×
86

NEW
87
            'm0' => $this->transform_extension_mechanism,
×
NEW
88
            's0' => $this->transform_source,
×
NEW
89
            'd0' => $this->transform_destination,
×
NEW
90
            'i0' => $this->input_method_engine_transform,
×
NEW
91
            'k0' => $this->keyboard_transform,
×
NEW
92
            't0' => $this->machine_translation,
×
NEW
93
            'h0' => $this->hybrid_locale_identifiers,
×
NEW
94
            'x0' => $this->private_use,
×
95

NEW
96
        ];
×
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc