Skip to content

Commit

Permalink
Follow Widget: load translation files using wpcom language codes.
Browse files Browse the repository at this point in the history
Related: #2698

The widget previously used the site's language code to populate the `data-lang` parameter.
that parameter is used to grab language files from WordPress.com, and should consequently use a language code that's available on
WordPress.com.

We consequently use the data available in locales.php to use the `slug` language code instead of `wp_locale` for each language.
  • Loading branch information
jeherve committed Dec 19, 2016
1 parent 39ef9cf commit 125cc90
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion modules/widgets/follow-button.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ public function widget( $args, $instance ) {
$attributes = array();
$instance = wp_parse_args( (array) $instance, array( 'show_name' => 1, 'show_count' => 0 ) );

$wpcom_locale = get_locale();

if ( ! class_exists( 'GP_Locales' ) ) {
if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
require JETPACK__GLOTPRESS_LOCALES_PATH;
}
}

if ( class_exists( 'GP_Locales' ) ) {
$wpcom_locale_object = GP_Locales::by_field( 'wp_locale', get_locale() );
if ( $wpcom_locale_object instanceof GP_Locale ) {
$wpcom_locale = $wpcom_locale_object->slug;
}
}

if ( empty( $instance['show_name'] ) ) {
$attributes[] = 'data-show-blog-name="false"';
}
Expand All @@ -41,7 +56,7 @@ public function widget( $args, $instance ) {
class="wordpress-follow-button"
href="<?php echo esc_url( home_url() ); ?>"
data-blog="<?php echo esc_url( home_url() ); ?>"
data-lang="<?php echo get_locale(); ?>" <?php if ( ! empty( $attributes ) ) echo implode( ' ', $attributes ); ?>
data-lang="<?php echo esc_attr( $wpcom_locale ); ?>" <?php if ( ! empty( $attributes ) ) echo implode( ' ', $attributes ); ?>
>
<?php sprintf( __( 'Follow %s on WordPress.com', 'jetpack' ), get_bloginfo( 'name' ) ); ?>
</a>
Expand Down

0 comments on commit 125cc90

Please sign in to comment.