Overview
This documentation is deprecated.
The documentation has moved
New Location https://project.pages.drupalcode.org/string/
Impacts:
- Module developers
- Themers
- Translators
Basic Usage
The main aim is to provide developers with the ability to define interface text in their codebase using custom identifiers. The developers can also provide some meta data surrounding the strings if needed.
For example,
// Instead of doing this
t('Hello @name!', ['@name' => $name], ['context' => 'short greeting']);
// Do this
t('dashboard.greeting.short', ['@name' => $name]);
Where dashboard.greeting.short would be defined in dashboard.string.yml file as follows,
dashboard.greetings.short:
default: "Hello @name!"
The Developers can also attach extra information surrounding the strings such as comments for the Translators. Following is an example string definitions used for examples on this page. The string module could export such comments into translation template file (POT).
dashboard.greetings.short:
default: "Hello @name!"
placeholders:
- key: "@name"
type: string
comments:
- "The short greeting would be used on narrow width devices."
Architecture
The string definitions are exposed to Drupal Core via "string_translator" Plugins. Thus it integrates well with core's Local module and all the related modules out of the box. String module however, aims to use the extra context available while defining strings to provide a richer user experience for Translators as well. It archives this by extending existing Core's functionality whenever possible. For Example:
- by providing an enhanced Translation Source file export with notes for translators.
- by exposing a custom source definition to make it easier to manage Job items in TGMNT module.
Please note that the string definition are stored in the codebase. In case you are after a solution where strings are treated as content, then there is a contrib module called Texts which might better suite your need.
How does string module helps?
Use yaml to define strings instead of POT files
Makes your codebase independent of translation workflow.
Editing a text in original language won't invalidate the translation in other language.
Manage your strings using identifiers
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion