Alright, let me explain it in detail.
We use the program PoEdit to translate our strings. It’s important to understand that PoEdit only translates the strings that are hardcoded in the code, that means variables like __($detail)
won’t be recognized as a string.
We can fix that by hardcoding our strings manually. The easiest (but not the nicest) way to do this is by opening any any .php file inside the IMDb Connector directory and add the following code anywhere (this is an example for translating the genres):
$imdb_connector_french = array(
__("Romance", "imdb_connector"),
__("Comedy", "imdb_connector"),
__("Action", "imdb_connector")
);
Note that the parameter “imdb_connector” is not the translated string but the textdomain which is like an unique ID that tells IMDb Connector to load its translation file.
Now, download the French .po project file from Transifex and move it into the plugin’s /languages/ directory. Rename it to “imdb_connector-fr_FR.po”.
Install PoEdit and open the moved .po file with it. In PoEdit, hit “Refresh” in the toolbar. A window should popup with our added strings in it. Click “OK”.
Find the strings in the list and translate them. When you’re done, press CTRL + S. This will overwrite the existing .mo translation the plugin will load on startup.
The last thing we need to do is wrapping our output strings into either __()
or _e()
. Here’s one example:
Genre de film: <?php _e(get_imdb_connector_movie_detail("Apocalypse Now", "genre"), "imdb_connector"); ?>
It’s important to always add the “imdb_connector” textdomain to the two functions, otherwise it won’t be translated. Also, make sure that your WordPress installation must use the same language as the translation you want to output. You can change that in the “Settings” section in the admin interface.
IMPORTANT: As I said, this is not the best solution because whenever there’s an update for IMDb Connector, your existing translations will be lost. To avoid that, always backup your imdb_connector-fr_FR.po, for example in the /wp-content/languages/ directory so you can always re-compile the translation file (.mo) and replace it with the existing one. Maybe I’ll add the detail strings later on manually to the code to make it easier for others to translate it.