Main menu

Filter the formal tone of a locale

When sending data to an automatic translation API, the formality can sometimes be sent as a hint. This gets around the problem that the API may only receive only a language tag, e.g. "de" or "nl", but requires that Loco Translate is able to detect the required tone automatically.

It can be derived that de_DE is informal, but only on the basis that de_DE_formal is defined by WordPress and de_DE_informal is not. Conversely, de_CH must be formal on the basis that de_CH_informal is defined.

This is not a very reliable indicator and there may be cases where you want to go against the rule. The following example forces a formal tone for any German language tag:

function ensure_german_always_formal( $tone, $tag ){
    if( 'de' === substr($tag,0,2) ){
        $tone = 'formal';
    }
    return $tone;
}
add_filter('loco_locale_formality','ensure_german_always_formal',999,2);
Last updated by