By bbu23 on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
11.4.x
Introduced in version:
11.4.0
Issue links:
Description:
A new StringContextInterface has been added to support filtering translatable strings by context and location in the translation interface (/admin/config/regional/translate).
User interface changes
The translate interface UI now includes "Context" and "Location" filter dropdowns.
API changes
A new optional interface:
namespace Drupal\locale;
interface StringContextInterface {
public function getContexts(): array;
public function getDistinctLocations(): array;
}
StringDatabaseStorage now implements this interface.
Example
$locale_storage = \Drupal::service('locale.storage');
// Get available contexts and locations.
if ($locale_storage instanceof \Drupal\locale\StringContextInterface) {
$contexts = $locale_storage->getContexts();
$locations = $locale_storage->getDistinctLocations();
}
Backward compatibility
No BC break. This is a new optional interface.
Impacts:
Site builders, administrators, editors
Module developers