How to translate (or edit) validation messages or "Labels" into wordpress plugins?

Asked

Viewed 925 times

0

As an example, I installed a plugin to add an attachment upload field in the Wordpress comments form- https://wordpress.org/plugins/comment-attachment/ How can I change the text in "attachmentRules" and "Choose file" using functions.php in my Child-Theme?

Comment form prtsc with open firebug: https://drive.google.com/file/d/0BwA1IuXMUSGIcG5CenFpMDB4RHM/view?usp=sharing

<!-- HTML começa aqui-->

<p class="comment-form-url comment-form-attachment"><label for="attachment">Adicione um anexo<small class="attachmentRules">&nbsp;&nbsp;(Allowed file types: <strong>jpg, gif, png, pdf, doc, docx</strong>, maximum file size: <strong>2MB.</strong></small></label></p>
<p class="comment-form-url comment-form-attachment"><input id="attachment" name="attachment" type="file"></p>

<!-- HTML termina aqui -->
  • I added some filters in Child-Theme’s functions.php on the wordpress site I’m building, either after research or with the help of plugin authors. However, sometimes I do not find them and I see that I am very limited not knowing how to manipulate these variables in the different plugins that have the Features I need but rarely in English. If anyone can guess indications of how I can become more autonomous in these situations, it would be more valuable than any recipe for any particular situation. In Codecademy is taking some time to master php functions :/

1 answer

0


Every good plugin or Wordpress theme has translation files.

This plugin you are using is no different. Inside the plugin folder is a folder called 'Languages' with two files 'comment-Attachment-de_DE.po' and 'comment-Attachment-de_DE.mo'

The name of these files is divided into 3 parts:

  1. The plugin name 'comment-Attachment'. So Wordpress will know what plugin refers to that file.

  2. The language and country code to which it refers. The first two lower-case letters refer to the tongue and the two capital letters to country.

  3. The file extension . po or .mo. The file . po is the one we edit and the . mo is the one used by Wordpress to load the translation.

Although you can open these files in a text editor, to safely edit the . po files you will need a program. I quote Poedit.

Now just open the file . po with Poedit, change the German to Portuguese translations and save the file as 'comment-Attachment-pt_PT.po'. Poedit will automatically generate a file with the . mo extension in the same directory.

You should then upload the two files 'comment-Attachment-pt_PT.po' and 'comment-Attachment-pt_PT.mo' to the wp-content/Languages/plugins folder. And that’s it! The plugin is translated.

It is important that your Wordpress language is pt_PT as well. For this just change the wp_config.php and add (or change) the line define ('WPLANG', 'pt_PT');.

After making the translation contact the author of the plugin so that he add it to the package.

  • Thanks! I’ve already ventured into the plugin translation. And in the sentences to be translated includes "Allowed File Types", but does not include "Choose File" or "Browse", which is found in the button to search for the file to upload. It also does not include the "No file Chosen" message, which is next to the button. It will be possible to change these texts differently using functions.php or creating a javascript file in my Child-Theme folder?

  • Probably these fields are <input type="file"> tags and the display of this field depends on the language the browser is in. In this case you will need to change with js and css. In fact the most practical way is to hide all the input with css opacity:0 and insert with js the text you want.

Browser other questions tagged

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