Translating 3rd party plugins
From PHPDevShell
Make sure to read Language Localization Translation to get a general idea of how the language system works.
Please note that you can only translate the plugin if the developer used the functions $core->__('Hello World') or __('Hello World') for his text strings inside his scripts.
Contents |
Step 1: Enable language system in PHPDevShell
Follow Language Localization Translation#Step 3: Prepare and set correct language options in PHPDevShell to enable needed language settings. This will enable the language system showing another required .mo file for example:
/home/titan/html/phpdev/plugins/DummyPlugin/language/af_ZA/LC_MESSAGES/DummyPlugin.mo
Step 2: Extracting language strings to a po template file
You will now need to create a po file from extracting language strings from all scripts, this one file will be used by a tool to translate it.
Tools to use for PO extraction.
I use the excellent command line xgettext utility, easy enough to use and it is fast. You could create a bat or a sh file to automatically run through all your .php files to extract the po files. If you are using Linux this utility should be included into your distro already, If you are using Windows you can download the utility here; http://ftp.gnu.org/gnu/gettext/gettext-runtime-0.13.1.bin.woe32.zip
So now that you have xgettext lets start the extraction examples. Lets use the DummyPlugin as an example plugin, we have the following files to extract for example;
plugins/DummyPlugin/menu.lang.php [default] plugins/DummyPlugin/plugin.lang.php [default] plugins/DummyPlugin/list_script.php plugins/DummyPlugin/manage_script.php plugins/DummyPlugin/sample/sample1.php plugins/DummyPlugin/sample/sample2.php plugins/DummyPlugin/sample/sample3.php
To extract run the following xgettext command for every file, in Linux for example (make sure you are in the PHPDevShell installation root);
xgettext --default-domain=plugins/DummyPlugin/language/DummyPlugin --language=Python --keyword=__ --keyword plugins/DummyPlugin/list_script.php xgettext --default-domain=plugins/DummyPlugin/language/DummyPlugin --language=Python --join-existing --keyword=__ --keyword plugins/DummyPlugin/plugin.lang.php etc...
To extract run the following xgettext command for every file, in Windows for example;
xgettext.exe --default-domain=c:\phpdevshell\plugins\DummyPlugin\language\DummyPlugin --language=Python --keyword=__ --keyword c:\phpdevshell\plugins\DummyPlugin\list_script.php xgettext.exe --default-domain=c:\phpdevshell\plugins\DummyPlugin\language\DummyPlugin --language=Python --join-existing --keyword=__ --keyword c:\phpdevshell\plugins\DummyPlugin\plugin.lang.php etc...
Note, You might have noticed that I use Python under the --language selector, there is a good reason for this, if I choose php it will not look under heredoc tags leaving some string un-extracted. This is kind of a limitation, but choosing Python handles this correctly.
Above will create a single file DummyPlugin.po with all the available language strings in this one single file ready for translation.
Step 3: Translating the po file to the new language and saving as compiled mo
This process is rather simple if you too use the https://launchpad.net/ system like PHPDevShell does, however if this is a once-off translation effort you can use any other of the following tools to load the .po file and do the translation.
- poEdit: I recommend this application, an open source program for Windows, Mac OS X and UNIX/Linux which provides an easy-to-use GUI for editing PO files and generate MO files. I strongly recommend this tool, it can be downloaded here;
- KBabel: Another open source PO editing program for the KDE window manager on Linux.
- GNU Gettext: The official Gettext tools package contains command-line tools for creating POTs, manipulating POs, and generating MOs. For those comfortable with a command shell.
- Using POEdit as an example, open the po file created in Step 2 and do the translation.
- When done save the file as a compiled .mo file, this file will be used by PHPDevShell for its translation.
Step 4: Where to move newly created .mo files?
You are almost done! The next few steps are the final steps in the translation process. This is where the .mo files needs to be moved so the translation system can locate and load the.
- Enable the Language Debugger in PHPDevShell so you can see where PHPDevShell will look for translated mo files. This can be done in System Control -> System Admin -> System Settings. Then enable Debug Language System.
- Now copy your .mo file from the language debug information to the correct directory, see below example:
/home/titan/html/phpdev/plugins/DummyPlugin/language/af_ZA/LC_MESSAGES/DummyPlugin.mo
Thats it!
I hope this will help you in translating your third party plugins.
Translating classes and hooks.
Same development and configuration applies when you want to have your hooks and classes also translatable. However because the classes and hooks gets called inside your script their is a good chance that the hook or class might change the textdomain to look for translated strings for the original script, this mean the original script will not be translated after the call. To prevent this PHPDevShell has the ability to override the textdomain, however you need to tell it to where to look for in classes and hooks.
This process is very easy, for both hook and class scripts have your strings as follow (also look at SimplePhonebook for examples);
Say for instance you class name is sample.class.php, your string would look like this;
$d = 'DummyPlugin'; $core->__('Hello World', $d);
Thats all, it will now know where to look for this string to translate, same works for hook scripts. You do not need to do this for any other scripts, just hooks and classes because it gets called inside the main script.

