Translate titles of sections on the home page

@fabe … be careful with your update. I think when I did mine is when the language translation stopped working. I’ve been trying for days to use the PO file and also the methods that you discuss. Maybe they are overriding each other.

If you happen to update with success, can you please notify the forum…thanks.

Also, what forum software do you use for this forum?

Thanks

@fabe @laranz
OK…so dummy me. Fabe I see what you are saying and it is really easy using the method you describe and much easier than using wordpress to alter the PHP code and then using PO & MO files. The reason is that the Polylang plugin has a admin interface where you can input the strings for each language.

To Recap:
So, as discussed in this forum you must add the code and similar to this in the functions file
pll_register_string( 'Button', get_theme_mod( 'illdy_jumbotron_general_first_button_title', __( 'Learn more', 'illdy-child' ) ), 'illdy-child' );

Then you must put onto your page something like this to print out the information from the Polylang string replacement.

 <div class="col-sm-12">
							 <h3><?php echo illdy_sanitize_html( pll_e( $jumbotron_title ) ); ?></h3>
						  </div><!--/.col-sm-12-->

  1. THE MOST IMPORTANT STEP WHICH I MISSED
    You must log into the Wordpress admin and then go to the language menu item and edit the string translations
    Once you add the string translations to the functions.php, they will show up in the admin/string translations page. Then there, you will the newly added strings.

Thanks for your guidance.

Exactly @storlab . Also I do not understand why the modifications haven’t been added to theme updates, since it would be extremely easy to do so, and have users translate their themes with polylang @laranz.

Hi @storlab,

Yes exactly :slight_smile: great you finally found the issue, each ML plugin have their string translations module.

Hi @rolandsguesthouse, What do you mean by that, I didn’t get your question. That is the default feature of any ML plugin, each has their own way of string translations.

Let us know,

Thanks,
laranz.

Hi @rolandsguesthouse @storlab @laranz,

I’ve just updated illdy theme without any issues. It works perfectly with my method. I didn’t lost anything with my child theme. You can update without fear.
Have a nice weekend. :wink:

Regards,

Fabe

Hi @rolandsguesthouse,
Would you be so kind to help me how did you create a “Section” folder withing the child theme folder?

Thanks, Dora

Hi @rolandsguesthouse,

Thank you all for sharing this solution. If I understand correctly, the goal is to make each element available on Polylang under Language > Strings Translation to be able to translate everything.

I have followed each of the steps detailed by @rolandsguesthouse and still don’t arrive to figure this out. I created the Child Theme with styles.css and the funtions.php files and ‘sections’ folder under it where I copied the front-page-bottom-header.php and modified it following your instructions. I started by adding only the First Button modifications in order to narrow the testing.

Since I cannot see what the code for the first_button is meant to look like in the php file in the previous post, I am guessing my problem might be there.

My functions.php and my front-page-bottom-header.php are currently as follows:

front-page-bottom-header.php


if ( $jumbotron_title || $entry || $first_button_title || $second_button_title ) {

	?>
	<div class="bottom-header front-page">
		<div class="container">
			<div class="row">
				<?php if ( $jumbotron_title ) : ?>
					<div class="col-sm-12">
						<h1><?php echo $jumbotron_title; ?></h1>
					</div><!--/.col-sm-12-->
				<?php endif; ?>
				<div class="col-sm-8 col-sm-offset-2">
					<?php if ( $entry ) : ?>
						<div class="section-description"><?php echo do_shortcode( wp_kses_post( $entry ) ); ?></div>
					<?php endif; ?>
					<?php if ( $first_button_title ) : ?>
						<a href="<?php echo esc_url( $first_button_url ); ?>" title="<?php echo esc_attr( $first_button_title ); ?>" class="header-button-one"><?php echo esc_html( pll_e( $first_button_title ) ); ?></a>
					<?php endif; ?>
					<?php if ( $second_button_title ) : ?>
						<a href="<?php echo esc_url( $second_button_url ); ?>" title="<?php echo esc_attr( $second_button_title ); ?>" class="header-button-two"><?php echo esc_html( $second_button_title ); ?></a>
					<?php endif; ?>
				</div><!--/.col-sm-8.col-sm-offset-2-->
			</div><!--/.row-->
		</div><!--/.container-->
	</div><!--/.bottom-header.front-page-->

functions.php


<?php
add_action( 'wp_enqueue_scripts', function() {
    //* Parent CSS
    wp_enqueue_style( 'illdy', 
      get_template_directory_uri() . '/style.css' );

    //* Child CSS
    wp_enqueue_style( 'illdy-child', 
      get_stylesheet_directory_uri() . '/style.css', [ 'illdy' ] );
} );

pll_register_string( ‘First Button’, get_theme_mod( ‘illdy_jumbotron_general_first_button_title’, __( ‘Learn more’, ‘illdy’ ) ), ‘illdy’ );


What am I doing wrong?

Thanks!

I seem to have the same problem…
The described solution doesn’t work for me :frowning:
The string shows up in the translation section after modifying the functions.php but it has no effect on the site. I believe because I changed the content of the three word title and description in the customizer and I’m not able to load the demo content again.
Any ideas on how to proceed?
Thank you very much for your support!
Love
Jonathan

@laranz I think your help is urgently needed here. I got my theme to work, but it’s really more complicated than what I really understand, and people need your help. As far as I remember if some php files would be updated to work with polylang from sides of colorlib it would save everybody a lot of headache. Any help here? Thank you @laranz

Hi…I can try to help.

1.) Do you have polylang plugin installed?
2.) Have you added the codes to the functions.php file?
3.) Then you need to login to the Wordpress admin, and edit the string translations. These can be edited in the admin area, after a new link is added for /languages/translations.
4.) Have you added a menu item to switch between languages? I used english, and mandarin so I have a link on the menu to switch between these languages.

It was a little confusing for me because there are multiple ways to have the system modify the languages. I don’t feel that you need to edit the specific page for the translation. It will be done automatically by the polylang.

Have you tried these steps?

Also…just to add…the string translations work like this…

“apple” replaced to “orange” So the example here is that they text you are replacing has to be exact in what you are attempting to replace. So double check these. Because this works, but it’s a little tricky.

For example, I had an article, that I wanted to replace text in. And you need to add this text into the functions page, and also then into the string translations page. Once these are perfected added in both spots, then the translation will occur.

Finally, the string translation is done by brute force…and by this I mean that it will replace any string translation that matches what you are attempting to convert.

I do manage to have all the strings show up in the string translation section. However, it doesn’t have any effect on the page - when I switch to English it still shows the German translation… any ideas on what to do?

Hi…

If you want to replace this text…

<?php if ( $first_button_title ) : ?>
						<a href="<?php echo esc_url( $first_button_url ); ?>" title="<?php echo esc_attr( $first_button_title ); ?>" class="header-button-one"><?php echo esc_html( pll_e( $first_button_title ) ); ?></a>
					<?php endif; ?>

Then you will need to make sure that the text used within the Wordpress Admin matches the text exactly that you use in the functions.php. So, from FABE’s example above.

pll_register_string( 'Contact-us', get_theme_mod( 'illdy_contact_us_general_title', __( 'Contact us', 'illdy' ) ), 'illdy' );'

php if( $general_title ): ?>
						<div class="col-sm-12">
							<h3><?php echo illdy_sanitize_html( pll_e( $general_title ) ); ?></h3>
						</div><!--/.col-sm-12-->
					<?php endif; ?>

The text in this example is “Contact Us”, and this text needs to match exactly what is used within the admin area where the theme is edited. The General Title within the theme editing area also needs to read “Contact Us” exactly! If it is slightly different with a capital, or an extra white space it is not exact, and therefore will not work. This is essential for the replacement to occur.

After this, you will need to match the text in the string replacement, with the text for the Two languages you are using…I think German and English.

Does this make sense?

Hi everyone,

let me join this issue. I am using illdy theme.

For me the process of making changes to the functions.php and sections files described by @fabe remains unclear.

a) Can i ask anyone who managed to solve the issue to describe it step by step for dummies without php background (like an example for one of the sections) attaching the php code

b) Do I definitely have to use a child theme for the described process? Or a backup will be enough?

As i understood, i had to create the child theme BEFORE building the site. And in case of creating the child theme AFTER the site is already built, there gonna be additional things to fix to get the site to look like the original. (My case).

Thanks in advance for Your answers!

First child theme…The child theme does two main things;

1.) It allows you to modify theme files without them being overwritten the next time wordpress updates the core and the theme. One of the great things about WP is how easily and quickly it updates both the theme files and the core files. So, if you make changes in the functions.php file in a non-child theme…all of those changes will be lost the next time you update the theme. If if by accident, they can be lost forever.

  1. It allows a novice to see and know easily what code they have worked on and quickly find the broken code.

To setup a child theme…it is generally easy…especially if you haven’t modified and PHP files by hand yet.

Your best bet is to follow these instructions:

https://codex.wordpress.org/Child_Themes

If you don’t have any idea on what to do from this tutorial page, then you may need to hire a professional to help you along the way.

Hey @storelab,
thank you so much for your help - also to everyone else who contributed!
I managed to get it done!
Have a beautiful day!
Warmly
Jonathan

@jonathank Can i ask you please for instructions?

Hi guys,

I receive several mails for translation problem. If something it’s not clear let me know.

Cheers,

I followed the instruction from storelab (see post from November 21, 2017 at 8:14 am).
That’s what worked for me.
Good luck!

@fabe, @storelab, Thank you for help, now it works fine for me too.

Best wishes