Making WordPress.org


Ignore:
Timestamp:
02/22/2022 03:06:29 AM (3 years ago)
Author:
dd32
Message:

Openverse: Update the theme to use path-based localisation.

Props sarayourfriend.
Closes https://github.com/WordPress/wordpress.org/pull/61
Fixes #6195.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/functions.php

    r11217 r11590  
    22
    33namespace WordPressdotorg\Openverse\Theme;
     4
     5use function WordPressdotorg\Locales\get_locales;
    46
    57/**
     
    8486        /* in_footer */ true
    8587    );
     88
     89    $use_path_based_locale_forwarding = get_theme_mod( 'ov_path_based_i18n', false );
     90    $wp_locale = get_locale();
     91    $locale = get_locales()[ $wp_locale ];
     92    $locale_slug = $use_path_based_locale_forwarding && $wp_locale !== 'en_US' ? $locale->slug : '';
     93
    8694    wp_add_inline_script(
    8795        /* handle   */ 'openverse-message',
    8896        /* JS       */ 'const openverseUrl = ' . wp_json_encode( get_theme_mod( 'ov_src_url', OPENVERSE_URL ) ) . ";\n" .
    8997        /* JS       */ 'const openverseSubpath = ' . wp_json_encode( OPENVERSE_SUBPATH ) . ";\n" .
    90         /* JS       */ 'const currentLocale = ' . wp_json_encode( get_locale() ) . ";\n",
     98        /* JS       */ 'const currentLocale = ' . wp_json_encode( $wp_locale ) . ";\n" . /* Used for legacy cookie based locale forwarding */
     99        /* JS       */ 'const localeSlug = ' . wp_json_encode( $locale_slug ) . ";\n",
    91100        /* position */ 'before'
    92     ); 
     101    );
    93102
    94103    wp_enqueue_script(
     
    161170        )
    162171    ) );
     172
     173    $wp_customize->add_setting( 'ov_path_based_i18n', array(
     174        'type' => 'theme_mod',
     175        'capability' => 'edit_theme_options',
     176        'default' => false
     177    ) );
     178
     179    $wp_customize->add_control( 'ov_path_based_i18n', array(
     180        'section' => 'ov_embed',
     181        'type' => 'checkbox',
     182        'id' => 'ov_path_based_i18n',
     183        'label' => 'Use path based locale forwarding',
     184        'priority' => 10
     185    ) );
    163186}
    164187add_action( 'customize_register', __NAMESPACE__ . '\wporg_ov_customizer' );
Note: See TracChangeset for help on using the changeset viewer.