[pmwiki-users] translation table using a variable

Peter Bowers pbowers at pobox.com
Wed Jul 2 15:51:14 CDT 2014


On Fri, Jun 27, 2014 at 10:44 AM, <lists at basel-inside.ch> wrote:

> I didn't find out until the moment, whether it's logic oder a bug
> $[lang_bas_str] doesn't seem to accept a function or ariable.
>
> I ase a workarround now - I use a comparison and a litteral/constant to
> translate.
>
> (:if equal {(substr {*$Trail} 9 7)} Gross:)[[Category/{(substr {*$Trail} 9
> 7)}?action=browse|$[Category]:$[Gross]-]](;elseif.....
>


If you set $EnableDiag to true and access a page with ?action=ruleset you
will see that the $[phrase] rule for translation fires in order #7 while
variables are order #8 and markup expressions are order #9.  This is why
you cannot translate the results of variables or markup expressions.

At different times in the past when faced with a specific need like this
where the standard rule order just doesn't do what I need I have
copy/pasted the markup function call from stdmarkup.php into config.php and
changed the name of the rule and the order.  Currently translation is
accomplished like this:

===(snip)===
# $[phrase] substitutions
Markup_e('$[phrase]', '>[=',
  '/\\$\\[(?>([^\\]]+))\\]/', "NoCache(XL(\$m[1]))");
===(snip)===

I would copy that from scripts/stdmarkup.php into config.php and change it
to be something like this:

===(snip)===
# $[phrase] substitutions
Markup_e('$[latexlate]', '>{(',
  '/\\$\\[(?>([^\\]]+))\\]/', "NoCache(XL(\$m[1]))");
===(snip)===

That will run right after markup expressions.  (Sometimes changing the
order of one rule like this will swap around the order of other rules if
the new order still fulfills the specified requirements, so you'll want to
ensure that it's still happening after {$var} as well using the
?action=ruleset again.)

It's somewhat inefficient because you will run the same rule twice, but it
keeps you from making changes to the core and it solves the problem you're
dealing with...

Oh, this assumes that the variable or the markup expression actually
contains the $[ and ] characters as well.  If you are doing $[{$var}] then
you'll need to change the markup slightly to be $late[{$var}] and then
change the regular expression to match appropriately.  (Otherwise the
$[...] will be changed to just ... by the firing of the first rule.)

I believe there's some way to delete a rule and then just redefine it in
your config.php - in fact, maybe simply by re-defining it you get rid of
previous definitions? - but it's been too long since I played with this
stuff so I don't remember.  If you can re-define the rule then just
copy/paste from stdmarkup.php and change the 2nd argument to be in the
order you want it to be.

-Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20140702/64aec32a/attachment.html>


More information about the pmwiki-users mailing list