Hello Summer Sale!
Exclusive season-opening discount on TheGem theme.
Limited time offer.

Okay
  Public Ticket #1505851
Author Box Translation WPML + TheGem
Closed

Comments

  •  2
    Natethenomad started the conversation

    I want to inform you that the translation of your Author Box with WPML is not working properly. I contacted WPML and they fixed the problem. The WPML team and I tried a lot of things before until we noticed that it has to be the theme. However, I want to let you know what code they had to put into the Theme in order to make this work.

    Here is the instructions they gave me:

    In \wp-content\themes\thegem\inc\content.php change line 619, change:

    <div class="name title-h5"><?php echo $user_data->data->display_name; ?> <span class="light"><?php esc_html_e('/ About Author', 'thegem'); ?></span></div>

    TO

    <div class="name title-h5"><?php echo apply_filters( 'wpml_translate_single_string', $user_data->data->display_name, 'Authors', 'display_name_'.$user_id ); ?> <span class="light"><?php esc_html_e('/ About Author', 'thegem'); ?></span></div>

    And in the same file line 621:

    <div class="post-author-description"><?php echo $user_data->description; ?>

    change it to:

    <div class="post-author-description"><?php echo apply_filters( 'wpml_translate_single_string', $user_data->description, 'Authors', 'description_'.$user_id ); ?></div>

    Then the translation via String Translation works (after input translation and clearing cache). I would very appreciate if you can implement this in the next Theme Update. You call the theme translation-ready and made me use WPML because "WPML is the only supported translation plugin". Then, please fix this issue.

  • [deleted] replied

    We checked wordpress documentation.

    Correct use of the author's fields is this https://codex.wordpress.org/Function_Reference/the_author_meta or this - https://developer.wordpress.org/reference/functions/get_the_author_meta/.

    Thereby we can change our code like this (and we did it for next theme update):

                <div class="post-author-info">
                    <div class="name title-h5"><?php the_author_meta('display_name', $user_id); ?> <span class="light"><?php esc_html_e('/ About Author', 'thegem'); ?></span></div>
                    <div class="post-author-description"><?php echo do_shortcode(nl2br(get_the_author_meta('description', $user_id))); ?></div>
                    <div class="post-author-posts-link"><a href="<?php echo esc_url(get_author_posts_url( $user_id )); ?>"><?php printf(esc_html__('More posts by %s', 'thegem'), $user_data->data->display_name); ?></a></div>
                </div>

    If you want to use something else you need to create your own author box function and use it in templates.

    This method "wpml_translate_single_string" is not good because it will not work with other translation plugins. But if you use the_author_meta and get_the_author_meta functions then you can use next hooks "get_the_author_{$field}" and "the_author_{$field}".

  •  2
    Natethenomad replied

    Thanks for the thorough response. I just wanted to inform you that the translation of the author box (the one I can enable via Theme Options) is not working at the moment and that the WPML team helped me to fix this. Basically, I was just the informant. If you can make it work with the next theme update, it would be highly appreciated :) The code WPML implemented will be overwritten with the next update anyways.