[pmwiki-users] Nested IFs / setting variables with directives

Patrick R. Michaud pmichaud at pobox.com
Sat Sep 30 10:29:04 CDT 2006

On Sat, Sep 30, 2006 at 04:56:12PM +0200, Mike wrote:
> Could you give me a hint about how to combine the Multi Language recipe
> with phrase translations? I.e., how does the phrase translation
> mechanism know which language is currently selected by Multi Language's
> "userlang" parameter?

Hmmm, this is the first time I've really looked at MultiLanguage
in detail, so I need to look at it a bit further.  But on first
reading it looks like the simplest approach might be to
simply use the userlang parameter to select the translation
pages to be loaded:

    switch (@$_COOKIE['userlang']) {
      case 'de': XLPage('de', 'PmWikiDe.XLPage');
                 XLPage('de', 'Site.XLPageDe');
      case 'fr': XLPage('fr', 'PmWikiFr.XLPage');
                 XLPage('fr', 'Site.XLPageFr');
      case 'it': XLPage('it', 'PmWikiIt.XLPage');
                 XLPage('it', 'Site.XLPageIt');

This loads in the standard translations as well as as any custom
translations from a Site.XLPage* page.

However, in thinking about the recipe a bit more I think I would
advocate a different approach to this problem.  Instead of trying
to do so much using the (:if:) markup, I think I would recommend
that we create a custom (:lang:) markup that handles the language
specific translations, including the "else" clase.  For example:

    (:lang de:)
    Text that is displayed when the language is german
    (:lang fr:)
    Text that is displayed when the language is french
    (:lang default:)
    Text that is displayed when the language is neither french nor german

This handles the "if-elseif-else" semantics that are desired,
but also it allows "nesting" of (:lang:) and (:if:):

    (:if ! name Index:)
    (:lang de:)German
    (:lang fr:)French
    (:lang it:)Italian
    (:lang default:)English

If we wanted to be a bit more general, we could have a "switch"
statement of sorts

    (:switch {$UserLang}:)
    (:case de:)German
    (:case fr:)French
    (:case it:)Italian
    (:case *:)English

but MultiLanguage is an area where I think having the custom (:lang:)
markup might make more sense to authors than something like 

Anyway, I'll have to think on the multilanguage issue a bit more.


More information about the pmwiki-users mailing list