[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: wml::std::lang



Hello Stefan `Sec` Zehl, in a previous mail you wrote:

> I just looked at the manpage for "wml::std::lang" because i want to
> translate some pages of mine. There is the:
> 
> <href name="The Hyperlink" url="<lang:star: index.*.html>">
> 
> method for hyperlinks. This is lacking one (for me important) feature. I
> don't want to translate my _whole_ tree at once, so i'd like it to make
> links to "index.de.html" and "index.en.html" only if they exist. If one
> of them doesn't, it should just link to "index.html" (as a form of
> fallback) - Does anybody here have an idea how to accomplish that ?

Good question. I've started with <lang:star:> now and created
a specialized version named <lang:star:href:> which has the
following additional feature:

1. it tests for the existence and if it doesn't exist it
   used the value without the star.
   
2. Because just removing the star from index.*.html would
   lead to index..html instead of index.html and because one often wants
   really more complicated fallbacks, it recognizes the syntax
   ``value|alt-value'' where alt-value is then the fallback.

With this new tag you can write:

<href name="The Hyperlink" url="<lang:star:href: index.*.html|index.html>">

which means use index.xx.html when it exists else index.html. Here is the
definition of the tag which I find useful for the other users, so I've added
to wml::std::lang for WML 1.6.2 now. It reads ugly because a lot of Meta-HTML
stuff was needed. Sorry, but hate Meta-HTML, too :-( But it's the best choice
for Pass 2 we currently have...

===========================================
<define-tag lang:star:href:>
<ifeq <match "%attributes" ".+\\|.*" action=report> true <prog
    <set-var __str=<match "%attributes" "^[^|]+" action=extract>>
    <set-var __alt=<match "%attributes" "[^|]*$" action=extract>>
> <prog
    <set-var __str="%attributes">
    <set-var __alt=<match "%attributes" "\\*" action=delete>>
>>
<set-var __i=0>
<while <get-var __languages[__i]>>
    <set-var __url=<subst-in-string "<get-var __str>" 
                    "\\*" "<get-var __languages[__i]>">>
    <: if (-f "<get-var __url>") { _:>
        <suck><subst-in-string
               "[LANG_<upcase <get-var __languages[__i]>>:<get-var __str>:]"
               "\\*" "<get-var __languages[__i]>"><suck>
    <: } else { _:>
        <suck>[LANG_<upcase <get-var __languages[__i]>>:<get-var __alt>:]<suck>
    <: } :>
    <increment __i>
</while>
</define-tag>
===========================================

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com
______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com