From 67f72f1a617371b2ea1a235872315120ea1683f5 Mon Sep 17 00:00:00 2001 From: Igor Date: Wed, 10 Nov 2010 13:54:03 +0300 Subject: Support for Translate plugin --- conf/default.php | 1 + syntax.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/conf/default.php b/conf/default.php index 897b755..e68a413 100644 --- a/conf/default.php +++ b/conf/default.php @@ -12,4 +12,5 @@ $conf['filetypes'] = array('PDF', 'DjVu', 'PS', 'TIFF'); $conf['papers'] = 'публикации'; // Wiki page with bibtex data $conf['grants'] = 'гранты'; $conf['purge-cache'] = true; +$conf['languages'] = 'ru, en'; diff --git a/syntax.php b/syntax.php index b608ab1..a9260ee 100644 --- a/syntax.php +++ b/syntax.php @@ -24,6 +24,16 @@ require_once (DOKU_PLUGIN . 'papers/bibtex.php'); class syntax_plugin_papers extends DokuWiki_Syntax_Plugin { + protected $langs_rx = ''; + + function syntax_plugin_papers() + { + //print($this->getConf('languages')); + $l = preg_replace('/\W+?\s*/u', '|', mb_strtolower($this->getConf('languages'))); + $this->langs_rx = '(' . $l . ')'; + //print ($this->langs_rx . "\n"); + } + function getType() { return 'protected'; } function getPType() { return 'block'; } // http://www.dokuwiki.org/devel:syntax_plugins#ptype @@ -151,9 +161,27 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin return p_render('xhtml', p_get_instructions($text), $info); } + function getLangPart($id) + { + if (preg_match('/^' . $this->langs_rx . '/', $id, $match)) + { + return $match[1]; + } + return ''; + } function format_bibtex(&$bibtex, $options = array()) { + global $ID; + global $conf; + + $save_lang = $this->getLangPart($ID); + if (!empty($save_lang)) + { + $save_lang = $conf['lang']; + $conf['lang'] = $this->getLangPart($ID); + } + $res = ''; $year = ''; $year_prev = ''; $type = ''; $type_prev = ''; @@ -247,6 +275,8 @@ class syntax_plugin_papers extends DokuWiki_Syntax_Plugin $res .= "\n"; + + if (!empty($save_lang)) $conf['lang'] = $save_lang; return $res; } } -- cgit v1.2.3