Making WordPress.org

Changeset 7057


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.

Location:
sites/trunk/wp15.wordpress.net/public_html/content
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wp15.wordpress.net/public_html/content/mu-plugins/assets/locale-switcher.js

    r6941 r7057  
    1 
    2 ( function( window, $ ) {
     1/* global wpCookies */
     2( function( window, $, wpCookies ) {
    33
    44        'use strict';
    … …  
    1010                $switcher: $(),
    1111
     12                $notice: $(),
     13
    1214                init: function() {
    1315                        app.$switcher = $( '#wp15-locale-switcher' );
     16                        app.$notice   = $( '.wp15-locale-notice' );
    1417
    1518                        app.$switcher.select2( {
    … …  
    2124                                $(this).parents( 'form' ).submit();
    2225                        } );
     26
     27                        app.$notice.on( 'click', '.wp15-locale-notice-dismiss', function( event ) {
     28                                event.preventDefault();
     29                                app.dismissNotice();
     30                        } );
     31                },
     32
     33                dismissNotice: function() {
     34                        app.$notice.fadeTo( 100, 0, function() {
     35                                app.$notice.slideUp( 100, function() {
     36                                        app.$notice.remove();
     37                                });
     38                        });
     39
     40                        wpCookies.set(
     41                                'wp15-locale-notice-dismissed',
     42                                true,
     43                                app.cookie.expires,
     44                                app.cookie.cpath,
     45                                app.cookie.domain,
     46                                app.cookie.secure
     47                        );
    2348                }
    2449        } );
    … …  
    2853        } );
    2954
    30 } )( window, jQuery );
     55} )( window, jQuery, wpCookies );
  • 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}
  • sites/trunk/wp15.wordpress.net/public_html/content/themes/twentyseventeen-wp15/header.php

    r7031 r7057  
    4343                <div class="site-content-contain">
    4444                        <div id="content" class="site-content">
     45
     46                                <?php Locales\locale_notice(); ?>
  • sites/trunk/wp15.wordpress.net/public_html/content/themes/twentyseventeen-wp15/style.css

    r7056 r7057  
    6363}
    6464
     65.site-header:before,
     66.site-header:after {
     67        content: none;
     68}
     69
    6570@supports( display: grid ) {
    6671        .site-header {
    … …  
    302307}
    303308
     309.wp15-locale-notice {
     310        background: #fafafa;
     311        margin-bottom: 5px;
     312        padding: 1px 38px 1px 12px;
     313        position: relative;
     314        text-align: center;
     315}
     316
     317.wp15-locale-notice p {
     318        margin: 0.5em 0;
     319        padding: 2px;
     320}
     321
     322.wp15-locale-notice-dismiss:before {
     323        background: none;
     324        color: #333;
     325        content: "\f153";
     326        display: block;
     327        font: normal 16px/20px dashicons;
     328        speak: none;
     329        margin: 0.5em 0;
     330        height: 20px;
     331        text-align: center;
     332        width: 20px;
     333        -webkit-font-smoothing: antialiased;
     334        -moz-osx-font-smoothing: grayscale;
     335}
     336
     337.wp15-locale-notice-dismiss {
     338        position: absolute;
     339        top: 0;
     340        right: 1px;
     341        border: none;
     342        margin: 0;
     343        padding: 7px;
     344        background: none;
     345        color: #333;
     346        cursor: pointer;
     347}
     348
     349.wp15-locale-notice-dismiss:hover,
     350.wp15-locale-notice-dismiss:active,
     351.wp15-locale-notice-dismiss:focus {
     352        background: inherit;
     353}
     354
     355.wp15-locale-notice-dismiss:hover:before,
     356.wp15-locale-notice-dismiss:active:before,
     357.wp15-locale-notice-dismiss:focus:before {
     358        color: #0073AA;
     359}
     360
     361.wp15-locale-notice-dismiss:focus {
     362        outline: none;
     363}
     364
     365.ie8 .wp15-locale-notice-dismiss:focus {
     366        outline: 1px solid #5b9dd9;
     367}
    304368
    305369/*
Note: See TracChangeset for help on using the changeset viewer.