Table of Contents
This page refers to VuFind 2.x and later; use of earlier versions is no longer recommended.
Keywords: localization, l10n, internationalization, i18n
VuFind supports multiple languages in its user interface through two main mechanisms.
VuFind uses Laminas' translation mechanism. The translator object is registered in the service manager under the standard 'Laminas\Mvc\I18n\Translator' key.
- If you attempt to translate a string that is not found in a language map, the original string will be displayed untranslated.
- Many of the translated strings in the language files are simply chunks of English text. However, more recent additions are represented as shorter tokens (i.e. “adv_search_filters”). The token approach is often preferable since it allows for more concise map files and reduces the chances of conflicts where the same text has multiple meanings.
Formatting Language Files
When modifying an existing language file or creating a new one, you should observe these standards:
- Save the file in UTF-8 format without a Byte Order Marker (BOM). Including a BOM may cause VuFind to fail to parse the file correctly.
- Make sure the file is sorted in a case-insensitive manner; VuFind's test suite will complain if language files are out of order, though it will not prevent translations from working properly in the user interface. A command-line tool exists to perform this sorting for you (see below).
- Put double-quotes around multi-word phrases on the right side of the equals sign. Do NOT put quotes around phrases on the left side of the equals sign.
For an example of a full language file, see en.ini.
Note: If modifications to a language file do not take effect, sometimes it is necessary to clear out the local directory language cache by removing the local/cache/languages directory. The directory should be recreated automatically.
Sorting Language Files
To sort a directory full of language files, simply go to the command line, and from your $VUFIND_HOME directory, run:
php public/index.php language normalize [path_to_language_files]
VuFind will automatically sort the files for you.
Adding a New Language
- If you also wish to translate strings inside text domains (see below) you will need to create appropriate subdirectories inside languages, and put additional language files inside these directories.
- If desired, translate help screens as described above.
- Edit config.ini and add your new language to the [Languages] section.
Customizing Language Files
If you need to customize the language files residing in VUFIND_HOME/languages but do not want to commit this customization to the dev branch, you only need to create a languages folder in your local folder (or any folder that is configured as your VUFIND_LOCAL_DIR). Any language file in your VUFIND_LOCAL_DIR/languages folder will be merged with its corresponding language file in VUFIND_HOME/languages (implicit inheritance).
Starting with VuFind 2.5, you can also put a languages directory inside a theme folder to apply custom translations to that specific theme. This can be useful, for example, to use shorter strings in a mobile interface than a desktop version.
Defining an Explicit Parent Language File
In addition to the above mentioned implicit inheritance of language .ini files VuFind\Il8n\Translator offers a similiar feature as the configuration .ini file's [Parent_Config] section: by adding the line @parent_ini = “relative/path/to/language.ini” to your custom language file in VUFIND_LOCAL_DIR/languages you can reference any other language .ini file as being the parent .ini file.
- language is set to “de”
- VUFIND_LOCAL_DIR = /var/www/vufind2/local
foo = bar
@parent_ini = "../../customlang/custom.ini"
The content of vufind2/customlangfiles/custom.ini will be merged into VUFIND_LOCAL_DIR/languages/de.ini and the result is being merged with vufind2/languages/de.ini.
Using customized language files for a multisite-setup.
- all your customized language files which should be used by all multisites go into:
vufind2/local/languages/de.ini en.ini ...
- your multisite local_dirs:
vufind2/multi1 vufind2/multi2 .. vufind2/multin
- let every multisite use the customized language files:
vufind2/multi1/languages/de.ini @parent_ini = "../../local/languages/de.ini" vufind2/multi1/languages/en.ini @parent_ini = "../../local/languages/en.ini" vufind2/multi2/languages/de.ini @parent_ini = "../../local/languages/de.ini" ... vufind2/multin/languages/en.ini @parent_ini = "../../local/languages/en.ini"
You can even use @parent_ini for multiple inheritance steps, BUT the @parent_ini path always needs to be relative to VUFIND_LOCAL_DIR.
Starting with VuFind 2.5, VuFind supports text domains – essentially namespaces for language strings. You can create a subdirectory of the languages folder named for the text domain and containing language .ini files named for the appropriate language codes. The text domain is then accessed in the translator by prefixing the string with the text domain and a '::' separator.
For example, suppose you added:
myString = "The translation"
on a valid $translator object would return “The translation”.
Text domains currently used by VuFind:
- CallNumberFirst - used for translation of main classification category
- CreatorRoles - used for translating author relator terms (such as these)
- HoldingStatus - used for displaying complex item availability messages (not supported by all ILS drivers)
- Exception - used for exception messages (currently not the exclusive location for these kinds of messages, but refactoring may eventually occur)
Help Screen Translation
VuFind's help screens contain too much text for the standard translation mechanism to be a practical way of presenting them in multiple languages. Instead, under the theme/root/templates/HelpTranslations directory, the help templates are in folders whose names correspond with VuFind language codes (i.e. “en” for English). When a user requests a help screen, VuFind attempts to serve them the most appropriate version for their selected language, though it defaults to the English version if nothing else is available; as of this writing, help screens have not been translated into all possible languages.
This topic is discussed in the Internationalization video.