I have decided to use ResourceBundles to provide translations for my php application. While the ResourceBundle (http://www.php.net/manual/en/class.resourcebundle.php) functionality is quite new, I prefer the way it works over gettext.
The question I have is that are there any good ResourceBundle editors? In particular I am looking for one that will scan all my source files and generate a list of message IDs that require translations and/or updating.
Previously, I have used POEdit to generate translation files for gettext. It is able to scan my source files for functions such as _() and hand me a list of message ids to translate.
I have tried installing an eclipse plugin (http://sourceforge.net/projects/eclipse-rbe/) and while it has a nice GUI, it doesn't scan my source files to generate a list of message IDs to translate.
Could anyone recommend any resource bundle editors?
After spending most of the day trying out loads of different tools and what not, I have devised this workflow, and howpfully it will help others as well.
ResourceBundles are quite new to PHP and there isn't really much information. Surprisingly, while resource bundles have been used by various languages such as Java for quite a while, I wasn't able to find any tools that can deal with RBs in a general manner.
SirDarius's suggestion to try RB Manager was a good start. It's straight forward to use, but there are some issues:
I have tried various tools to convert between formats, namely the XLIFF format, but I find that the XLIFF files generated are often malformed, and the next piece of software would refuse to process it.
For those who might run into this issue in the future, here is what I have done:
I am assuming that you will have some classes or function to wrap around the MessageFormatter and ResourceBundle classes. In my application, I use something like $translate->_('text');
to perform translation. The trick is to use POEdit. POEdit will scan your source files for _() and get a list of keys and remove old keys. Remember that in MessageFormatter, you only use a message id, for example system.warning.reason instead of a full string "Your action was denied. This has been logged".
You should then use POEdit to write your translations. Dealing with plurals is a bit different. You should not set up any rules for dealing with plurals. Dealing with plurals is done inline for the translation string, which is really flexible. See here: http://userguide.icu-project.org/formatparse/messages for some examples.
Once your translation has been completed, I wrote a small PHP script to convert the .mo files generated by POEdit into the equivalent ICU files.For parsing the .mo files, I used the gettext adapter in Zend_Translate. It also contained a function to grab all message IDs and messages, which is extremely useful. You then convert that data into ICU format like so:
root {
// message ID {" Pattern "}
system.warning.reason { "Your action was denied. This has been logged" }
}
Once this is done, you need to download the ICU package from : http://site.icu-project.org/download. In the bin directory, you will find an executable called genrb, which compiles the resourcebundle into a binary for PHP to use.
The command is genrb inputfile.txt -e UTF-8
notice that the input encoding is specified as UTF-8. You can change this to whatever encoding your input files uses.
That's it. I believe this is the simpliest and most productive workflow when generating and translating resourcebundles for PHP.
If anyone comes up with a better way, or perhaps even a full standalone program to take care of this, please post a comment!