> */ private static array $catalogue = []; private function __construct() {} /** * Every replaceable text: the standard wording (translated), and for the settings screen * a label and the placeholders the wording may use. * * @return array */ public static function catalogue(): array { $locale = determine_locale(); if ( isset( self::$catalogue[ $locale ] ) ) { return self::$catalogue[ $locale ]; } self::$catalogue[ $locale ] = [ 'waiting_page' => [ 'label' => __( 'Waiting for the payment (Cryptoway page)', 'cryptoway-button' ), 'default' => __( 'Waiting for your payment…', 'cryptoway-button' ), ], 'waiting_onsite' => [ 'label' => __( 'Waiting for the transfer (payment on the page)', 'cryptoway-button' ), 'default' => __( 'Waiting for your transfer…', 'cryptoway-button' ), ], 'confirming' => [ 'label' => __( 'Money arrived, confirming', 'cryptoway-button' ), 'default' => __( 'Payment received, confirming…', 'cryptoway-button' ), ], 'paid' => [ 'label' => __( 'Paid (when the button has no message of its own)', 'cryptoway-button' ), 'default' => __( 'Thank you! Your payment is confirmed.', 'cryptoway-button' ), ], 'underpaid' => [ 'label' => __( 'Underpaid, remainder known', 'cryptoway-button' ), /* translators: 1: received amount, 2: invoiced amount, 3: coin, 4: remaining amount */ 'default' => __( 'Received %1$s of %2$s %3$s. Please send the remaining %4$s.', 'cryptoway-button' ), /* translators: the placeholders are written literally: they name what the site owner must keep in the text */ 'placeholders' => __( '%1$s — received, %2$s — invoiced, %3$s — coin, %4$s — remaining', 'cryptoway-button' ), ], 'underpaid_unknown' => [ 'label' => __( 'Underpaid, remainder unknown', 'cryptoway-button' ), 'default' => __( 'Part of the amount arrived. Please send the rest.', 'cryptoway-button' ), ], 'short_late' => [ 'label' => __( 'Underpaid and the time ran out', 'cryptoway-button' ), 'default' => __( 'The payment arrived short and the time to pay ran out. Please contact us.', 'cryptoway-button' ), ], 'expired' => [ 'label' => __( 'The time ran out without payment', 'cryptoway-button' ), 'default' => __( 'The time to pay ran out. Please start again.', 'cryptoway-button' ), ], 'late' => [ 'label' => __( 'Paid after the time ran out', 'cryptoway-button' ), 'default' => __( 'Your payment arrived after the time to pay ran out. We will check it and get back to you.', 'cryptoway-button' ), ], 'aml' => [ 'label' => __( 'Held by the Cryptoway check', 'cryptoway-button' ), 'default' => __( 'Your payment is being checked by Cryptoway.', 'cryptoway-button' ), ], 'cancelled' => [ 'label' => __( 'Cancelled', 'cryptoway-button' ), 'default' => __( 'The payment was cancelled.', 'cryptoway-button' ), ], 'hold' => [ 'label' => __( 'Being checked by the site', 'cryptoway-button' ), 'default' => __( 'Your payment is being checked. We will get back to you.', 'cryptoway-button' ), ], 'failed' => [ 'label' => __( 'Could not start', 'cryptoway-button' ), 'default' => __( 'The payment could not be started. Please try again.', 'cryptoway-button' ), ], ]; return self::$catalogue[ $locale ]; } /** The wording in force: the site owner's, or the standard one. */ public static function get( string $key ): string { $own = Settings::texts()[ $key ] ?? ''; if ( '' !== $own ) { return $own; } return self::catalogue()[ $key ]['default'] ?? ''; } /** * Fills %s / %1$s placeholders without sprintf: a stray "%" in the owner's wording must not * break the page. Unnumbered placeholders take the arguments in order. */ public static function fill( string $text, string ...$args ): string { $next = 0; return (string) preg_replace_callback( '/%(?:(\d+)\$)?s/', static function ( array $m ) use ( &$next, $args ): string { $index = isset( $m[1] ) && '' !== $m[1] ? (int) $m[1] - 1 : $next++; return $args[ $index ] ?? ''; }, $text ); } /** get() with its placeholders filled. */ public static function line( string $key, string ...$args ): string { return self::fill( self::get( $key ), ...$args ); } }