Main menu

Filter the list of available translation API providers

You can extend the list of translation providers by filtering on the initial list of built-in APIs.

For an example of how to do this, see our Mock Translation API

Alter configurations

You can also use this hook to modify the saved configurations of existing providers. For example to set your own API key instead of the one saved in the plugin settings. This example overrides the Google translate API key:

function use_my_google_translate_key( array $apis ){
    foreach( $apis as $i => $api ){
        if( 'google' === $api['id'] ){
            $apis[$i]['key'] = 'MY_API_KEY';
        }
    }
    return $apis;
}
add_filter('loco_api_providers','use_my_google_translate_key',999,1);

Set an alternative source language

WordPress does not have a configurable source language, but if you need to translate strings that are not in English, you can override this so that an alternative code is sent to external APIs. The following example sets the "src" key, asking all external APIs to translate from German instead of English:

function use_alternative_source_language( array $apis ){
    foreach( $apis as $i => $api ){
        $apis[$i]['src'] = 'de';
    }
    return $apis;
}
add_filter('loco_api_providers','use_alternative_source_language',999,1);

See also

Last updated by