Changeset 8317
- Timestamp:
- 02/22/2019 06:45:02 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-custom-warnings/wporg-gp-custom-warnings.php
r7314 r8317 30 30 * This allows for the scheme to change, and for WordPress.org URL's to change to a subdomain. 31 31 * 32 * @param string $original The orig nal string.32 * @param string $original The original string. 33 33 * @param string $translation The translated string. 34 34 */ … … 96 96 } 97 97 98 99 /** 100 * Adds a warning for changing placeholders. 101 * 102 * This only supports placeholders in the format of '###[A-Z_]+###'. 103 * 104 * @param string $original The original string. 105 * @param string $translation The translated string. 106 */ 107 public function warning_mismatching_placeholders( $original, $translation ) { 108 $placeholder_regex = '@(###[A-Z_]+###)@'; 109 110 preg_match_all( $placeholder_regex, $original, $original_placeholders ); 111 $original_placeholders = array_unique( $original_placeholders[0] ); 112 113 preg_match_all( $placeholder_regex, $translation, $translation_placeholders ); 114 $translation_placeholders = array_unique( $translation_placeholders[0] ); 115 116 $missing_placeholders = array_diff( $original_placeholders, $translation_placeholders ); 117 $added_placeholders = array_diff( $translation_placeholders, $original_placeholders ); 118 if ( ! $missing_placeholders && ! $added_placeholders ) { 119 return true; 120 } 121 122 // Error. 123 $error = ''; 124 if ( $missing_placeholders ) { 125 $error .= "The translation appears to be missing the following placeholders: " . implode( ', ', $missing_placeholders ) . "\n"; 126 } 127 if ( $added_placeholders ) { 128 $error .= "The translation contains the following unexpected placeholders: " . implode( ', ', $added_placeholders ); 129 } 130 131 return trim( $error ); 132 } 133 98 134 /** 99 135 * Registers all methods starting with warning_ with GlotPress.
Note: See TracChangeset
for help on using the changeset viewer.