elementor
1 year ago
logs
1 month ago
strong-testimonials-beaver-block
1 year ago
submodules
8 months ago
class-strong-gutemberg.php
1 year ago
class-strong-log.php
1 year ago
class-strong-mail.php
1 year ago
class-strong-testimonials-average-shortcode.php
1 year ago
class-strong-testimonials-count-shortcode.php
1 year ago
class-strong-testimonials-defaults.php
1 month ago
class-strong-testimonials-form.php
1 month ago
class-strong-testimonials-order.php
1 year ago
class-strong-testimonials-privacy.php
1 year ago
class-strong-testimonials-render.php
1 month ago
class-strong-testimonials-templates.php
1 year ago
class-strong-testimonials-view-shortcode.php
1 week ago
class-strong-testimonials-view-widget.php
1 year ago
class-strong-view-display.php
1 day ago
class-strong-view-form.php
1 day ago
class-strong-view-slideshow.php
1 day ago
class-strong-view.php
1 day ago
class-walker-strong-category-checklist-front.php
1 year ago
deprecated.php
1 year ago
filters.php
1 month ago
functions-activation.php
1 month ago
functions-content.php
11 months ago
functions-image.php
5 months ago
functions-rating.php
1 year ago
functions-template-form.php
1 week ago
functions-template.php
4 months ago
functions-views.php
1 year ago
functions.php
1 month ago
l10n-polylang.php
1 year ago
l10n-wpml.php
1 year ago
post-types.php
1 week ago
retro.php
1 year ago
scripts.php
1 month ago
l10n-polylang.php
186 lines
| 1 | <?php |
| 2 | /** |
| 3 | * ---------------------------------------- |
| 4 | * POLYLANG |
| 5 | * ---------------------------------------- |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Add translation actions & filters. |
| 10 | */ |
| 11 | function wpmtst_l10n_filters_polylang() { |
| 12 | |
| 13 | // Translate |
| 14 | remove_filter( 'wpmtst_l10n', 'wpmtst_l10n_default' ); |
| 15 | add_filter( 'wpmtst_l10n', 'wpmtst_l10n_polylang', 20, 3 ); |
| 16 | // TODO handle cat IDs like WPML |
| 17 | |
| 18 | // Help |
| 19 | add_action( 'wpmtst_before_form_settings', 'wpmtst_help_link_polylang' ); |
| 20 | add_action( 'wpmtst_before_fields_settings', 'wpmtst_help_link_polylang' ); |
| 21 | add_action( 'wpmtst_after_notification_fields', 'wpmtst_help_link_polylang' ); |
| 22 | } |
| 23 | add_action( 'init', 'wpmtst_l10n_filters_polylang', 20 ); |
| 24 | |
| 25 | /** |
| 26 | * @param $l10n_string |
| 27 | * @param $context |
| 28 | * @param $name |
| 29 | * |
| 30 | * @return bool|string |
| 31 | */ |
| 32 | function wpmtst_l10n_polylang( $l10n_string, $context, $name ) { |
| 33 | if ( function_exists( 'pll__' ) ) { |
| 34 | return pll__( $l10n_string ); |
| 35 | } |
| 36 | return $l10n_string; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * pll_register_string($name, $string, $group, $multiline); |
| 41 | * $name (required) name provided for sorting convenience (ex: ‘myplugin’) |
| 42 | * $string (required) the string to translate |
| 43 | * $group (optional) the group in which the string is registered, defaults to ‘polylang’ |
| 44 | * $multiline (optional) if set to true, the translation text field will be multiline, defaults to false |
| 45 | */ |
| 46 | |
| 47 | /** |
| 48 | * Register form field strings. |
| 49 | * |
| 50 | * @param $fields |
| 51 | */ |
| 52 | function wpmtst_form_fields_polylang( $fields ) { |
| 53 | if ( function_exists( 'pll_register_string' ) ) { |
| 54 | $context = 'strong-testimonials-form-fields'; |
| 55 | foreach ( $fields as $field ) { |
| 56 | $name = $field['name'] . ' : '; |
| 57 | if ( isset( $field['after'] ) && $field['after'] ) { |
| 58 | pll_register_string( $name . __( 'after', 'strong-testimonials' ), $field['after'], $context ); |
| 59 | } |
| 60 | if ( isset( $field['before'] ) && $field['before'] ) { |
| 61 | pll_register_string( $name . __( 'before', 'strong-testimonials' ), $field['before'], $context ); |
| 62 | } |
| 63 | if ( isset( $field['placeholder'] ) && $field['placeholder'] ) { |
| 64 | pll_register_string( $name . __( 'placeholder', 'strong-testimonials' ), $field['placeholder'], $context ); |
| 65 | } |
| 66 | if ( isset( $field['label'] ) && $field['label'] ) { |
| 67 | pll_register_string( $name . __( 'label', 'strong-testimonials' ), $field['label'], $context ); |
| 68 | } |
| 69 | if ( isset( $field['default_form_value'] ) && $field['default_form_value'] ) { |
| 70 | pll_register_string( $name . __( 'default form value', 'strong-testimonials' ), $field['default_form_value'], $context ); |
| 71 | } |
| 72 | if ( isset( $field['default_display_value'] ) && $field['default_display_value'] ) { |
| 73 | pll_register_string( $name . __( 'default display value', 'strong-testimonials' ), $field['default_display_value'], $context ); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Register form strings. |
| 81 | * |
| 82 | * @param $options |
| 83 | */ |
| 84 | function wpmtst_form_options_polylang( $options ) { |
| 85 | if ( function_exists( 'pll_register_string' ) ) { |
| 86 | // Form messages |
| 87 | $context = 'strong-testimonials-form-messages'; |
| 88 | foreach ( $options['messages'] as $key => $field ) { |
| 89 | pll_register_string( $field['description'], $field['text'], $context ); |
| 90 | } |
| 91 | |
| 92 | // Form notification |
| 93 | $context = 'strong-testimonials-notification'; |
| 94 | pll_register_string( __( 'Email subject', 'strong-testimonials' ), $options['email_subject'], $context ); |
| 95 | pll_register_string( __( 'Email message', 'strong-testimonials' ), $options['email_message'], $context, true ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Register "Read more" link text. |
| 101 | * |
| 102 | * @since 2.11.17 |
| 103 | */ |
| 104 | function wpmtst_readmore_polylang() { |
| 105 | if ( function_exists( 'pll_register_string' ) ) { |
| 106 | $context = 'strong-testimonials-views'; |
| 107 | |
| 108 | $views = wpmtst_get_views(); |
| 109 | if ( ! $views ) { |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | foreach ( $views as $key => $view ) { |
| 114 | $view_data = unserialize( $view['value'] ); |
| 115 | if ( ! is_array( $view_data ) ) { |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | pll_register_string( |
| 120 | // translators: %s is the view ID. |
| 121 | sprintf( __( 'View %s : Read more (testimonial)', 'strong-testimonials' ), $view['id'] ), |
| 122 | $view_data['more_post_text'], |
| 123 | $context |
| 124 | ); |
| 125 | |
| 126 | pll_register_string( |
| 127 | // translators: %s is the view ID. |
| 128 | sprintf( __( 'View %s : Read less (testimonial)', 'strong-testimonials' ), $view['id'] ), |
| 129 | $view_data['less_post_text'], |
| 130 | $context |
| 131 | ); |
| 132 | |
| 133 | pll_register_string( |
| 134 | // translators: %s is the view ID. |
| 135 | sprintf( __( 'View %s : Read more (page or post)', 'strong-testimonials' ), $view['id'] ), |
| 136 | $view_data['more_page_text'], |
| 137 | $context |
| 138 | ); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Polylang string translations |
| 145 | * |
| 146 | * @since 1.21.0 |
| 147 | * `add_action( 'load-languages_page_mlang_strings', 'wpmtst_admin_polylang' );` |
| 148 | * |
| 149 | * @since 2.26.10 |
| 150 | * We can no longer use the page-specific hook because it's constructed using the user's admin language. |
| 151 | * Polylang does not provide a hook either. |
| 152 | * English: load-languages_page_mlang_strings |
| 153 | * French: load-langues_page_mlang_strings |
| 154 | */ |
| 155 | function wpmtst_admin_polylang() { |
| 156 | global $plugin_page; |
| 157 | |
| 158 | if ( isset( $plugin_page ) && 'mlang_strings' === $plugin_page ) { |
| 159 | // Minor improvements to list table style |
| 160 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 161 | wp_enqueue_style( 'wpmtst-admin-style-polylang', WPMTST_ADMIN_URL . 'css/polylang.css', array(), $plugin_version ); |
| 162 | |
| 163 | // Register strings for translation |
| 164 | wpmtst_form_fields_polylang( wpmtst_get_all_fields() ); |
| 165 | wpmtst_form_options_polylang( get_option( 'wpmtst_form_options' ) ); |
| 166 | wpmtst_readmore_polylang(); |
| 167 | } |
| 168 | } |
| 169 | add_action( 'admin_init', 'wpmtst_admin_polylang' ); |
| 170 | |
| 171 | /** |
| 172 | * Help link on various settings screens. |
| 173 | * |
| 174 | * @param $context |
| 175 | */ |
| 176 | function wpmtst_help_link_polylang( $context ) { |
| 177 | echo '<p>'; |
| 178 | echo '<span class="dashicons dashicons-info icon-blue"></span> '; |
| 179 | printf( |
| 180 | // translators: %s is the URL to the Polylang String Translations page for the specific context. |
| 181 | wp_kses_post( __( 'Translate these fields in <a href="%s">Polylang String Translations</a>', 'strong-testimonials' ) ), |
| 182 | esc_url( admin_url( 'admin.php?page=mlang_strings&group=strong-testimonials-' . $context . '&paged=1' ) ) |
| 183 | ); |
| 184 | echo '</p>'; |
| 185 | } |
| 186 |