TemplateTag::subscripting - jcobban/Genealogy GitHub Wiki
The class TemplateTag
implements the methods of the interface ArrayAccess so that subscripts are used to reference string values which correspond either to values of the attribute 'data-key'
or to the position of a child tag under the current tag.
parameter | description |
---|---|
$key | a string which is used to search the children of this tag for a match on either the data-key attribute or the position under this tag |
For example the shared translate template 'TranTabfr.html'
, which encapsulates translations to French, includes the following tables, among others:
<div id="LMonths">
<span></span>
<span>Janvier</span>
<span>Fevrier</span>
<span>Mars</span>
<span>Avril</span>
<span>Mai</span>
<span>Juin</span>
<span>Juillet</span>
<span>Août</span>
<span>Septembre</span>
<span>Octobre</span>
<span>Novembre</span>
<span>Decembre</span>
</div>
<!-- general I18N translate table -->
<div id="tranTab" class="hidden">
<span data-key=""></span>
<span data-key="a[fem]">une</span>
<span data-key="a[masc]">un</span>
<span data-key="about">environ</span>
<span data-key="AD">ap. J.-C.</span>
<span data-key="adopted">adopté</span>
...
</div>
Given that $template
is an instance of class FtTemplate
which includes internationalization support:
$translate = $template->getTranslate(); // gets `'TranTab$lang.html'` as instance of Template
$lmonths = $translate['LMonths']; // get a translation table
$april = $lmonths[4]; // is 'Avril'
$t = $translate['tranTab']; // get a translation table
$after = $t['after']; // is 'apres'
$t['never'] = 'jamais'; // you may update the table locally