rainlab / translate-plugin

Enables multi-lingual sites
Other
125 stars 88 forks source link

Components views are not scanned for messages #702

Closed mplodowski closed 2 years ago

mplodowski commented 2 years ago

It seems like plugin components views are not scanned for translated messages.

public function scanForMessages()
{
    $this->scanThemeConfigForMessages();
    $this->scanThemeTemplatesForMessages();
    $this->scanMailTemplatesForMessages();
    // todo scan components for messages
}
mplodowski commented 2 years ago

This code seems to work, but I don't know if this will work for all cases.

  Event::listen('rainlab.translate.themeScanner.afterScan', function (ThemeScanner $scanner) {
      $messages = [];

      $manager = ComponentManager::instance();

      foreach ($manager->listComponents() as $componentClass) {
          $componentObj = $manager->makeComponent($componentClass);

          $partial = ComponentPartial::load($componentObj, 'default');

          if ($partial) {
              $messages = array_merge($messages, $scanner->parseContent($partial->content));
          }
      }

      Message::importMessages($messages);
  });
daftspunk commented 2 years ago

We can include this in addition to the other checks. However, it won't cover partials inside the components directory other than the default one. Most components should strive to be encapsulated in a single template, this makes them easy to override, so this proposal is helpful to include.

samgeorges commented 2 years ago

Added this in 8c66aeba6e50dab37ba88fa2c94f767c4810207c