Making WordPress.org

Changeset 11590


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.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse
Files:
4 edited

Legend:

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

    r11559 r11590  
    44mu-plugins/
    55vendor/
     6wporg_locales.sql
  • 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' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/iframe_nav.js

    r11466 r11590  
    66    .replace(openverseSubpath, '')
    77    .replace(/^\/$/, ''); // Remove Openverse site subpath
    8   iframePath = `${openverseUrl}${iframePath}${query}`; // Add domain and query
     8  const localePart = localeSlug
     9    ? openverseUrl.endsWith('/')
     10      ? localeSlug
     11      : `/${localeSlug}`
     12    : '';
     13  iframePath = `${openverseUrl}${localePart}${iframePath}${query}`; // Add domain and query
    914
    1015  console.log(`Navigating iframe to ${iframePath}`);
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-openverse/js/message.js

    r11466 r11590  
    1212function updatePath(value) {
    1313  const path = value.path;
    14   const url = `${openverseSubpath}${path}`; // openverseSubpath defined in `index.php`
     14  let url = `${openverseSubpath}${path}`; // openverseSubpath defined in `index.php`
     15  if (localeSlug) {
     16    url = url.replace(`openverse/${localeSlug}`, 'openverse');
     17  }
    1518
    1619  console.log(`Replacing state URL: ${url}`);
Note: See TracChangeset for help on using the changeset viewer.