Changeset 13051
- Timestamp:
- 12/12/2023 11:29:38 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-other-languages.php
r8761 r13051 9 9 10 10 class Other_Languages extends GP_Route { 11 12 /** 13 * Indicates the related locales for each locale, so we will put them in the top list 14 * of "Other locales". 15 * 16 * This array should be sync with 17 * https://github.com/GlotPress/gp-translation-helpers/blob/main/helpers/helper-other-locales.php 18 * 19 * @var array 20 */ 21 public array $related_locales = array( 22 'ca' => array( 'ca-val', 'bal', 'es', 'oci', 'an', 'gl', 'fr', 'it', 'pt', 'ro', 'la' ), 23 'es' => array( 'gl', 'ca', 'pt', 'pt-ao', 'pt-br', 'it', 'fr', 'ro' ), 24 'gl' => array( 'es', 'pt', 'pt-ao', 'pt-br', 'ca', 'it', 'fr', 'ro' ), 25 'it' => array( 'ca', 'de', 'es', 'fr', 'pt', 'ro' ), 26 'ne' => array( 'hi', 'mr', 'as' ), 27 'oci' => array( 'ca', 'fr', 'it', 'es', 'gl' ), 28 'ug' => array( 'tr', 'uz', 'az', 'zh-cn', 'zh-tw' ), 29 ); 11 30 12 31 public function get_suggestions( $project_path, $locale_slug, $translation_set_slug ) { … … 39 58 $suggestions = $this->query( $original, $translation_set ); 40 59 41 wp_send_json_success( gp_tmpl_get_output( 'other-languages-suggestions', [ 'suggestions' => $suggestions ], PLUGIN_DIR . '/templates/' ) );60 wp_send_json_success( gp_tmpl_get_output( 'other-languages-suggestions', array( 'suggestions' => $suggestions ), PLUGIN_DIR . '/templates/' ) ); 42 61 } 43 62 … … 78 97 ); 79 98 80 return $results; 99 $results_with_preference = array(); 100 101 // Put the variants in the top list. 102 foreach ( $results as $key => $result ) { 103 if ( explode( '-', $result['locale'] )[0] === explode( '-', $set_to_exclude->locale )[0] ) { 104 $results_with_preference[] = $result; 105 unset( $results[ $key ] ); 106 } 107 } 108 109 if ( ! empty( $this->related_locales[ $set_to_exclude->locale ] ) ) { 110 foreach ( $this->related_locales[ $set_to_exclude->locale ] as $locale ) { 111 foreach ( $results as $key => $result ) { 112 if ( $result['locale'] == $locale ) { 113 $results_with_preference[] = $result; 114 unset( $results[ $key ] ); 115 continue 2; 116 } 117 } 118 } 119 } 120 121 return array_merge( $results_with_preference, $results ); 81 122 } 82 123 }
Note: See TracChangeset
for help on using the changeset viewer.