Plugin: wvdslang
Version: 1.0.0
Namespace: lib/plugins/wvdslang/
Author: Wolfgang van der Stille zeljko.petrusic@outlook.de
License: GPL 2
The wvdslang plugin enables multilingual translations in DokuWiki pages with centralized management. It solves the problem of scattered translations and provides a secure alternative to PHP code in pages.
{{wvds:lang>key}}
| Syntax | Description | Example |
|---|---|---|
{{wvds:lang>key}} | Translation from INI configuration | {{wvds:lang>menu_home}} |
{{wvds:lang:CODE>key}} | Explicit language | {{wvds:lang:en>menu_home}} |
{{wvds:lang>de:X|en:Y}} | Inline translation | {{wvds:lang>de:Ja|en:Yes}} |
{{wvds:lang>conf:setting}} | DokuWiki configuration | {{wvds:lang>conf:title}} |
{{wvds:lang>tpl:setting}} | Template configuration | {{wvds:lang>tpl:footerText}} |
| Parameter | Type | Description |
|---|---|---|
| key | string | Key from INI configuration |
| CODE | string | ISO 639-1 language code (de, en, sl, etc.) |
| conf: | prefix | Prefix for DokuWiki configuration values |
| tpl: | prefix | Prefix for template configuration values |
Via Admin → Configuration → wvdslang:
| Setting | Type | Default | Description |
|---|---|---|---|
enabled | On/Off | On | Enable/disable plugin |
languages | Text | de,en | Available languages (comma-separated) |
defaultLang | Text | de | Default language for fallback |
langPosition | Number | 0 | Language position in namespace path (0 = first level) |
translations | Textarea | (empty) | Translations in INI format |
Translations are stored in INI format in the plugin configuration:
[de] menu_home = Startseite menu_contact = Kontakt menu_back = Zurück site_welcome = Willkommen auf unserer Seite [en] menu_home = Home menu_contact = Contact menu_back = Back site_welcome = Welcome to our site [sl] menu_home = Domov menu_contact = Kontakt menu_back = Nazaj site_welcome = Dobrodošli na naši strani
| Rule | Example |
|---|---|
| Section with language code | [de], [en], [sl] |
| Key = Value | menu_home = Home |
| No quotes needed | text = My Text |
| Spaces allowed | long_text = This is a long text |
| Multiline not possible | Use \\n for line breaks |
Requirement: Menu text should display in current language.
Welcome to the {{wvds:lang>menu_home}}!
Result (at en:start):
Result (at de:start):
Requirement: Show German term in English documentation.
The hash value (German: {{wvds:lang:de>term_hash}}) is a cryptographic fingerprint.
Configuration:
[de] term_hash = Hashwert [en] term_hash = Hash
Result:
Requirement: Quick translation without configuration entry.
{{wvds:lang>de:Weiter|en:Continue|sl:Naprej}}
Result:
Requirement: Translations in sidebar with HTML structure.
<html> <nav class="main-menu"> <ul> <li><a href="?id=start">{{wvds:lang>menu_home}}</a></li> <li><a href="?id=contact">{{wvds:lang>menu_contact}}</a></li> </ul> </nav> </html>
<html>…</html> blocks, as it replaces before HTML processing.
Requirement: Read multilingual wiki title from configuration.
Welcome to {{wvds:lang>conf:title}}
DokuWiki local.php:
$conf['title'] = 'de:Wissensdatenbank|en:Knowledge Base|sl:Baza znanja';
Result (on English page):
1. Syntax Detection
└── Finds all {{wvds:lang>...}} tags in the page
2. Language Detection
└── Checks namespace path (e.g., en:page → "en")
└── If not found: Browser Accept-Language header
└── If not found: Default language from configuration
3. Key Resolution
├── conf:* → Reads from $conf[...]
├── tpl:* → Reads from tpl_getConf(...)
├── de:X|en:Y → Parses inline format
└── key → Searches in INI translations
4. Value Extraction
└── For pipe format: Extracts value for current language
└── For simple value: Returns value directly
└── Fallback: defaultLang or key itself
5. Replacement
└── Replaces tag with found value
Language is detected in the following priority:
| Priority | Source | Example |
|---|---|---|
| 1 | Namespace path | en:docs:start → „en“ |
| 2 | Accept-Language header | en-US,en;q=0.9,de;q=0.8 → „en“ |
| 3 | Default language | defaultLang = en → „en“ |
langPosition. With langPosition=0, the first segment is used (e.g., en:docs:start).
Via Admin → Configuration → wvdslang:
| Setting | Type | Default | Description |
|---|---|---|---|
enabled | On/Off | On | Enable plugin |
languages | Text | de,en | Available languages |
defaultLang | Text | de | Default language |
langPosition | Number | 0 | Language position in namespace |
The translations textarea contains all translations in INI format:
[de] ; Navigation menu_home = Startseite menu_docs = Dokumentation menu_contact = Kontakt menu_back = Zurück ; General site_welcome = Willkommen site_footer = © 2025 My Company [en] ; Navigation menu_home = Home menu_docs = Documentation menu_contact = Contact menu_back = Back ; General site_welcome = Welcome site_footer = © 2025 My Company
| Scenario | Behavior |
|---|---|
| Key not found | Returns the key itself |
| Language not in INI | Fallback to defaultLang |
| No fallback available | Returns the key |
| Invalid format | Returns the original |
If problems occur, check:
langPosition value correct?languages list?| Scenario | Recommendation |
| Few translations (<50) | Normal usage |
| Many translations (50-500) | Group by area |
| Very many translations (>500) | Split into wvdschunk |
{{wvds:lang>...}} should use ~~NOCACHE~~ if content should change based on language.
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | 2025-01-06 | Initial release |
File: lib/plugins/wvdslang/syntax.php
| Method | Description |
|---|---|
getType() | Returns substition |
getSort() | Returns 305 (before wvdschunk) |
connectTo($mode) | Registers pattern \\{\\{wvds:lang[^}]*>[^}]+\\}\\} |
handle($match, …) | Parses syntax, extracts key and language |
render($mode, …) | Replaces tag with translated value |
File: lib/plugins/wvdslang/helper.php
| Method | Parameters | Returns | Description |
|---|---|---|---|
getLang() | - | string | Determines current language |
get() | $key, $lang=null | string | Returns translation |
parseTranslations() | $ini | array | Parses INI into array |
parseValue() | $value, $lang | string | Extracts language value from pipe format |
// In template files (main.php, etc.) $helper = plugin_load('helper', 'wvdslang'); if ($helper) { $lang = $helper->getLang(); $homeText = $helper->get('menu_home'); echo "<a href='?id=start'>$homeText</a>"; }
// In other plugins $langHelper = plugin_load('helper', 'wvdslang'); if ($langHelper) { $translated = $langHelper->get('my_key'); }