You are here

public function LayerSwitcher::i18nStringsRefresh in Openlayers 7.3

Refresh string translations.

Overrides Base::i18nStringsRefresh

File

src/Plugin/Control/LayerSwitcher/LayerSwitcher.php, line 125
Control: LayerSwitcher.

Class

LayerSwitcher
Class LayerSwitcher.

Namespace

Drupal\openlayers\Plugin\Control\LayerSwitcher

Code

public function i18nStringsRefresh() {

  // Ensure just labels of active layers are stored.
  $labels = $this
    ->getOption('layer_labels', array());
  $layers = $this
    ->getOption('layers', array());
  $existing_layers = array_intersect_key($labels, $layers);
  $removed_layers = array_diff_key($layers, $labels);

  // Handle translatable values.
  // Remove / register string translations.
  foreach ($removed_layers as $layer) {
    openlayers_i18n_string_remove('openlayers:layerswitcher:' . $this
      ->getMachineName() . ':' . $layer . ':label');
  }
  foreach ($existing_layers as $layer => $label) {
    openlayers_i18n_string_update('openlayers:layerswitcher:' . $this
      ->getMachineName() . ':' . $layer . ':label', $label);
  }

  // Register string in i18n string if possible.
  openlayers_i18n_string_update('openlayers:layerswitcher:' . $this
    ->getMachineName() . ':title', $this
    ->getOption('label', 'Layers'));
}