Skip to content

Instantly share code, notes, and snippets.

@jstask82
Last active October 30, 2023 15:33
Show Gist options
  • Save jstask82/fff0112c6ead289b4b16a01e1b7af46a to your computer and use it in GitHub Desktop.
Save jstask82/fff0112c6ead289b4b16a01e1b7af46a to your computer and use it in GitHub Desktop.
function translations()
{
add_filter(
"get_term",
function ($term, $tax) {
if (is_admin()) {
return $term;
}
$fixes = [
"fix" => [
[
"taxonomy" => "event-type",
"mappings" => [["reccuring", __("Wiederkehrend", NAME_SPACE)], ["single", __("Einzel", NAME_SPACE)]],
],
],
];
foreach ($fixes["fix"] as $fix) {
$text = [];
if ($fix["taxonomy"] === $tax) {
foreach ($fix["mappings"] as $map) {
$text[$map[0]] = $map[1];
}
return $text[$term->name];
}
}
return $term;
},
10,
2
);
add_filter(
"gettext",
function ($translated, $untranslated, $domain) {
$fixes = [
"fix" => [
[
"text_domain" => NAME_SPACE,
"mappings" => [["recurring", "Wiederkehrend"], ["single", "Einzel"]],
],
],
];
foreach ($fixes["fix"] as $fix) {
$text = [];
if ($fix["text_domain"] === $domain) {
foreach ($fix["mappings"] as $map) {
$text[$map[0]] = $map[1];
}
return str_ireplace(array_keys($text), $text, $translated);
}
}
return $translated;
},
999,
3
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment