Making WordPress.org


Ignore:
Timestamp:
04/06/2018 10:34:48 PM (9 years ago)
Author:
coreymckrill
Message:

WP15: Add dismissible notice when chosen locale is not 100% translated

This also adds styles to fix a gap beneath the nav bar after it has become
fixed and then the window is scrolled back to the top.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/locales.php

    r7039 r7057  
    5858                'locale-switcher',
    5959                WP_CONTENT_URL . '/mu-plugins/assets/locale-switcher.js',
    60                 array( 'jquery', 'select2' ),
     60                array( 'jquery', 'select2', 'utils' ),
    6161                1,
    6262                true
    … …  
    6969                        'locale' => get_locale(),
    7070                        'dir'    => is_rtl() ? 'rtl' : 'ltr',
     71                        'cookie' => array(
     72                                'expires' => YEAR_IN_SECONDS,
     73                                'cpath'   => SITECOOKIEPATH,
     74                                'domain'  => '',
     75                                'secure'  => true,
     76                        )
    7177                )
    7278        );
    … …  
    149155        wp_enqueue_script( 'locale-switcher' );
    150156}
     157
     158/**
     159 * Prints markup for a notice when a locale isn't fully translated.
     160 */
     161function locale_notice() {
     162        $current_locale = get_locale();
     163        $status         = get_option( 'wp15_locale_status', array() );
     164        $threshold      = 90;
     165        $is_dismissed   = ! empty( $_COOKIE['wp15-locale-notice-dismissed'] );
     166
     167        if ( isset( $status[ $current_locale ] ) && absint( $status[ $current_locale ] ) <= $threshold && ! $is_dismissed ) : ?>
     168                <div class="wp15-locale-notice">
     169                        <p>
     170                                <?php
     171                                printf(
     172                                        wp_kses_post( __( 'The translation for this locale is incomplete. Help us get to 100%% by <a href="%s">contributing a translation</a>.', 'wp15' ) ),
     173                                        esc_url( sprintf(
     174                                                'https://translate.wordpress.org/projects/meta/wp15/%s/default',
     175                                                strtolower( str_replace( '_', '-', $current_locale ) )
     176                                        ) )
     177                                );
     178                                ?>
     179                        </p>
     180                        <button type="button" class="wp15-locale-notice-dismiss">
     181                                <span class="screen-reader-text"><?php _e( 'Dismiss this notice.' ); ?></span>
     182                        </button>
     183                </div>
     184        <?php endif;
     185}
Note: See TracChangeset for help on using the changeset viewer.