I'm looking for a way to make PoEdit understand PHP annotations. Here's a sample of code I want PoEdit to pick up and put into catalog:
class MyController extends Controller {
/**
* @Title "Home"
*/
public function index() {
...
}
}
The interesting part is @Title
annotation. It is accessed in front controller and assigned to master view, effectively ending up inside <title>...</title>
tag.
Now I need that string translated, but PoEdit seems to only understand _()
expressions, and adding @Title
to keywords does not work. This is probably because annotations in PHP are in comment block.
Is there any way to force PoEdit to understand annotations?
Introduction to PHP Annotations. PHP annotations are basically metadata which can be included in the source code and also in between classes, functions, properties and methods. They are to be started with the prefix @ wherever they are declared and they indicate something specific.
Poedit was built to handle translation using gettext (PO), which is used by many PHP projects (Drupal, WordPress), Python projects (Django), or virtually anything running on Linux.
PHP-DOC annotations do not have a fixed syntax - that is, everything after @name is interpreted differently for each type of annotation. For example, the syntax for @var is @var {type} {description}, while the syntax for @param is @param {type} {$name} {description}.
Open Source version and source code Up-to-date source code of the Open Source version of Poedit (sans the Pro features included in the above binaries) is available at GitHub under the terms of the MIT license. Windows and Mac versions can only be built from a git checkout; Unix builds can be done either from the checkout or from the above tarball.
Short answer, you can't.
POEdit uses xgettext to scan your files therefore using specific syntax, ignoring commented lines.
For example, if your keywords are _
the following examples will be parsed like:
_('test');
-> string 'test'
_("test");
-> string 'test'
_('test'
-> string 'test'
_ 'test
-> no catch
_('test
-> no catch
_(test)
-> no catch
_($test)
-> no catch
//_('test');
-> no catch
/*_('test');*/
-> no catch
You can execute xgettext
using other parameters but I'm not sure if you will be able to achieve your goal.
One easy fix (not standard ofc) is to add other keyword like placeholder
and make a php function like
function placeholder($string){}
and use it so POEdit can parse it
class MyController extends Controller {
/**
* @Title "Home"
*/
public function index() {
placeholder('Home');
...
}
}
At your frontend parser just use the simple _($value)
and you will have your title translated.
Dunno how is your code but will assume its something similar to this.
Assuming that $tag = 'title' and $value = 'Home'
echo '<'.$tag.'>'._($value).'</'.$tag.'>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With