Hotaru Docs


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

Getting StartedDesign and LayoutPlugin DevelopmentAdvanced TopicsFunction ReferenceTroubleshooting