Making WordPress.org


Ignore:
Timestamp:
09/04/2023 01:30:28 PM (3 years ago)
Author:
amieiro
Message:

Translate: Sync gp-translation-helpers with GitHub

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers/helper-other-locales.php

    r11837 r12874  
    3333
    3434        /**
     35         * Indicates the related locales for each locale, so we will put them in the top list
     36         * of "Other locales".
     37         *
     38         * This array should be sync with
     39         * https://github.com/WordPress/wordpress.org/blob/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/routes/class-other-languages.php
     40         *
     41         * @since 0.0.1
     42         * @var array
     43         */
     44        public array $related_locales = array(
     45                'gl' => array( 'es', 'pt', 'pt-ao', 'pt-br', 'ca', 'it', 'fr', 'ro' ),
     46                'es' => array( 'gl', 'ca', 'pt', 'pt-ao', 'pt-br', 'it', 'fr', 'ro' ),
     47        );
     48
     49        /**
    3550         * Activates the helper.
    3651         *
     
    6782                }
    6883
    69                 $translations           = GP::$translation->find_many_no_map(
     84                $translations                           = GP::$translation->find_many_no_map(
    7085                        array(
    7186                                'status'      => 'current',
     
    7388                        )
    7489                );
    75                 $translations_by_locale = array();
     90                $translations_by_locale                 = array();
     91                $translations_by_locale_with_preference = array();
    7692                foreach ( $translations as $translation ) {
    7793                        $_set = GP::$translation_set->get( $translation->translation_set_id );
     
    84100                ksort( $translations_by_locale );
    85101
    86                 return $translations_by_locale;
     102                // Put the variants in the top list.
     103                foreach ( $translations_by_locale as $key => $translation ) {
     104                        // phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
     105                        if ( explode( '-', $key )[0] === explode( '-', $this->data['locale_slug'] )[0] ) {
     106                                $translations_by_locale_with_preference[ $key ] = $translation;
     107                                unset( $translations_by_locale[ $key ] );
     108                        }
     109                }
     110
     111                // Put the related locales in the top list, after the variants.
     112                if ( ! empty( $this->related_locales[ $this->data['locale_slug'] ] ) ) {
     113                        foreach ( $this->related_locales[ $this->data['locale_slug'] ] as $locale ) {
     114                                if ( array_key_exists( $locale, $translations_by_locale ) ) {
     115                                        $translations_by_locale_with_preference[ $locale ] = $translations_by_locale[ $locale ];
     116                                        unset( $translations_by_locale[ $locale ] );
     117                                }
     118                        }
     119                }
     120
     121                return array_merge( $translations_by_locale_with_preference, $translations_by_locale );
    87122        }
    88123
Note: See TracChangeset for help on using the changeset viewer.