你可以使用gettext filter:
add_filter( \'gettext\', \'cyb_filter_gettext\', 10, 3 );
function cyb_filter_gettext( $translated, $original, $domain ) {
// Use the text string exactly as it is in the translation file
if ( $translated == "Categorie: %s" ) {
$translated = "Sectie: %s";
}
return $translated;
}
如果需要根据上下文过滤翻译,请使用
gettext_with_context
filter:
add_filter( \'gettext_with_context\', \'cyb_filter_gettext_with_context\', 10, 4 );
function cyb_filter_gettext_with_context( $translated, $original, $context, $domain ) {
// Use the text string exactly as it is in the translation file
if ( $translated == "Categorie: %s" ) {
$translated = "Sectie: %s";
}
return $translated;
}
带上下文的翻译意味着在用于翻译字符串的gettext函数中给出了上下文。例如,这没有上下文:
$translated = __( \'Search\', \'textdomain\' );
这就是背景:
$translated = _x( \'Search\', \'form placeholder\', \'textdomain\' );
类似的过滤器可用于复数翻译(
[_n()][2]
和
[_nx()][2]
):
ngettext
和
ngettext_with_context
.