@boborg I’ve found a solution. It’s not the best since you have to translate the genres manually, but at least it works. First off, here’s the code:
/**
* @param array $movie_details
*
* @return array
*/
function imdb_connector_translate_genres_manually(array $movie_details) {
if(!isset($movie_details["genres"])) {
return $movie_details;
}
$translated_genres = array(
"Crime" => "Krimi"
);
$genres = $movie_details["genres"];
$indexes = count($genres) - 1;
for($round = 0; $round <= $indexes; $round++) {
if(array_key_exists($genres[$round], $translated_genres)) {
$movie_details["genres"][$round] = $translated_genres[$genres[$round]];
}
}
return (array)$movie_details;
}
add_filter("imdb_connector_movie_details", "imdb_connector_translate_genres_manually");
As you can see, this function makes use of the movie details filter, which means it manipulates the output (shortcodes use this output). You can translate genres like this:
- Place the code into the functions.php file of your active theme
- Add translations to the
$translated_genres
array as seen in the example (first item is the English version, the second item is the translation)
That’s it. The genres should now be replaced with the string inside the array. Please let me know if you encounter any problems.
For the next version, I thought about adding the genres to the translation files (which are being translated by the WordPress community) and insert an option whether the user would like the genres to be translated or not. Do you think this would be a useful feature?
-
This reply was modified 7 years, 6 months ago by
thaikolja.
-
This reply was modified 7 years, 6 months ago by
thaikolja.