The new translatable text syntax in twig templates is custom (different from the regular t('String') that was in phptemplate themes).

Drupal 7:

     <?php if ($logo): ?>
       <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
         <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
        </a>
     <?php endif; ?>

Drupal 8:

    {% if logo %}
      <a href="{{ front_page }}" title="{{ 'Home'|t }}" rel="home" id="logo">
        <img src="{{ logo }}" alt="{{ 'Home'|t }}"/>
      </a>
    {% endif %}

The strings to parse for are 'String'|t.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ksenzee’s picture

Assigned: Unassigned » ksenzee

Making progress on this. It works fine except that the regex doesn't support escaped quotes ('Here\'s an apostrophe'). Will post a patch when that works.

ksenzee’s picture

Version: 7.x-2.x-dev » 6.x-3.x-dev
Status: Active » Needs review
FileSize
4.13 KB

Here's a working patch. In my testing it handles all of the following correctly:

{{ 'This is a test'|t }}
{{ 'Here\'s an escaped quote'|t }}
{{ "Here's a double-quoted string with an escaped \" that should work fine"|t }}
{{ "Here's a double-quoted string" . "this shouldn't work"|t }}
{{ 'Here\'s a single-quoted string' . 'that should fail'|t }}
Gábor Hojtsy’s picture

This looks fabulous! Can you also include a sample twig file with some proper and improper uses? The tests directory has such modules and JS as samples. Other than that, amazing :)

Gábor Hojtsy’s picture

Title: Support for Drupal 8 twig template translatables » Support for Drupal 8 twig |t translatables
Gábor Hojtsy’s picture

Title: Support for Drupal 8 twig |t translatables » Support for Drupal 8 twig t filter translatables
ksenzee’s picture

Added a test file and some tests, which pass locally.

Status: Needs review » Needs work

The last submitted patch, 2011442-6.twig-translatables.patch, failed testing.

coltrane’s picture

Status: Needs work » Needs review
FileSize
5.78 KB

Re-roll #6 without D8 API support following #2040115: Initial Drupal 8 API support to exclude old things getting in

Gábor Hojtsy’s picture

Status: Needs review » Fixed

Yay, looks great, committed!

Gábor Hojtsy’s picture

Version: 6.x-3.x-dev » 7.x-2.x-dev
Status: Fixed » Patch (to be ported)
s_leu’s picture

Status: Patch (to be ported) » Needs review
FileSize
6.06 KB

Adding a reroll of the the patch for 7.x-2.x

Gábor Hojtsy’s picture

Is this applying the current naming scheme for functions in this branch?

  • Gábor Hojtsy committed f49ba46 on 7.x-2.x
    Issue #2011442 by ksenzee, coltrane | Gábor Hojtsy: Support for Drupal 8...

  • Gábor Hojtsy committed f49ba46 on 7.x-3.x
    Issue #2011442 by ksenzee, coltrane | Gábor Hojtsy: Support for Drupal 8...
SebCorbin’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Issue summary: View changes
Status: Needs review » Closed (fixed)

Ported to 7.x-3.x as it has been branched directly from 6.x-3.x