Translate Wordpress strings from Portuguese to English

Asked

Viewed 544 times

3

I am with a Wordpress installation in en en and have searched numerous forms of theme translation, strings but none has worked out. Most take a theme that the default is English and I translate into Portuguese.

I needed to "translate" some custom strings from the Portuguese to English menu, I even used wpml but totally messed up my theme. Does anyone have any simpler idea how to translate in hand?

  • Already tried to edit the files directly?

  • @Amandalima, I tried it with poedit (I don’t know if this is it directly), but it doesn’t find my custom strings

  • 1

    Take a look here on this question. If the theme is prepared for "Localization", this solution will help you. Otherwise, the only solution is as @Amandalima said, change the strings in the files themselves.

  • 1

    @haykou, if there are few strings you need to translate, open the Wordpress file with any text editor (Notepad++ in the case of Windows, Gedit in the case of Linux), look for the string and replace it with the translated word.

  • The ideal would be to show an example of how this theme is.

2 answers

3

I did not find a more practical solution, I switched the strings manually even, as the ? lang Wordpress, follows my solution:

 <?php 
              $mylocale = get_bloginfo('language'); //Pega o lang padrão do tema
              if($mylocale == 'pt-BR') { ?>
             <p>Palavra em português</p>
<?php }
             elseif($mylocale == 'en-US'){ ?>

             <p>Palavra em inglês</p>

<?php }
?>
  • Good tip! + 1! :) Only rearrange the code differently to avoid opening and closing the tag <?php ?> several times to make output HTML code, which is unnecessary because you can in this way.

2


The default solution in Wordpress for translations is Internationalization. You prepare your theme/plugin so that it can receive different translations. Basically, you embrace your strings text in methods that WP itself provides. Documentation

$hello =  __( 'Hello, dear user!', 'my-text-domain' );

The method __(), in addition to assigning the value Hello, Dear user! for the variable, also adds it to the domain my-text-Domain. If you need to do echo within your code, you use the method _e(), as follows:

_e( 'Using this option you will make a fortune!', 'my-text-domain' );

After having all your code prepared, with the strings within a domain, you need to generate a file .pot which will contain all the strings internationalized of your code. When I need to do this, I use the Easypo.

In possession of the file .pot, you can use the Poedit to translate all the strings and generate a new domain. Then just set the locale and everything must work. This process makes VERY MUCH easier maintenance of translations.

Here and here you can read (in English) two excellent articles on how to internationalize your theme/plugin. Also have an interesting discussion on this here

  • ended up needing to translate another part and used qtranslator X with _e() and it was much better than the if I did, which served only in a single case

Browser other questions tagged

You are not signed in. Login or sign up in order to post.