1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Language Files for Plugins

Discussion in 'Developing Plugins' started by Nick, Jul 21, 2009.

  1. Nick

    Nick Well-Known Member

    Wherever possible, you should avoid hard-coding raw language into your plugin and put it in a language file instead. There are two obvious benefits of this:

    1. Language for an entire plugin can be quickly updated, changed or translated because it's all gathered together in a single file.

    2. Language files can be moved from your plugin and into a language pack's plugins folder and still work! This saves users from having their customizations overwritten when they upgrade your plugin.

    Example language file

    A language file is just a regular PHP file. It must be put in a folder named "languages" and it should be named pluginname_language.php. For example, the Users plugin has a language file here:



    /* Login */
    $lang["users_login"] = "Login";
    $lang["users_login_instructions"] = "Enter your username and password to login:";
    $lang["users_login_failed"] = "Login failed";
    $lang["users_login_form_submit"] = "Login";

    Your language file is included automatically when a plugin hook function is accessed, so all you need to do to use the language is...

    echo $h->lang["users_login"];
    That will, of course, output "Login" to the page.
    Last edited: Jan 6, 2010

Share This Page