InternationalPTVs

Summary: Allow international characters in the names of PageTextVariables
Version: 20240704
Prerequisites: PmWiki 2.2.58
Status: experimental
Maintainer: Petko
Users: +1 (view / edit)
License: PD

Description

Allow international characters in the names of PageTextVariables.

In the default installation, PageTextVariables can only have a name containing basic Latin/Roman (ASCII) letters, digits, dash and underscore. This is a limitation for international wikis. The recipe makes it possible to have variable names containing international characters in addition (or in place) of the basic Latin. With this recipe, PageTextVariables names can contain extended/accented Latin characters, Cyrillic alphabet, Greek alphabet, Chinese and other alphabets.

Demo: the recipe is enabled on this page and in the UTF8 group (it should work both with UTF-8 enabled and disabled).

Installation

Add to a local config file these lines:

include_once('scripts/xlpage-utf-8.php');

$PageTextVarPatterns = array(
  'var:'        => '/^(:*[ \\t]*([\\w\\x80-\\xff][-\\w\\x80-\\xff]*)[ \\t]*:[ \\t]?)(.*)($)/m',
  '(:var:...:)' => '/(\\(: *([\\w\\x80-\\xff][-\\w\\x80-\\xff]*) *:(?!\\))\\s?)(.*?)(:\\))/s'
  );

Markup('textvar:', '<split',
  '/\\(: *[\\w\\x80-\\xff][-\\w\\x80-\\xff]* *:(?!\\)).*?:\\)/s', '');

Markup('{$var}', '>$[phrase]',
  '/\\{(\\*|!?[-\\w.\\/\\x80-\\xff]*)(\\$:?[\\w\\x80-\\xff][-\\w\\x80-\\xff]*)\\}/',
  "i18n_ptv");

function i18n_ptv($m) {
  extract($GLOBALS['MarkupToHTML']);
  return PRR(PVSE(PageVar($pagename, $m[2], $m[1])));
}

$PageListArgPattern = '((?:\\$:?)?[\\w\\x80-\\xff][-\\w\\x80-\\xff]*)[:=]';

Usage

You can use any international characters as variable names.

(:Adreça: Carrer Casa Blanca, Alcoi (PV):)
(:Петко: "Petko" in Cyrillic alphabet:)
(:檢視:Something in Chinese:)
VoilàEnFrançais: Here you go in French

* Петко : %navy%{$:Петко}%%
* Adreça : %red%{$:Adreça}%%
* VoilàEnFrançais : %blue%{$:VoilàEnFrançais}%%
* 檢視 : %yellow%{$:檢視}%%

From another page ([[PITS.01272]]): 
* Institució: %green%{PITS.01272$:Institució} %%
* Telèfon: %red%{PITS.01272$:Telèfon} %%

VoilàEnFrançais: Here you go in French

  • Петко : "Petko" in Cyrillic alphabet
  • Adreça : Carrer Casa Blanca, Alcoi (PV)
  • VoilàEnFrançais : Here you go in French
  • 檢視 : Something in Chinese

From another page (PITS.01272):

  • Institució: Universitat Jaume I
  • Telèfon: +34 964 72 80 00

Notes

  • Currently PageLists cannot work with international PageTextVariables,
    • one could have (:pagelist $:ïñţvàя=search:)
    • but not (:pagelist order=$:ïñţvàя:) or use {=$:ïñţvàя} in PageList templates.
  • PmSyntax doesn't correctly highlight international PageTextVariables.

Change log / Release notes

  • 20121012 first release, ready to be tested.

See also

Contributors

Written by Petko.

Comments

See discussion at InternationalPTVs-Talk?

test

Here iPTVs like ={$Institució} are not expected to work (yet):

nameInstitucióTelèfon
01270{=$Institució}{=$Telèfon}
01271{=$Institució}{=$Telèfon}
01272{=$Institució}{=$Telèfon}
01273{=$Institució}{=$Telèfon}
01274{=$Institució}{=$Telèfon}
01275{=$Institució}{=$Telèfon}
01276{=$Institució}{=$Telèfon}
01277{=$Institució}{=$Telèfon}
01278{=$Institució}{=$Telèfon}
01279{=$Institució}{=$Telèfon}
[[#testfmt]]
(:template first:)
|| border=1
||! name ||! Institució ||! Telèfon ||
(:template each:)
|| [[{=$Group}/{=$Name}]] || {=$Institució} || {=$Telèfon} ||
[[#testfmtend]]

Here iPTVs like =$:Telèfon=*72* should be expected to work but not order=$:Institució (yet):

(:pagelist name=PITS.0127* $:Telèfon=*72* order=$:Institució:)
PITS /
01272  Locale letters not recognized by page text variables. (Closed, added to Cookbook)
01271  PHP Code Injection Vulnerability (Closed, fixed for 2.2.35)
(:pagelist name=PITS.0127* $:Telèfon=*72* order=-$:Institució:)
PITS /
01272  Locale letters not recognized by page text variables. (Closed, added to Cookbook)
01271  PHP Code Injection Vulnerability (Closed, fixed for 2.2.35)

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.