null-provider.php
189 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Null Multilingual Provider. |
| 4 | * |
| 5 | * Used when no supported multilingual plugin is detected. Returns inputs unchanged so |
| 6 | * existing single-language behavior is preserved without conditional checks at call sites. |
| 7 | * |
| 8 | * @package sureforms. |
| 9 | * @since 2.11.0 |
| 10 | */ |
| 11 | |
| 12 | namespace SRFM\Inc\Compatibility\Multilingual\Providers; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly. |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Null_Provider. |
| 20 | * |
| 21 | * Pass-through implementation of {@see Provider}. |
| 22 | * |
| 23 | * @since 2.11.0 |
| 24 | */ |
| 25 | class Null_Provider implements Provider { |
| 26 | /** |
| 27 | * Whether the underlying multilingual plugin is active. |
| 28 | * |
| 29 | * @since 2.11.0 |
| 30 | * @return bool Always false for the Null provider. |
| 31 | */ |
| 32 | public function is_active(): bool { |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Current visitor language code. |
| 38 | * |
| 39 | * @since 2.11.0 |
| 40 | * @return string Always an empty string. |
| 41 | */ |
| 42 | public function current_language(): string { |
| 43 | return ''; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Site default language code. |
| 48 | * |
| 49 | * @since 2.11.0 |
| 50 | * @return string Always an empty string. |
| 51 | */ |
| 52 | public function default_language(): string { |
| 53 | return ''; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Register a translatable string. No-op for the Null provider. |
| 58 | * |
| 59 | * @param string $name Unique string identifier within the domain. |
| 60 | * @param string $value Original string value to register. |
| 61 | * @param string $domain Translation domain. Defaults to the sureforms text domain. |
| 62 | * @since 2.11.0 |
| 63 | * @return void |
| 64 | */ |
| 65 | public function register_string( string $name, string $value, string $domain = 'sureforms' ): void { |
| 66 | // No-op: there is no String Translation registry to talk to. |
| 67 | unset( $name, $value, $domain ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Translate a string. The Null provider returns the original value unchanged. |
| 72 | * |
| 73 | * @param string $value Original string value. |
| 74 | * @param string $name Unique string identifier within the domain. |
| 75 | * @param string $domain Translation domain. Defaults to the sureforms text domain. |
| 76 | * @param string|null $language Optional target language code. |
| 77 | * @since 2.11.0 |
| 78 | * @return string The unchanged input value. |
| 79 | */ |
| 80 | public function translate( string $value, string $name, string $domain = 'sureforms', ?string $language = null ): string { |
| 81 | unset( $name, $domain, $language ); |
| 82 | return $value; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Switch the active language context. No-op for the Null provider. |
| 87 | * |
| 88 | * @param string $language Target language code. |
| 89 | * @since 2.11.0 |
| 90 | * @return void |
| 91 | */ |
| 92 | public function switch_language( string $language ): void { |
| 93 | // No-op: there is no language context to switch. |
| 94 | unset( $language ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Restore the previous language context. No-op for the Null provider. |
| 99 | * |
| 100 | * @since 2.11.0 |
| 101 | * @return void |
| 102 | */ |
| 103 | public function restore_language(): void { |
| 104 | // No-op: there is no language context to restore. |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Render a language switcher. No-op for the Null provider. |
| 109 | * |
| 110 | * @since 2.11.0 |
| 111 | * @return string Empty string — no switcher to render when no provider is active. |
| 112 | */ |
| 113 | public function render_language_switcher(): string { |
| 114 | return ''; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * No package support without an active multilingual provider. |
| 119 | * |
| 120 | * @since 2.11.0 |
| 121 | * @return bool Always false. |
| 122 | */ |
| 123 | public function supports_packages(): bool { |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Begin a package registration. No-op for the Null provider. |
| 129 | * |
| 130 | * @param array<string,string> $package Package descriptor. |
| 131 | * @since 2.11.0 |
| 132 | * @return void |
| 133 | */ |
| 134 | public function start_package( array $package ): void { |
| 135 | unset( $package ); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Finish a package registration. No-op for the Null provider. |
| 140 | * |
| 141 | * @param array<string,string> $package Package descriptor. |
| 142 | * @since 2.11.0 |
| 143 | * @return void |
| 144 | */ |
| 145 | public function finish_package( array $package ): void { |
| 146 | unset( $package ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Register a package string. No-op for the Null provider. |
| 151 | * |
| 152 | * @param array<string,string> $package Package descriptor. |
| 153 | * @param string $name String identifier. |
| 154 | * @param string $value Original value. |
| 155 | * @param string $title Editor label. |
| 156 | * @param string $type Editor field type. |
| 157 | * @since 2.11.0 |
| 158 | * @return void |
| 159 | */ |
| 160 | public function register_package_string( array $package, string $name, string $value, string $title = '', string $type = 'LINE' ): void { |
| 161 | unset( $package, $name, $value, $title, $type ); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Translate a package string. Returns the original value for the Null provider. |
| 166 | * |
| 167 | * @param array<string,string> $package Package descriptor. |
| 168 | * @param string $name String identifier. |
| 169 | * @param string $value Original value. |
| 170 | * @since 2.11.0 |
| 171 | * @return string The original value unchanged. |
| 172 | */ |
| 173 | public function translate_package_string( array $package, string $name, string $value ): string { |
| 174 | unset( $package, $name ); |
| 175 | return $value; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Delete a string package. No-op for the Null provider. |
| 180 | * |
| 181 | * @param array<string,string> $package Package descriptor. |
| 182 | * @since 2.12.3 |
| 183 | * @return void |
| 184 | */ |
| 185 | public function delete_package( array $package ): void { |
| 186 | unset( $package ); |
| 187 | } |
| 188 | } |
| 189 |