views:

44

answers:

1

Hi people
I'm doing a translation of php script and want to gain some time by doing some automatization The file contains very large number of lines like these

define('LNG_NewsletterNameIsNotValid', 'Email Campaign name is not Valid');
define('LNG_UnableToCreateNewsletter', 'Unable to create an Campaña de Email');
define('LNG_HLP_NewsletterName', 'You must insert \\\'Custom Fields\\\' in the field.');
define('LNG_UnableToUpdateNewsletter', 'Unable to update '. LNG_xxx . ' from Email Campaign');

and I would like to:

  • open each php file
  • go through each line
  • get the string corresponding to each define()
  • put a field where I should write the translation
  • save the new string to the file

I have the script almost done, except for the part for getting the string to be translated from each line. I point several examples so you can see that translation strings can contain references to other variables, quotes, etc.

Do I need a regular expression, right?
Can any1 help me with one?

Thanks

+2  A: 

You'd probably be better of using token_get_all. While regex could probably get most of them, It doesn't have the necessary complexity to parse PHP correctly (just like regexes can't parse html). token_get_all would only miss edge cases, such as using a variable-function or eval'ing text.

If your doing language translations it might be worth looking into gettext instead of using define.

Kendall Hopkins
+1 for both suggestions :)
Anpher
Kendall, that was awesome. I can't change define for gettext because I'm not the developer of the script, but I'll send that suggestion to them. Thanks!
Enrique