You are here

PassthroughTranslator.php in Backup and Migrate 8.4

File

lib/backup_migrate_core/src/Translation/PassthroughTranslator.php
View source
<?php

namespace BackupMigrate\Core\Translation;

use BackupMigrate\Core\Translation\TranslatorInterface;

/**
 * This translator service simply passes through the us-english strings with the
 * replacement tokens substituted in.
 *
 * Class PassthroughTranslator.
 *
 * @package BackupMigrate\Core\Service
 */
class PassthroughTranslator implements TranslatorInterface {

  /**
   * @param string $string
   *  The string to be translated.
   * @param $replacements
   *  Any untranslatable variables to be replaced into the string.
   * @param $context
   *  Extra context to help translators distinguish ambiguous strings.
   *
   * @return mixed
   */
  public function translate($string, $replacements = [], $context = []) {

    // Provide Drupal-like escaping of replacement values.
    foreach ($replacements as $key => $value) {
      switch (substr($key, 0, 1)) {
        case '@':
        case '%':
          $replacements[$key] = strip_tags($value);
          break;
      }
    }
    return strtr($string, $replacements);
  }

}

Classes

Namesort descending Description
PassthroughTranslator This translator service simply passes through the us-english strings with the replacement tokens substituted in.