Example #1
0
 /**
  * Tests views_ui tour tip availability in a different language.
  */
 public function testViewsUiTourTipsTranslated()
 {
     $langcode = 'nl';
     // Add a default locale storage for this test.
     $this->localeStorage = $this->container->get('locale.storage');
     // Add Dutch language programmatically.
     ConfigurableLanguage::createFromLangcode($langcode)->save();
     // Handler titles that need translations.
     $handler_titles = array('Format', 'Fields', 'Sort criteria', 'Filter criteria');
     foreach ($handler_titles as $handler_title) {
         // Create source string.
         $source = $this->localeStorage->createString(array('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;
     $view['page[path]'] = $this->randomMachineName(16);
     // Load the page in dutch.
     $this->drupalPostForm($langcode . '/admin/structure/views/add', $view, t('Save and edit'));
     $this->assertTourTips();
 }
Example #2
0
 /**
  * Tests translating the pager using locale.
  */
 public function testPagerLocale()
 {
     // Enable locale and language module.
     $this->container->get('module_installer')->install(array('locale', 'language'));
     $this->resetAll();
     $langcode = 'nl';
     // Add a default locale storage for this test.
     $this->localeStorage = $this->container->get('locale.storage');
     // Add Dutch language programmatically.
     ConfigurableLanguage::createFromLangcode($langcode)->save();
     // Labels that need translations.
     $labels = array('« First' => '« Eerste', '‹ Previous' => '‹ Vorige', 'Next ›' => 'Volgende ›', 'Last »' => 'Laatste »');
     foreach ($labels as $label => $translation) {
         // Create source string.
         $source = $this->localeStorage->createString(array('source' => $label));
         $source->save();
         $this->createTranslation($source, $translation, $langcode);
     }
     // We create 11 nodes, this will give us 3 pages.
     $this->drupalCreateContentType(array('type' => 'page'));
     for ($i = 0; $i < 11; $i++) {
         $this->drupalCreateNode();
     }
     // Go to the second page so we see both previous and next buttons.
     $this->drupalGet('nl/test_pager_full', array('query' => array('page' => 1)));
     foreach ($labels as $label => $translation) {
         // Check if we can find the translation.
         $this->assertRaw($translation);
     }
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function resolveCacheMiss($offset)
 {
     $translation = $this->stringStorage->findTranslation(array('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(array('source' => $offset, 'context' => $this->context, 'version' => \Drupal::VERSION))->addLocation('path', $this->requestUri())->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($this->langcode, array('operation' => 'locale_lookup', 'data' => $offset));
         if (!empty($fallbacks)) {
             foreach ($fallbacks as $langcode) {
                 $translation = $this->stringStorage->findTranslation(array('language' => $langcode, 'source' => $offset, 'context' => $this->context));
                 if ($translation && !empty($translation->translation)) {
                     $value = $translation->translation;
                     break;
                 }
             }
         }
     }
     $this->storage[$offset] = $value;
     // Disabling the usage of string caching allows a module to watch for
     // the exact list of strings used on a page. From a performance
     // perspective that is a really bad idea, so we have no user
     // interface for this. Be careful when turning this option off!
     if ($this->configFactory->get('locale.settings')->get('cache_strings')) {
         $this->persist($offset);
     }
     return $value;
 }
Example #4
0
 /**
  * Creates random source string object.
  *
  * @return \Drupal\locale\StringInterface
  *   A locale string.
  */
 public function buildSourceString($values = array())
 {
     return $this->storage->createString($values += array('source' => $this->randomName(100), 'context' => $this->randomName(20)));
 }