How to use language files in plugins?

Basically read the source for the function load_plugin_textdomain():

function load_plugin_textdomain( $domain, $abs_rel_path = false, $plugin_rel_path = false )

Ignore the second parameter, it was deprecated a long time ago.

An example from my plugin T5 Taxonomy Location:

protected function load_language()
{
    load_plugin_textdomain(
        'plugin_t5_tax_location',
        FALSE,
        plugin_basename( dirname( __FILE__ ) ) . '/languages'
    );
}

The first parameter is the text domain, the last the path to the languages directory in the plugin.

Now you can use strings in your plugin with that text domain:

__( 'Locations', 'plugin_t5_tax_location' )

There are multiple tools available to create new translations. I have used Codestyling Localization in the past, but it is broken now unfortunately.

tech