Table of Contents

Language Support

Keywords: localization, l10n, internationalization, i18n

VuFind® supports multiple languages in its user interface through two main mechanisms.

Translate Function

VuFind® uses Laminas' translation mechanism. The translator object is registered in the service manager under the standard 'Laminas\Mvc\I18n\Translator' key.

Notes:

Formatting Language Files

When modifying an existing language file or creating a new one, you should observe these standards:

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

  1. Create a new language file as described above and put it in the languages directory (either in the root of VuFind® if you are planning to commit the new language to the dev branch, or inside your local settings directory if this is a local customization).
  2. 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.
  3. If desired, translate help screens as described above.
  4. Edit config.ini and add your new language to the [Languages] section.

Updating a Language

If you wish to maintain an existing set of language files, but you are not sure which strings have been recently added, VuFind® includes a language tool which will generate lists of missing strings in all supported languages. To access it, turn on development mode and then add “/DevTools/Language” to the end of your base URL to access the language report.

Note also that there are language-related command line utilities which can help with common maintenance tasks. Most importantly, rather than manually sorting your language files, you can add new/missing strings to the ends, and rely upon the “language normalize” tool to put everything in correct order and format files to project standards.

If you want to contribute to the project's translations without modifying code or files, you can also request access to our Lokalise instance.

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.

Example 1

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.

Example 2

Using customized language files for a multisite-setup.

vufind2/local/languages/de.ini
                        en.ini
                        ...
vufind2/multi1
vufind2/multi2
..
vufind2/multin
    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.

Text Domains

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:

$VUFIND_HOME/languages/MyDomain/en.ini:

  myString = "The translation"

Then calling

  $translator->translate('MyDomain::myString');

or

  $translator->translate(['MyDomain', 'myString']);

on a valid $translator object would return “The translation”.

Text domains currently used by VuFind®:

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.

Troubleshooting Language Strings

Starting with VuFind® 9.1, if you activate the “debug” language code in the [Languages] section of config.ini, you can put the software into a mode that will display all of the raw data used in translation, instead of actually applying the translation system. This can be helpful for identifying which strings in the language files need to be overridden to customize particular parts of the interface and for troubleshooting problems.

Video

This topic is discussed in the Internationalization video.