Localization API

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Documentation about Localization API in Drupal 8.

Localization API overview

Drupal makes it easy to develop translatable interfaces.

When to use st(), t() and get_t() in install and update functions

Drupal does not have access to a database in the early stages of the installation process, so any interface strings which might be generated

Dynamic strings with placeholders

The t() function family not only allows you to translate simple strings. It is possible that you need a variable component in the string: a

Dynamic or static links and HTML in translatable strings

The general rule of thumb for translatable strings is that we keep inline markup for translation but avoid block tags (but do read the whole

Formatting numbers, dates/times, sizes and intervals with localization

While t() can translate strings from one language to another, there are cases where we must display item counts, dates/times, etc. Drupal

Strings at well-known places: built-in menus, permissions, log messages and .info files

As with format_plural(), Drupal has functions where you don't explicitly use t(), but the provided strings are still translated. In some

Translating strings in JavaScript

The JavaScript library shipped with Drupal 6 includes ports of the t() and format_plural() functions, for formatting and translating strings

Language Negotiation API

It is possible to customize the language negotiation process both for how we detect the user's language and also on what type of data they

String context

Note: This handbook page is under discussion, see [#1035716]

Guide maintainers

drupalastic's picture