How to use language files in plugins?

At the moment i’m developing my first wordpress plugin and want to include multi-language function in it. May be there is some manuals on it? Tried to google, but only get best wordpress language switcher plugin.

Related posts

Leave a Reply

1 comment

  1. 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.