Changeset 8751 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/helper-functions.php
- Timestamp:
- 05/08/2019 07:33:18 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/helper-functions.php
r8502 r8751 1 1 <?php 2 wp_register_style( 'wporg-translate', plugins_url( 'style.css', __FILE__ ), array( 'gp-base' ), '20190324' ); 2 wp_register_style( 3 'wporg-translate', 4 plugins_url( 'style.css', __FILE__ ), 5 [ 'gp-base' ], 6 '20190324' 7 ); 3 8 gp_enqueue_style( 'wporg-translate' ); 4 9 5 gp_enqueue_script( 'jquery' ); 6 7 wp_register_style( 'chartist', plugins_url( 'css/chartist.min.css', __FILE__ ), array(), '0.9.5' ); 8 wp_register_script( 'chartist', plugins_url( 'js/chartist.min.js', __FILE__ ), array(), '0.9.5' ); 10 wp_register_script( 11 'details-element-polyfill', 12 plugins_url( 'js/details-element-polyfill.min.js', __FILE__ ), 13 [], 14 '2.3.1' 15 ); 16 17 gp_enqueue_script( 'details-element-polyfill' ); 18 19 wp_register_script( 20 'autosize', 21 plugins_url( 'js/autosize.min.js', __FILE__ ), 22 [], 23 '4.0.2' 24 ); 25 26 wp_register_script( 27 'wporg-translate-editor', 28 plugins_url( 'js/editor.js', __FILE__ ), 29 [ 'gp-editor', 'autosize' ], 30 '20190506' 31 ); 32 33 wp_register_style( 34 'chartist', 35 plugins_url( 'css/chartist.min.css', __FILE__ ), 36 [], 37 '0.9.5' 38 ); 39 wp_register_script( 40 'chartist', 41 plugins_url( 'js/chartist.min.js', __FILE__ ), 42 [], 43 '0.9.5' 44 ); 45 46 if ( isset( $template ) && 'translations' === $template ) { 47 gp_enqueue_script( 'wporg-translate-editor' ); 48 } 49 50 /** 51 * Prints markup for translations help modal in footer. 52 */ 53 add_action( 'gp_footer', static function() use ( $template, $args ) { 54 if ( 'translations' === $template && ! empty( $args['locale_slug'] ) ) { 55 $locale = GP_Locales::by_slug( $args['locale_slug'] ); 56 wporg_translation_help_modal( $locale ); 57 } 58 } ); 59 60 /** 61 * Prints markup for the translation help dialog. 62 * 63 * @param \GP_Locale $locale Locale of the current translation set. 64 */ 65 function wporg_translation_help_modal( $locale ) { 66 $locale_resources = wporg_get_locale_resources( $locale ) 67 ?> 68 <div id="wporg-translation-help-modal" class="wporg-translate-modal"> 69 <div class="wporg-translate-modal__overlay"> 70 <div class="wporg-translate-modal__frame" role="dialog" aria-labelledby="wporg-translation-help-modal-headline"> 71 <div class="wporg-translate-modal__header"> 72 <h1 id="wporg-translation-help-modal-headline" class="wporg-translate-modal__headline">Help</h1> 73 <button type="button" aria-label="Close modal" class="wporg-translate-modal__close"><span class="screen-reader-text">Close</span><span aria-hidden="true" class="dashicons dashicons-no-alt"></span></button> 74 </div> 75 76 <div class="wporg-translate-modal__content"> 77 <div class="wporg-translate-modal__content_primary"> 78 <h2>Validating Translations</h2> 79 <p>After a contributor suggests a string, the string gets a status of “suggested”. In order to transform them into “approved” strings (which will be used in WordPress), a Translation Editor needs to accept (or reject) those suggestions.<br> 80 Please give editors a reasonable time to validate suggestions — We are all volunteers.</p> 81 82 <h2>Translation Status</h2> 83 <ul class="no-list"> 84 <li><span style="color: #c1e1b9">◼︎</span> <strong>Current:</strong> Indicates an approved string.</li> 85 <li><span style="color: #ffe399">◼︎</span> <strong>Waiting:</strong> Indicates a string that was suggested, but not yet approved by a Translation Editor.</li> 86 <li><span style="color: #fbc5a9">◼︎</span> <strong>Fuzzy:</strong> Indicates a “fuzzy” string. Those translations need to be reviewed for accuracy and edited or approved.</li> 87 <li><span style="color: #cdc5e1">◼︎</span> <strong>Old:</strong> Indicates a string that was obsoleted by a newer, approved translation.</li> 88 <li><span style="color: #dc3232">◼︎</span> <strong>Warning:</strong> Indicates validation warnings. These translations either need to be corrected or their warnings explicitly discarded by a Translation Editor.</li> 89 </ul> 90 </div> 91 <div class="wporg-translate-modal__content_secondary"> 92 <?php if ( $locale_resources ) : ?> 93 <h2><span aria-hidden="true" class="dashicons dashicons-info"></span> Locale Resources for <?php echo esc_html( $locale->english_name ); ?></h2> 94 <?php echo wp_kses_post( $locale_resources ); ?> 95 <?php endif; ?> 96 97 <h2><span aria-hidden="true" class="dashicons dashicons-admin-page"></span> Global Handbook Resources</h2> 98 <?php 99 add_filter( 'walker_nav_menu_start_el', 'wporg_add_nav_description', 10, 4 ); 100 wp_nav_menu( [ 101 'theme_location' => 'wporg_translate_global_resources', 102 'fallback_cb' => false, 103 'container' => false, 104 'menu_id' => 'global-resources', 105 'depth' => 2, 106 ] ); 107 remove_filter( 'walker_nav_menu_start_el', 'wporg_add_nav_description' ); 108 ?> 109 </div> 110 </div> 111 </div> 112 </div> 113 </div> 114 <?php 115 } 116 117 /** 118 * Adds descriptions to navigation items. 119 * 120 * @param string $item_output The menu item output. 121 * @param WP_Post $item Menu item object. 122 * @param int $depth Depth of the menu. 123 * @param array $args wp_nav_menu() arguments. 124 * @return string Menu item with possible description. 125 */ 126 function wporg_add_nav_description( $item_output, $item, $depth, $args ) { 127 if ( $item->description ) { 128 $item_output = str_replace( 129 $args->link_after . '</a>', 130 $args->link_after . '</a>: <span class="menu-item-description">' . $item->description . '</span>', 131 $item_output 132 ); 133 } 134 135 return $item_output; 136 } 137 138 /** 139 * Retrieves the navigation menu from the assigned Rosetta site. 140 * 141 * Output is cached for an hour. 142 * 143 * @param \GP_Locale $locale 144 * @return string The HTML markup of the navigation menu. 145 */ 146 function wporg_get_locale_resources( $locale ) { 147 if ( empty( $locale->wp_locale ) ) { 148 return ''; 149 } 150 151 $transient_key = 'locale-resources-' . $locale->wp_locale; 152 $cache = get_transient( $transient_key ); 153 154 if ( false !== $cache ) { 155 return $cache; 156 } 157 158 $result = get_sites( [ 159 'locale' => $locale->wp_locale, 160 'network_id' => WPORG_GLOBAL_NETWORK_ID, 161 'path' => '/', 162 'fields' => 'ids', 163 'number' => '1', 164 ] ); 165 $site_id = array_shift( $result ); 166 if ( ! $site_id ) { 167 set_transient( $transient_key, '', HOUR_IN_SECONDS ); 168 return ''; 169 } 170 171 switch_to_blog( $site_id ); 172 173 add_filter( 'walker_nav_menu_start_el', 'wporg_add_nav_description', 10, 4 ); 174 175 $menu = wp_nav_menu( [ 176 'theme_location' => 'rosetta_translation_contributor_resources', 177 'fallback_cb' => false, 178 'container' => false, 179 'menu_id' => 'locale-resources', 180 'depth' => 2, 181 'echo' => false, 182 ] ); 183 184 remove_filter( 'walker_nav_menu_start_el', 'wporg_add_nav_description' ); 185 186 restore_current_blog(); 187 188 set_transient( $transient_key, $menu, HOUR_IN_SECONDS ); 189 190 return $menu; 191 } 9 192 10 193 /** … … 51 234 <?php 52 235 } ); 236 237 /** 238 * Prints HTML markup for translation textareas. 239 * 240 * @param object $entry Current translation entry. 241 * @param array $permissions User's permissions. 242 * @param int $index Plural index. 243 */ 244 function wporg_gp_translate_textarea( $entry, $permissions, $index = 0 ) { 245 list( $can_edit, $can_approve ) = $permissions; 246 $disabled = $can_edit ? '' : 'disabled="disabled"'; 247 ?> 248 <div class="textareas<?php echo ( 0 === $index ) ? ' active' : ''; ?>" data-plural-index="<?php echo $index; ?>"> 249 <?php 250 if ( isset( $entry->warnings[ $index ] ) ) : 251 $warnings = $entry->warnings[ $index ]; 252 foreach ( $warnings as $key => $value ) : 253 ?> 254 <div class="warning secondary"> 255 <strong><?php _e( 'Warning:', 'glotpress' ); ?></strong> <?php echo esc_html( $value ); ?> 256 257 <?php if ( $can_approve ) : ?> 258 <a href="#" class="discard-warning" data-nonce="<?php echo esc_attr( wp_create_nonce( 'discard-warning_' . $index . $key ) ); ?>" data-key="<?php echo esc_attr( $key ); ?>" data-index="<?php echo esc_attr( $index ); ?>"><?php _e( 'Discard', 'glotpress' ); ?></a> 259 <?php endif; ?> 260 </div> 261 <?php 262 endforeach; 263 endif; 264 ?> 265 <textarea placeholder="Enter translation here" class="foreign-text" name="translation[<?php echo esc_attr( $entry->original_id ); ?>][]" id="translation_<?php echo esc_attr( $entry->original_id ); ?>_<?php echo esc_attr( $index ); ?>" <?php echo $disabled; // WPCS: XSS ok. ?>><?php echo esc_translation( gp_array_get( $entry->translations, $index ) ); // WPCS: XSS ok. ?></textarea> 266 </div> 267 <?php 268 } 269 270 /** 271 * Counts the number of warnings. 272 * 273 * @param object $entry Current translation entry. 274 * @return int Number of warnings. 275 */ 276 function wporg_gp_count_warnings( $entry ) { 277 $count = 0; 278 279 if ( empty( $entry->warnings ) ) { 280 return $count; 281 } 282 283 foreach ( $entry->warnings as $warnings ) { 284 $count += count( $warnings ); 285 } 286 287 return $count; 288 }
Note: See TracChangeset
for help on using the changeset viewer.