I have to create translations for the project I work on. The simplest solution was to change all stings to a functioncall(string) so that I could get unique string hashes everytime.
My code has the following different t() function uses:
<label for="anon"><?php echo t('anonymously? (20% extra)')?></label>
exit(t("Success! You made {amount} oranges out of it!", array('amount' => $oranges)));
echo t('You failed.');
My current regexp is:
$transMatches = preg_match_all('/[^a-z]t\([^)(]+/m', $contents, $matches);
The problem is that it fails on #1 example, matchin “anonymously?”.
What I really want to achieve is: “match t( then match either ‘ or ” then match anything except what you matched for ‘ or ” and )”
Idea: t\(['|"](.*?)[^'|"]\)?
I cannot make above regexp to work.
How could I do AND in regexp so that it matches “[‘|”] AND )” OR “[‘|”] AND, array”
Please help me on regexp and explain why it works.
Thank you!
Parsing function arguments may be quite complex, but you need to parse only the first argument which (for simplicity) can assume always to be string escaped either with
'or with", thus those regexps may match”Therefore you just need to match:
[^\w\d]assumes that notest1twill match,\s*makes you space tolerant…With this regexp you’ll get results like:
And I can’t imagine situation where you would need to parse out array too, can you describe it in comment/question?