You are here

potx_test_8.module.txt in Translation template extractor 7.3

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

File used purely to test the parser in potx. This is file has a .txt extension so that it does not fail linting tests run by continuous integration.

File

tests/potx_test_8.module.txt
View source
  1. /**
  2. * @file
  3. * File used purely to test the parser in potx. This is file has a .txt
  4. * extension so that it does not fail linting tests run by continuous
  5. * integration.
  6. */
  7. /**
  8. * @TestAnnotation(
  9. * id = "test_annotation",
  10. * test_label = @Translation("Good translation annotation"),
  11. * test_label_context = @Translation("Translation in good context", context="Translation test")
  12. * )
  13. */
  14. function potx_test_8_example() {
  15. // Tested with long format array style.
  16. $a = new TranslationWrapper('TranslationWrapper string');
  17. $b = new TranslationWrapper('TranslationWrapper string with context', array(), array('context' => 'With context'));
  18. // Test with short format array styles mixed with other tokens.
  19. $a = new TranslatableMarkup('TranslatableMarkup string');
  20. $c = new TranslatableMarkup('TranslatableMarkup string without context', []);
  21. $d = new TranslatableMarkup('TranslatableMarkup string with long array context', [], array('context' => 'With context']));
  22. $d = new TranslatableMarkup('TranslatableMarkup string with short array context', [], ['context' => 'With context']);
  23. $e = new TranslatableMarkup('TranslatableMarkup string with long array followed by short array context', array(), ['context' => 'With context']);
  24. $f = new TranslatableMarkup('TranslatableMarkup string with complicated tokens', array([], 2, potx_test_8_sample(), array(), [[]]), ['context' => 'With context']);
  25. $g = new TranslatableMarkup('TranslatableMarkup string with complicated option tokens', [], ['foo' => potx_test_8_sample([4]), 'bar' => [12, 14, []], 'context' => 'With context', 'eek' => 'ook']);
  26. $a->debug('Debug message');
  27. $b->info('Info message');
  28. $c->notice('Notice message');
  29. $d->warning('Warning message');
  30. $e->error('Error message');
  31. $f->critical('Critical message');
  32. $g->alert('Alert message');
  33. $h->emergency('Emergency message');
  34. $i->log(1, 'Log message');
  35. $j->log('false positive');
  36. $k->log($boo, 'Log message 2');
  37. $l->log($another_false_positive);
  38. $m->log(potx_test_8_sample(), 'Log message 3');
  39. $n->log();
  40. }
  41. /**
  42. * Let's see if we catch errors in @Translation() annotation.
  43. *
  44. * @TestAnnotation2(
  45. * test_1 = @Translation("Bad translation annotation),
  46. * test_2 = @Translation("Another good translation annotation"),
  47. * test_3 = @Translation Even worse,
  48. * test_4 = @Translation("Final good translation annotation"),
  49. * )
  50. */
  51. function potx_test_8_sample() {
  52. }
  53. /**
  54. * Empty annotations are not allowed either.
  55. *
  56. * @TestAnnotation3(
  57. * test = @Translation("")
  58. * )
  59. */
  60. function potx_test_8_empty() {
  61. }
  62. /**
  63. * Test parsing Drupal 8 $this->t and formatPlural function calls.
  64. */
  65. class PotxTestD8 {
  66. function test_func() {
  67. // In the real world, we'd also need to define "function t", and inject
  68. // the translation service. please refer to https://drupal.org/node/2079611
  69. // for an example.
  70. $test_translation = $this->t('Using t inside D8 classes ($this->t)');
  71. }
  72. function testFormatPlural() {
  73. $this->formatPlural($count, '1 formatPlural test string', '@count formatPlural test strings');
  74. $this->formatPlural($count, '1 formatPlural test string in context', '@count formatPlural test strings in context', array(), array('context' => 'Test context'));
  75. $this->formatPlural($count);
  76. $this->formatPlural();
  77. \Drupal::translation()->formatPlural($count, '1 translation->formatPlural test string in context', '@count translation->formatPlural test strings in context', array(), array('context' => 'Test context'));
  78. \Drupal::translation()->formatPlural($count, '1 translation->formatPlural test string', '@count translation->formatPlural test strings');
  79. $a = new PluralTranslatableMarkup($count, '1 PluralTranslatableMarkup test string', '@count PluralTranslatableMarkup test strings');
  80. $b = new PluralTranslatableMarkup($count, '1 PluralTranslatableMarkup test string with context', '@count PluralTranslatableMarkup test strings with context', array(), array('context' => 'Test context'));
  81. }
  82. }
  83. /**
  84. * Test parsing inline templates inside PHP files in Drupal 8.
  85. */
  86. function potx_test_inline_templates() {
  87. $render_array = array(
  88. '#type' => 'inline_template',
  89. '#template' => "Here is a {% trans 'Test translatable string inside an inline template' %}."
  90. );
  91. $render_array['#template'] = 'Here is {% trans %}Another test translatable string inside an inline template{% endtrans %}';
  92. $render_array["#template"] = 'Here is {% trans %}A translatable string inside an inline template, with double-quoted "#template" key{% endtrans %}';
  93. }
  94. /**
  95. * Test that potx ignores translation keywords in non-translation situations, without causing notices.
  96. */
  97. class TestWrapper extends TranslatableMarkup {}