| 1 |
<?php |
| 2 |
/** |
| 3 |
* Translatable Class file for Sureforms. |
| 4 |
* |
| 5 |
* @package Sureforms |
| 6 |
* @since 1.0.5 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace SRFM\Inc; |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; // Exit if accessed directly. |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Sureforms Translatable Class |
| 17 |
* |
| 18 |
* A helper class providing an interface for handling translation of text elements, specifically |
| 19 |
* frontend validation messages, used in the Sureforms plugin. This class enables dynamic and |
| 20 |
* reusable translated strings to enhance user experience across different languages. |
| 21 |
* |
| 22 |
* @since 1.0.5 |
| 23 |
*/ |
| 24 |
class Translatable { |
| 25 |
/** |
| 26 |
* Retrieve default frontend validation messages. |
| 27 |
* |
| 28 |
* Returns an array of validation messages, each identified by a unique key. Messages are |
| 29 |
* translated for frontend display, with placeholders included for dynamically populated values. |
| 30 |
* |
| 31 |
* @since 1.0.5 |
| 32 |
* @return array<string, string> Associative array of translated validation messages for frontend use. |
| 33 |
*/ |
| 34 |
public static function get_frontend_validation_messages() { |
| 35 |
$translatable_array = self::dynamic_validation_messages(); |
| 36 |
|
| 37 |
/** |
| 38 |
* Filter for frontend validation messages. |
| 39 |
* |
| 40 |
* This filter allows developers to add or modify the default validation messages. |
| 41 |
* Primarily intended for enabling custom validation messages and supporting pro functionality. |
| 42 |
* |
| 43 |
* @internal This filter is primarily used for internal purposes and pro functionality. |
| 44 |
*/ |
| 45 |
return apply_filters( 'srfm_frontend_validation_messages', $translatable_array ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Retrieve default dynamic validation messages. |
| 50 |
* |
| 51 |
* @since 1.2.1 |
| 52 |
* @return array<string, string> Associative array of translated validation messages for dynamic use. |
| 53 |
*/ |
| 54 |
public static function dynamic_validation_messages() { |
| 55 |
$translatable_array = self::dynamic_messages(); |
| 56 |
|
| 57 |
/** |
| 58 |
* Filter for dynamic validation messages. |
| 59 |
* |
| 60 |
* The `srfm_dynamic_validation_messages` filter allows developers to add or modify |
| 61 |
* the default dynamic validation messages. |
| 62 |
* This is primarily intended for enabling custom validation messages and supporting pro functionality. |
| 63 |
* |
| 64 |
* @internal This filter is primarily used for internal purposes and pro functionality. |
| 65 |
*/ |
| 66 |
$filtered_array = apply_filters( 'srfm_dynamic_validation_messages', $translatable_array ); |
| 67 |
|
| 68 |
$dynamic_options = get_option( 'srfm_default_dynamic_block_option', [] ); |
| 69 |
if ( ! empty( $dynamic_options ) && is_array( $dynamic_options ) ) { |
| 70 |
foreach ( $dynamic_options as $key => $value ) { |
| 71 |
if ( isset( $filtered_array[ $key ] ) ) { |
| 72 |
$filtered_array[ $key ] = $value; |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
return $filtered_array; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Dynamic messages array |
| 82 |
* |
| 83 |
* @since 1.2.1 |
| 84 |
* @return array<string, string> Associative array of translated dynamic messages. |
| 85 |
*/ |
| 86 |
public static function dynamic_messages() { |
| 87 |
return [ |
| 88 |
'srfm_valid_phone_number' => __( 'Please enter a valid phone number.', 'sureforms' ), |
| 89 |
'srfm_valid_url' => __( 'Please enter a valid URL.', 'sureforms' ), |
| 90 |
'srfm_confirm_email_same' => __( 'Confirmation email does not match.', 'sureforms' ), |
| 91 |
'srfm_valid_email' => __( 'Please enter a valid email address.', 'sureforms' ), |
| 92 |
|
| 93 |
/* translators: %s represents the minimum acceptable value */ |
| 94 |
'srfm_input_min_value' => __( 'Minimum value is %s', 'sureforms' ), |
| 95 |
|
| 96 |
/* translators: %s represents the maximum acceptable value */ |
| 97 |
'srfm_input_max_value' => __( 'Maximum value is %s', 'sureforms' ), |
| 98 |
|
| 99 |
/* translators: %s represents the minimum number of selections required */ |
| 100 |
'srfm_dropdown_min_selections' => __( 'Minimum %s selections are required', 'sureforms' ), |
| 101 |
|
| 102 |
/* translators: %s represents the maximum number of selections allowed */ |
| 103 |
'srfm_dropdown_max_selections' => __( 'Maximum %s selections are allowed', 'sureforms' ), |
| 104 |
|
| 105 |
/* translators: %s represents the minimum number of characters required */ |
| 106 |
'srfm_multi_choice_min_selections' => __( 'Minimum %s selections are required', 'sureforms' ), |
| 107 |
|
| 108 |
/* translators: %s represents the maximum number of characters allowed */ |
| 109 |
'srfm_multi_choice_max_selections' => __( 'Maximum %s selections are allowed', 'sureforms' ), |
| 110 |
]; |
| 111 |
} |
| 112 |
} |
| 113 |
|