value) ); } catch (\Throwable $th) { $name = null; } $parts = explode('-', $this->value); return [ 'code' => $this->value, 'language_code' => $parts[0] ?? null, 'country_code' => $parts[1] ?? null, 'name' => $name ]; } public static function create(string $val): ?static { $value = trim($val); $map = [ 'yue-HK' => 'zh-HK', 'cmn-TW' => 'zh-TW', 'cmn-CN' => 'zh-CN', 'ar-XA' => 'ar-SA', 'en-UK' => 'en-GB', ]; $value = $map[$value] ?? $value; $value = str_replace([' ', '_'], '-', $value); return self::tryFrom($value); } }