Claudiu Cristea commented on merge request !60 at project / babel

Claudiu Cristea
2025-10-01T07:20:45Z

We can use the official API here, BabelStorage::getSourceStringInstances():

use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
 * Cache collector for translated strings.
 */
class StringsCollector extends CacheCollector {

  /**
   * Static cache for strings provided by a plugin in a certain language.
   */
  protected array $stringsByPluginAndLang = [];

  public function __construct(
    protected readonly string $langcode,
    #[Autowire(service: 'cache.babel')]
    CacheBackendInterface $cache,
    #[Autowire(service: 'lock')]
    LockBackendInterface $lock,
    protected readonly BabelStorageInterface $babelStorage,
    protected readonly TranslationTypePluginManager $manager,
  ) {
    parent::__construct("strings.$this->langcode", $cache, $lock);
  }

  /**
   * {@inheritdoc}
   */
  protected function resolveCacheMiss($key): ?array {
    $value = NULL;
    foreach ($this->getPluginStringsForLanguage($pluginId, $this->langcode, $ids) as $pluginId => $ids) {
      foreach ($this->getPluginStringsForLanguage($pluginId, $this->langcode, $ids) as $string) {

Needs also a change in StringsCollectorFactory