You are here

potx_test_8.module in Translation template extractor 6.3

Same filename and directory in other branches
  1. 7.2 tests/potx_test_8.module

File used purely to test the parser in potx.

File

tests/potx_test_8.module
View source
<?php

/**
 * @file
 *   File used purely to test the parser in potx.
 */

/**
 * @TestAnnotation(
 *   id = "test_annotation",
 *   test_label = @Translation("Good translation annotation"),
 *   test_label_context = @Translation("Translation in good context", context="Translation test")
 * )
 */
function potx_test_8_example() {
  $a = new TranslationWrapper('TranslationWrapper string');
  $b = new TranslationWrapper('TranslationWrapper string with context', array(), array(
    'context' => 'With context',
  ));
  $a = new TranslatableMarkup('TranslatableMarkup string');
  $b = new TranslatableMarkup('TranslatableMarkup string with context', array(), array(
    'context' => 'With context',
  ));
  $a
    ->debug('Debug message');
  $b
    ->info('Info message');
  $c
    ->notice('Notice message');
  $d
    ->warning('Warning message');
  $e
    ->error('Error message');
  $f
    ->critical('Critical message');
  $g
    ->alert('Alert message');
  $h
    ->emergency('Emergency message');
  $i
    ->log(1, 'Log message');
  $j
    ->log('false positive');
  $k
    ->log($boo, 'Log message 2');
  $l
    ->log($another_false_positive);
  $m
    ->log(potx_test_8_sample(), 'Log message 3');
  $n
    ->log();
}

/**
 * Let's see if we catch errors in @Translation() annotation.
 *
 * @TestAnnotation2(
 *   test_1 = @Translation("Bad translation annotation),
 *   test_2 = @Translation("Another good translation annotation"),
 *   test_3 = @Translation Even worse,
 *   test_4 = @Translation("Final good translation annotation"),
 * )
 */
function potx_test_8_sample() {
}

/**
 * Empty annotations are not allowed either.
 *
 * @TestAnnotation3(
 *   test = @Translation("")
 * )
 */
function potx_test_8_empty() {
}

/**
 * Test parsing Drupal 8 $this->t and formatPlural function calls.
 */
class PotxTestD8 {
  function test_func() {

    // In the real world, we'd also need to define "function t", and inject
    // the translation service. please refer to https://drupal.org/node/2079611
    // for an example.
    $test_translation = $this
      ->t('Using t inside D8 classes ($this->t)');
  }
  function testFormatPlural() {
    $this
      ->formatPlural($count, '1 formatPlural test string', '@count formatPlural test strings');
    $this
      ->formatPlural($count, '1 formatPlural test string in context', '@count formatPlural test strings in context', array(), array(
      'context' => 'Test context',
    ));
    $this
      ->formatPlural($count);
    $this
      ->formatPlural();
    \Drupal::translation()
      ->formatPlural($count, '1 translation->formatPlural test string in context', '@count translation->formatPlural test strings in context', array(), array(
      'context' => 'Test context',
    ));
    \Drupal::translation()
      ->formatPlural($count, '1 translation->formatPlural test string', '@count translation->formatPlural test strings');
    $a = new PluralTranslatableMarkup($count, '1 PluralTranslatableMarkup test string', '@count PluralTranslatableMarkup test strings');
    $b = new PluralTranslatableMarkup($count, '1 PluralTranslatableMarkup test string with context', '@count PluralTranslatableMarkup test strings with context', array(), array(
      'context' => 'Test context',
    ));
  }

}

/**
 * Test parsing inline templates inside PHP files in Drupal 8.
 */
function potx_test_inline_templates() {
  $render_array = array(
    '#type' => 'inline_template',
    '#template' => "Here is a {% trans 'Test translatable string inside an inline template' %}.",
  );
  $render_array['#template'] = 'Here is {% trans %}Another test translatable string inside an inline template{% endtrans %}';
  $render_array["#template"] = 'Here is {% trans %}A translatable string inside an inline template, with double-quoted "#template" key{% endtrans %}';
}

Functions

Namesort descending Description
potx_test_8_empty Empty annotations are not allowed either.
potx_test_8_example Plugin annotation @TestAnnotation( id = "test_annotation", test_label = @Translation("Good translation annotation"), test_label_context = @Translation("Translation in good context", context="Translation test") )
potx_test_8_sample Let's see if we catch errors in Plugin annotation @Translation() annotation. @TestAnnotation2( test_1 = @Translation("Bad translation annotation), test_2 = @Translation("Another good translation annotation"), test_3 = @Translation Even…
potx_test_inline_templates Test parsing inline templates inside PHP files in Drupal 8.

Classes

Namesort descending Description
PotxTestD8 Test parsing Drupal 8 $this->t and formatPlural function calls.