$field ) { if ( ! empty( $field['label'] ) ) { $fields[ $name ]['label'] = pll__( $field['label'] ); } if ( ! empty( $field['placeholder'] ) ) { $fields[ $name ]['placeholder'] = pll__( $field['placeholder'] ); } } } return $fields; } /** * Registers the strings. * * @since 1.3 * * @return void */ protected function register_strings() { foreach ( self::$options as $option ) { $fields = get_option( $option ); if ( is_array( $fields ) ) { foreach ( $fields as $name => $field ) { if ( ! empty( $field['label'] ) ) { pll_register_string( sprintf( __( 'Label', 'polylang-wc' ), $name ), $field['label'], 'Checkout Field Editor' ); } if ( ! empty( $field['placeholder'] ) ) { pll_register_string( sprintf( __( 'Placeholder', 'polylang-wc' ), $name ), $field['placeholder'], 'Checkout Field Editor' ); } } } } } /** * Translated strings must be sanitized the same way Checkout Field Editor for WooCommerce does before they are saved * * @since 1.3 * * @param string $translation The string translation. * @param string $name The name as defined in pll_register_string. * @param string $context The context as defined in pll_register_string. * @return string Sanitized translation. */ public function sanitize_strings( $translation, $name, $context ) { if ( 'Checkout Field Editor' === $context ) { if ( __( 'Label', 'polylang-wc' ) === $name ) { $translation = wp_kses_post( trim( $translation ) ); } if ( __( 'Placeholder', 'polylang-wc' ) === $name ) { $translation = wc_clean( $translation ); } } return $translation; } }