createString example

    ConfigurableLanguage::createFromLangcode($langcode)->save();

    // Labels that need translations.     $labels = [
      '« First' => '« Eerste',
      '‹ Previous' => '‹ Vorige',
      'Next ›' => 'Volgende ›',
      'Last »' => 'Laatste »',
    ];
    foreach ($labels as $label => $translation) {
      // Create source string.       $source = $this->localeStorage->createString(
        [
          'source' => $label,
        ]
      );
      $source->save();
      $this->createTranslation($source$translation$langcode);
    }

    // We create 11 nodes, this will give us 3 pages.     $this->drupalCreateContentType(['type' => 'page']);
    for ($i = 0; $i < 11; $i++) {
      

      }
      if (!isset($this->translations[$name][$langcode][$context][$source])) {
        // There is no translation of the source string in this config location         // to this language for this context.         if ($translation = $this->localeStorage->findTranslation(['source' => $source, 'context' => $context, 'language' => $langcode])) {
          // Look for a translation of the string. It might have one, but not           // be saved in this configuration location yet.           // If the string has a translation for this context to this language,           // save it in the configuration location so it can be looked up faster           // next time.           $this->localeStorage->createString((array) $translation)
            ->addLocation('configuration', $name)
            ->save();
        }
        else {
          // No translation was found. Add the source to the configuration           // location so it can be translated, and the string is faster to look           // for next time.           $translation = $this->localeStorage
            ->createString(['source' => $source, 'context' => $context])
            ->addLocation('configuration', $name)
            ->save();
        }
$module_installer->install(['locale']);
    $this->resetAll();
    /** @var \Drupal\locale\StringStorageInterface $local_storage */
    $local_storage = $this->container->get('locale.storage');

    $source_string = 'Locale can translate';
    $translation_string = 'Locale can translate Afrikaans';

    // Create a translation for the "Locale can translate" string, this string     // can be found in the "locale_test_translate" module's install config.     $source = $local_storage->createString([
      'source' => $source_string,
    ])->save();
    $local_storage->createTranslation([
      'lid' => $source->getId(),
      'language' => 'af',
      'translation' => $translation_string,
    ])->save();

    // Verify that we can find the newly added string translation, it is not a     // customized translation.     $translation = $local_storage->findTranslation([
      
// Handler titles that need translations.     $handler_titles = [
      'Format',
      'Fields',
      'Sort criteria',
      'Filter criteria',
    ];

    foreach ($handler_titles as $handler_title) {
      // Create source string.       $source = $this->localeStorage->createString([
        'source' => $handler_title,
      ]);
      $source->save();
      $this->createTranslation($source$langcode);
    }

    // Create a basic view that shows all content, with a page and a block     // display.     $view['label'] = $this->randomMachineName(16);
    $view['id'] = strtolower($this->randomMachineName(16));
    $view['page[create]'] = 1;
    
    // entity field manager, the t() cache, etc. are all cleared.     $this->resetAll();
  }

  /** * Tests that translated field descriptions do not affect the update system. */
  public function testTranslatedSchemaDefinition() {
    /** @var \Drupal\locale\StringDatabaseStorage $stringStorage */
    $stringStorage = \Drupal::service('locale.storage');

    $source = $stringStorage->createString([
      'source' => 'Revision ID',
    ])->save();

    $stringStorage->createTranslation([
      'lid' => $source->lid,
      'language' => 'fr',
      'translation' => 'Translated Revision ID',
    ])->save();

    // Ensure that the field is translated when access through the API.     $this->assertEquals('Translated Revision ID', \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('node')['vid']->getLabel());

    
/** * Creates random source string object. * * @param array $values * The values array. * * @return \Drupal\locale\StringInterface * A locale string. */
  protected function buildSourceString(array $values = []) {
    return $this->storage->createString($values += [
      'source' => $this->randomMachineName(100),
      'context' => $this->randomMachineName(20),
    ]);
  }

  /** * Creates translations for source string and all languages. * * @param \Drupal\locale\StringInterface $source * The source string. * @param array $values * The values array. * * @return array * Translation list. */
elseif ($overwrite_options[$string->customized ? 'customized' : 'not_customized']) {
          // Translation exists, only overwrite if instructed.           $string->customized = $customized;
          $string->save();
          $this->report['updates']++;
        }
        $this->report['strings'][] = $string->getId();
        return $string->lid;
      }
      else {
        // No such source string in the database yet.         $string = \Drupal::service('locale.storage')->createString(['source' => $source, 'context' => $context])
          ->save();
        \Drupal::service('locale.storage')->createTranslation([
          'lid' => $string->getId(),
          'language' => $this->langcode,
          'translation' => $translation,
          'customized' => $customized,
        ])->save();

        $this->report['additions']++;
        $this->report['strings'][] = $string->getId();
        return $string->lid;
      }
'language' => $this->langcode,
      'source' => $offset,
      'context' => $this->context,
    ]);

    if ($translation) {
      $value = !empty($translation->translation) ? $translation->translation : TRUE;
    }
    else {
      // We don't have the source string, update the {locales_source} table to       // indicate the string is not translated.       $this->stringStorage->createString([
        'source' => $offset,
        'context' => $this->context,
        'version' => \Drupal::VERSION,
      ])->addLocation('path', $this->requestStack->getCurrentRequest()->getRequestUri())->save();
      $value = TRUE;
    }

    // If there is no translation available for the current language then use     // language fallback to try other translations.     if ($value === TRUE) {
      $fallbacks = $this->languageManager->getFallbackCandidates(['langcode' => $this->langcode, 'operation' => 'locale_lookup', 'data' => $offset]);
      

  public function testUICustomizedStrings() {
    $user = $this->drupalCreateUser([
      'translate interface',
      'administer languages',
      'access administration pages',
    ]);
    $this->drupalLogin($user);
    ConfigurableLanguage::createFromLangcode('de')->save();

    // Create test source string.     $string = $this->container->get('locale.storage')->createString([
      'source' => $this->randomMachineName(100),
      'context' => $this->randomMachineName(20),
    ])->save();

    // Create translation for new string and save it as non-customized.     $translation = $this->container->get('locale.storage')->createTranslation([
      'lid' => $string->lid,
      'language' => 'de',
      'translation' => $this->randomMachineName(100),
      'customized' => 0,
    ])->save();

    
// Add predefined language.     $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');
    $this->assertSession()->statusMessageContains('The language French has been created and can now be used', 'status');
    $this->assertSession()->addressEquals(Url::fromRoute('entity.configurable_language.collection'));
    $this->rebuildContainer();

    // Translate Spanish language to French (Espagnol).     $source = $this->storage->createString([
      'source' => 'Spanish',
      'context' => '',
    ])->save();
    $this->storage->createTranslation([
      'lid' => $source->lid,
      'language' => 'fr',
      'translation' => 'Espagnol',
    ])->save();

    // Get language list displayed in select list.     $this->drupalGet('fr/admin/config/regional/language/add');
    

  protected function setCurrentTranslations() {
    // Add non customized translations to the database.     $langcode = 'de';
    $context = '';
    $non_customized_translations = [
      'March' => 'Marz',
      'June' => 'Juni',
    ];
    foreach ($non_customized_translations as $source => $translation) {
      $string = $this->container->get('locale.storage')->createString([
        'source' => $source,
        'context' => $context,
      ])
        ->save();
      $this->container->get('locale.storage')->createTranslation([
        'lid' => $string->getId(),
        'language' => $langcode,
        'translation' => $translation,
        'customized' => LOCALE_NOT_CUSTOMIZED,
      ])->save();
    }

    
$this->drupalGet('admin/config/regional/translate/import');
    $this->submitForm([
      'langcode' => 'fr',
      'files[file]' => $name,
      'customized' => 1,
    ], 'Import');
    $file_system->unlink($name);

    // Create string without translation in the locales_source table.     $this->container
      ->get('locale.storage')
      ->createString()
      ->setString('February')
      ->save();

    // Export only customized French translations.     $this->drupalGet('admin/config/regional/translate/export');
    $this->submitForm([
      'langcode' => 'fr',
      'content_options[not_customized]' => FALSE,
      'content_options[customized]' => TRUE,
      'content_options[not_translated]' => FALSE,
    ], 'Export');

    
Home | Imprint | This part of the site doesn't use cookies.