This module provides a way to store and retrieve values that vary based on language, without needing to create separate content entities. It extends Drupal's State API to allow for language-specific settings that can be managed programmatically.
INTRODUCTION
Wrapper for State API that handles states that variate per language.
The primary use case for this module is to store translatable variables without a content entity.
REQUIREMENTS
More than one language enabled.
CONFIGURATION
None, API-only module.
USAGE
Defines a new service multilingual_state that follows the same interface as the Drupal State service but gets/sets the variable with a language suffix.
When the current language is Spanish something like this can be executed:
\Drupal::service('multilingual_state')->set('site_title', 'Mi Drupal en español');
\Drupal::service('multilingual_state')->get('site_title');
And that variable can be different for each language.
There is three new methods:
// Specify the langcode explictly. public function getTranslated($key, $langcode, $default = NULL); public function setTranslated($key, $value, $langcode); // Remove the variable from all languages. public function deleteAllLanguages($key);
MAINTAINERS
Current maintainers for Drupal 11:
- Rodrigo Aguilera (rodrigoaguilera) - https://www.drupal.org/u/rodrigoaguilera
Ask your assistant about Multilingual state
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
- language Drupal core
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.