1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
}
}
|