How to translate header and footer texts in WordPress

Translating the sites title or tagline is often quite easy when using a plugin like Polylang. Just update the text on the strings translation settings page.

 

But what if there is more content that needs to be translated?

Find out where the content is coming from

The headers and footers are defined by your theme. They can be composed of several different parts. Usually these are menus, widgets, images and texts.

If the text to be translated is part of a menu/navigation, you’ll need to define or change the corresponding menu. You’ll find the menus under Appearance->Menus.

If the text to be translated is part of a widget, you can make use of the language visibility setting. Duplicate the widget for each language and always specify for which language it should be displayed.  You’ll find the widget settings under Appearance->Widgets.

If the texts to be translated are not part of a widget nor menu, you’ll need to have a closer look at the theme and its code.

 

Make sure the theme and content is translatable

A theme must be setup correctly in order to be able to translate its content. It must define and load a text domain and use localisation functions to get the translations. You won’t be able to translate the content unless this is the case. So first, check that your theme is translatable. You can find a handbook on how to internationalize a theme here: Internationalization.

You’ll need to check the code to be sure that the content is translatable.  Usually the header and footer content is defined in a header.php respectively footer.php file. Open the files and locate the content that needs to be translated.

<footer>
    <p>This is some text that needs to be translated!</p>
</footer>

The text in above example is not translatable. This code should be changed so that it gets the translations by calling a localisation function.

<footer>
    <p><?php _e('This is some text that needs to be translated!'); ?></p>
</footer>

 

Translate a theme

The translations of a theme are saved as PO (Portable Object) files. First you need to find out where those files are located. One of most used locations is in a languages folder inside the themes root directory. If there is no languages folder, you can check the load_theme_textdomain or load_child_theme_textdomain call in the functions.php file.

load_child_theme_textdomain('my-theme', get_template_directory().'/langs' );

It should pass a path as second parameter. In above example the PO files are found in the themes root directory inside a langs folder.

Once you found the location you can create PO files for the target languages. The file should be named by following format:  {text-domain}-{locale}.po. You can find a handbook on how to create PO files here: Localization

Simplest way to get the PO files with the translations is to order the translations on our website with the POT file. Generating a POT file with Poedit is described here: Poedit.

 

translate.wordpress.org

Newer themes may use https://translate.wordpress.org/ as translation tool. In this case the  translations are managed online. WordPress downloads the PO files automatically and saves them in the WordPress theme language folder under/wp-content/languages/themes/.




Ähnliche Beiträge


Leave a Reply

Your email address will not be published. Required fields are marked *



*