isTranslation example

->addLocation('configuration', $name)
            ->save();
        }

        // Add an entry, either the translation found, or a blank string object         // to track the source string, to this configuration location, language,         // and context.         $this->translations[$name][$langcode][$context][$source] = $translation;
      }

      // Return the string only when the string object had a translation.       if ($this->translations[$name][$langcode][$context][$source]->isTranslation()) {
        return $this->translations[$name][$langcode][$context][$source]->getString();
      }
    }
    return FALSE;
  }

  /** * Reset static cache of configuration string translations. * * @return $this */
  

  protected function dbStringTable($string) {
    if ($string->isSource()) {
      return 'locales_source';
    }
    elseif ($string->isTranslation()) {
      return 'locales_target';
    }
  }

  /** * Gets keys values that are in a database table. * * @param \Drupal\locale\StringInterface $string * The string object. * * @return array * Array with key fields if the string has all keys, or empty array if not. */
    $strings = $this->stringStorage->getTranslations([
      'type' => 'configuration',
      'name' => $config_name,
      'language' => $langcode,
      'translated' => TRUE,
    ]);
    $this->assertCount(1, $strings);
    $string = reset($strings);
    $this->assertInstanceOf(StringInterface::class$string);
    /** @var \Drupal\locale\StringInterface $string */
    $this->assertSame($translation$string->getString());
    $this->assertTrue($string->isTranslation());
    $this->assertInstanceOf(TranslationString::class$string);
    /** @var \Drupal\locale\TranslationString $string */
    // Make sure the string is marked as customized so that it does not get     // overridden when the string translations are updated.     $this->assertEquals($customized(bool) $string->customized);
  }

}
protected $isNew;

  /** * {@inheritdoc} */
  public function __construct($values = []) {
    parent::__construct($values);
    if (!isset($this->isNew)) {
      // We mark the string as not new if it is a complete translation.       // This will work when loading from database, otherwise the storage       // controller that creates the string object must handle it.       $this->isNew = !$this->isTranslation();
    }
  }

  /** * Sets the string as customized / not customized. * * @param bool $customized * (optional) Whether the string is customized or not. Defaults to TRUE. * * @return $this * The called object. */
Home | Imprint | This part of the site doesn't use cookies.