Hello world', [], ]; // text, no arg $cases[] = [ '
{{ts("Hello world")}}
', ['Hello world'], ]; // text, no arg, alternate text $cases[] = [ '
{{ts("Good morning, Dave")}}
', ['Good morning, Dave'], ]; // angular one-time binding notation - great when there are no args $cases[] = [ '
{{:: ts("One-time binding is more efficient!") }}
', ['One-time binding is more efficient!'], ]; // text, with arg $cases[] = [ '
{{ts("Hello world", {1: "whiz"})}}
', ['Hello world'], ]; // text, not really ts(), no arg $cases[] = [ '
{{clients("Hello world")}}
', [], ]; // text, not really ts(), with arg $cases[] = [ '
{{clients("Hello world", {1: "whiz"})}}
', [], ]; // two strings, duplicate $cases[] = [ '
{{ts("Hello world")}}

{{ts("Hello world")}}

', ['Hello world'], ]; // two strings, addition $cases[] = [ '
{{ts("Hello world") + "-" + ts("How do you do?")}}

', ['Hello world', 'How do you do?'], ]; // two strings, separate calls $cases[] = [ '
{{ts("Hello world")}}

{{ts("How do you do?")}}

', ['Hello world', 'How do you do?'], ]; // single quoted $cases[] = [ '
{{ts(\'Hello world\')}}
', ['Hello world'], ]; // unclear string $cases[] = [ '
{{ts(message)}}
', [], ]; // ts() within a string $cases[] = [ '
{{ts("Does the ts(\'example\') notation work?")}}
', ['Does the ts(\'example\') notation work?'], ]; // attribute, no arg $cases[] = [ '
', ['Hello world'], ]; // attribute, with arg $cases[] = [ '
', ['Hello world'], ]; // attribute, two strings, with arg $cases[] = [ '
', ['Hello world', 'How do you do, %1?'], ]; // trick question! Not used on Smarty templates. $cases[] = [ '
{ts}Hello world{/ts}
', [], ]; return $cases; } /** * @param string $html * Example HTML input. * @param array $expectedStrings * List of expected strings. * @dataProvider translateExamples */ public function testParseStrings($html, $expectedStrings) { // Magic! The JS parser works with HTML! $actualStrings = CRM_Utils_JS::parseStrings($html); sort($expectedStrings); sort($actualStrings); $this->assertEquals($expectedStrings, $actualStrings); } }