PluginProbe
TablePress – Tables in WordPress made easy / 3.4
TablePress – Tables in WordPress made easy v3.4
3.4 3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 All 45 releases
tablepress / libraries / vendor / PhpSpreadsheet / Style / NumberFormat / Wizard / Locale.php

Locale.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php

36 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace TablePress\PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
4
5 use NumberFormatter;
6 use TablePress\PhpOffice\PhpSpreadsheet\Exception;
7
8 final class Locale
9 {
10 /**
11 * Language code: ISO-639 2 character, alpha.
12 * Optional script code: ISO-15924 4 alpha.
13 * Optional country code: ISO-3166-1, 2 character alpha.
14 * Separated by underscores or dashes.
15 */
16 public const STRUCTURE = '/^(?P<language>[a-z]{2})([-_](?P<script>[a-z]{4}))?([-_](?P<country>[a-z]{2}))?$/i';
17
18 private NumberFormatter $formatter;
19
20 public function __construct(?string $locale, int $style)
21 {
22 $formatterLocale = str_replace('-', '_', $locale ?? '');
23 $this->formatter = new NumberFormatter($formatterLocale, $style);
24 if ($this->formatter->getLocale() !== $formatterLocale) {
25 throw new Exception("Unable to read locale data for '{$locale}'");
26 }
27 }
28
29 public function format(bool $stripRlm = true): string
30 {
31 $str = $this->formatter->getPattern();
32
33 return ($stripRlm && str_starts_with($str, "\xe2\x80\x8f")) ? (string) substr($str, 3) : $str;
34 }
35 }
36