Question

I need to generate .po files for the Php code of my web application. This is a very large application that needs to be translated to several different languages. So far, I have been using PoEdit in order to generate my .po files. The problem lies in that many of my files lack the Gettext notation echo _("message") and in the past I only used echo "message".

This is what I think it could be the best solution for my issue:

  1. Create a script that scans my Php code and tells me which of my messages are being and not being displayed using Gettext. How would I do this?

  2. Replace those string not using Gettext with the appropriate Gettext pattern.

Can you please advise me what is the best aproach in order to get all my code using Gettext that I should look to?

Was it helpful?

Solution

You have one way how to convert echoing messages without translation by gettext to echoing messages with translation by gettext:

If you know that all messages are represented by only one variable, for example $Message, following way will be made relatively fast, else you would have to find all used echoing of any messages ... and do that manually (mostly if message is only one - and it is represented by text, not by variable holding that text).

In your editor to start global search (in all files) and then, to go file by file and use replacing - and set $Message for search and _($Message) for replacement ... unless your editor allows replacing in more files at the same time. Then you would do all replacement at one time.

I would not suggest to do this replacing directly in php.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top