| 1 |
<?php |
| 2 |
|
| 3 |
namespace Packetery\Module\Framework; |
| 4 |
|
| 5 |
trait TranslationTrait { |
| 6 |
/** |
| 7 |
* It is not possible to use esc_html__ or esc_attr__ this way. |
| 8 |
*/ |
| 9 |
public function __( string $text, string $domain = 'default' ): string { |
| 10 |
// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.NonSingularStringLiteralDomain |
| 11 |
$translation = __( $text, $domain ); |
| 12 |
if ( is_string( $translation ) ) { |
| 13 |
return $translation; |
| 14 |
} |
| 15 |
|
| 16 |
return ''; |
| 17 |
} |
| 18 |
|
| 19 |
public function getLocale(): string { |
| 20 |
return get_locale(); |
| 21 |
} |
| 22 |
|
| 23 |
public function getUserLocale(): string { |
| 24 |
return get_user_locale(); |
| 25 |
} |
| 26 |
|
| 27 |
public function unloadTextDomain( string $domain, bool $reloadable ): void { |
| 28 |
unload_textdomain( $domain, $reloadable ); |
| 29 |
} |
| 30 |
|
| 31 |
public function loadPluginTextDomain( string $domain ): void { |
| 32 |
load_plugin_textdomain( $domain ); |
| 33 |
} |
| 34 |
|
| 35 |
public function loadDefaultTextDomain(): void { |
| 36 |
load_default_textdomain(); |
| 37 |
} |
| 38 |
} |
| 39 |
|