0

i try to make .mo files from my sources in php by finding "t()" function calls, i know that one better way is using regex functions like preg_match or something, but i'm not the better creating regular expresions, any help?

(and sorry for my english...)

DavidB
  • 3
  • 1
  • Please provide some examples of the input and clearly indicate what substrings you're trying to match. – Bart Kiers May 18 '11 at 08:26
  • @Bart: I believe the author wants to generate .mo files as generated by gettext. The `t()` function is probably equivalent of gettext's `_()` function. The author needs to find all these function calls in order to get the untranslated source strings. – Sander Marechal May 18 '11 at 09:03
  • @Sander, it's exactly what you say, thankyou – DavidB May 18 '11 at 15:13

2 Answers2

1

No, preg_match is not better. When you want to parse PHP code, use the tokenizer. It is far more reliable.

Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
  • ohhh thank you very much, i googled for this solution a lot, maybe i dont know how to google in the correct terms :( , i do some tests and its just that i need, thank you very much again!!! – DavidB May 18 '11 at 15:16
  • @DavidB: If this solves your problem please consider [accepting my answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) by clicking the big "tick" icon on my answer. Thank you. – Sander Marechal May 18 '11 at 22:16
  • of course, sorry, this was my first question here and i didnt know, done. – DavidB May 20 '11 at 06:27
  • Could you go into more detail? The tokenizer returns the same token constant for function calls as it does for plain old strings (it gives back T_STRING) so it's not clear how to be sure that you've found a call to the function t versus a string that contains the letter t. (I'm on 5.3.11, but the docs don't mention any constant for function calls, so I assume this is the same across all versions.) – mmitchell Nov 26 '12 at 18:43
0

Assuming that you have no function calls within the t() call, the simplest way to match them is

t\([^)]*?\)
Thomas Hupkens
  • 1,570
  • 10
  • 16
  • sorry but i didn't explain so good, there is a lot of code around de t() calls, but thankyou for your time & help – DavidB May 18 '11 at 15:12