Results 1 to 1 of 1

Thread: Language Files for Plugins

  1. #1
    Former lead dev Nick's Avatar
    Join Date
    Jun 2009
    Location
    Kakamigahara, Japan
    Posts
    2,858
    Blog Entries
    88
    Thanks
    482
    Thanked 806 Times in 526 Posts

    Default Language Files for Plugins

    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:

    /content/plugins/users/languages/users_language.php

    PHP Code:
    <?php

    /* 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...

    PHP Code:
    echo $h->lang["users_login"]; 
    That will, of course, output "Login" to the page.
    Last edited by Nick; 01-06-2010 at 02:37 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •