- var_dump: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$code = <<<TWIG
(function (Translator) {
{% if include_config %}
Translator.fallback = '{{ fallback }}';
Translator.defaultDomain = '{{ defaultDomain }}';
{% endif %}
{% for locale, domains in translations %}
// {{ locale }}
{% for domain, messages in domains %}
{% for key, message in messages %}
Translator.add({{ key|json_encode|raw }}, {{ message|json_encode|raw }}, "{{ domain }}", "{{ locale }}");
{% endfor %}
{% endfor %}
{% endfor %}
})(Translator);
TWIG;
preg_match_all('/(\{\{|\{%|\{\#)(\-)?/s', $code, $matches, PREG_OFFSET_CAPTURE);
var_dump($matches[2]);