Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Places to search for lang strings.

Development:Places to search for lang strings

From MoodleDocs

Moodle has a mechanism that allows a number of places to be searched (in order) to find language strings or help files. This enables help to be packaged with optional plugins and avoids the step of having to copy the language files over to the language directory when a plugin is installed. This page provides some information about this mechanism which might be useful to plugin developers or those wishing to add a completely new pluggable feature to moodle.

Basic concepts

When it is required to lookup a string or point to a help file, two basic items of information are required. The first is the name of the string (or the help filename) and the name of the module in which it can be found. For example, get_string('editingquiz','quiz') returns "Editing Quiz" in the current language; a call to help.php?module=label&file=mods.html displays the help for a label, again in the current language.

Plugin support extends this by defining a new format for the module name. The module name becomes type_plugin, where type is a generic name common to the plugin type and plugin is the name of the individual item. To illustrate this, here is an example. Blocks are a pluggable resource - the type name is block_ and the plugin name is the name of the individual block. Some examples of block module names are block_search (type is block_ and plugin is search) and block_online_users (type is block_ and plugin is online_users).

It is important to grasp that every block is now a discrete module type. This applies to all pluggable resources, so every, e.g., questiontype, authentication plugin, grade report is a separate module and will have its own language file and it's own directory for its help files. Not all plugin types define both language strings and help files but here is an example of what you might find for a plugin module:

   Description: questiontype plugin for multichoice
   Module name: qtype_multichoice
   Language strings (English): lang/en_utf8/qtype_multichoice.php
   Help files directory (English): lang/help/qtype_multichoice/

All of the above must be in place for pluggable language and help strings to be a possibility for optional plugins.

Defining the search path(s)

The next step is to define the search locations for the plugin. This is only needed to define where the optional plugins will be installed, the standard help locations will be searched automatically. This is done by adding an entry to the array defined in the function places_to_search_for_lang_strings located in lib/moodlelib.php.