summaryrefslogtreecommitdiffstats
path: root/includes/class-cepis-woo-messages.php
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 16:41:48 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 16:47:14 -0300
commit535dbda6b48171f8115b455e54790de94d97d42a (patch)
tree5c0410011e61a883bdf063ee612875a637fb1d22 /includes/class-cepis-woo-messages.php
downloadwoocommerce-0.1.0.tar.gz
Initial importv0.1.0
Diffstat (limited to 'includes/class-cepis-woo-messages.php')
-rw-r--r--includes/class-cepis-woo-messages.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/includes/class-cepis-woo-messages.php b/includes/class-cepis-woo-messages.php
new file mode 100644
index 0000000..201fe4e
--- /dev/null
+++ b/includes/class-cepis-woo-messages.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * The strings the shopper sees while a CEP is looked up.
+ *
+ * @package CepisWooCommerce
+ */
+
+declare(strict_types=1);
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * The widget ships its own Portuguese messages; these replace them so that a
+ * store running in another locale gets the checkout in that locale, and so a
+ * store owner can reword them with the usual translation tooling.
+ *
+ * Keys are the widget's status kinds and error codes. Anything not listed
+ * keeps the widget's own wording.
+ */
+final class Cepis_Woo_Messages {
+
+ /**
+ * Build the message table.
+ *
+ * Must be called at or after `init`: it is the first thing in the plugin
+ * that translates.
+ *
+ * @return array<string, string> Message per status kind or error code.
+ */
+ public static function all(): array {
+ $messages = array(
+ 'idle' => '',
+ 'loading' => __( 'Looking the address up…', 'cepis-woocommerce' ),
+ 'found' => __( 'Address found.', 'cepis-woocommerce' ),
+ 'not_found' => __( 'CEP not found. Check the number or fill the address in by hand.', 'cepis-woocommerce' ),
+ 'invalid' => __( 'Invalid CEP. Type all 8 digits.', 'cepis-woocommerce' ),
+ 'rate_limited' => __( 'Too many lookups in a short time. Wait a few seconds and try again.', 'cepis-woocommerce' ),
+ 'server' => __( 'The CEP service is unavailable. Fill the address in by hand.', 'cepis-woocommerce' ),
+ 'network' => __( 'Could not look the CEP up. Check your connection and try again.', 'cepis-woocommerce' ),
+ 'timeout' => __( 'The CEP lookup took too long. Try again or fill the address in by hand.', 'cepis-woocommerce' ),
+ 'invalid_response' => __( 'Unexpected answer from the CEP service. Fill the address in by hand.', 'cepis-woocommerce' ),
+ );
+
+ /**
+ * Filters the messages shown at the checkout while a CEP is resolved.
+ *
+ * @param array<string, string> $messages Message per status kind or error code.
+ */
+ $messages = (array) apply_filters( 'cepis_woocommerce_messages', $messages );
+
+ $clean = array();
+ foreach ( $messages as $key => $message ) {
+ if ( is_string( $key ) && is_scalar( $message ) ) {
+ $clean[ sanitize_key( $key ) ] = wp_strip_all_tags( (string) $message );
+ }
+ }
+
+ return $clean;
+ }
+}