I have created string extractor for translations from javascript files. I found jsgettext project which I used as a starting point (see).
It uses reqular expression to find calls to __()
method inside javascript files. The simple calls are found successfully, but calls with arguments like __('string', { a: 'b'})
are not.
I tried to modify the regular expression to match also method calls with arguments, but without any success (I'm not regular expressions expert).
My question is: How to modify following regular expression to match strings like this?
// this is catched successfully
// var string = __("Please enter %number% more characters.");
// this is problematic
var string = __("Please enter %number% more characters.", { '%number%' : 2 });
Regular expression:
$keywords = join('|', array('__'));
preg_match_all('# (?:' . $keywords . ') \(\\ *" ( (?: (?>[^"\\\\]++) | \\\\\\\\ | (?<!\\\\)\\\\(?!\\\\) | \\\\" )* ) (?<!\\\\)"\\ *\) #ix', $content, $matches, PREG_SET_ORDER);
Thank you