[Resolved] Display different authot's name translations depending on language version

Home Forums Support [Resolved] Display different authot's name translations depending on language version

Home Forums Support Display different authot's name translations depending on language version

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1272580
    Oleksiy

    Hi, guys,
    Could you please help me with the following problem.
    I’d like to dislay different translations of the author’s name across different language versions. Because it actually has a different spelling. Including Cyryllic.

    First of all I use the code from here https://docs.generatepress.com/article/generate_post_author_output/ to remove a link. After this I use the following code:

    add_filter( 'generate_post_author_output', 'alex_translate_name' );
    	function alex_translate_name() {
    		if (get_locale() == 'ru_RU') {		
    			return 'My name in Russian';
    		}	
    		if (get_locale() == 'uk') {
    			return 'My name in Ukrainian';	
    		}
    		if (get_locale() == 'en_US') {
    			return 'My name in English';	
    		}  
    	}  
    

    or this one just to check:

    
    add_filter( 'generate_post_author_output', function( $output ) {    
        return 'My name in Ukrainian';
    } );
    

    Result is the same. One more author’s name is being added to the already displayed. No replacement.
    It’s at the end of the post.

    How can I fix it?

    #1272928
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It shouldn’t be appending to the existing author – make sure you’re not using another function with the same filter.

    You should be able to do this:

    add_filter( 'generate_post_author_output', function( $output ) {
        $author_name = 'Your name';
    
        if (get_locale() == 'ru_RU') {		
            $author_name = 'Your name in Russian.
        }
    
        return sprintf( '<span class="byline">%1$s<span class="author vcard" %5$s><a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span></span> ',
            apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            /* translators: 1: Author name */
            esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), $author_name ) ),
            $author_name,
            generate_get_microdata( 'post-author' )
        );
    } );
    #1273358
    Oleksiy

    Hi, Tom

    update: looks like at last I fixed it. Thanks. Your solution helped to update mine.
    But I leave the text below to explain what exactly code above is actually doing. In case if somebody is searching exactly for this.

    Language versions are working. But avatar disappeared, “author” word is visible, and a link to all author’s posts is present.

    #1274133
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.