Skip to content

Commit

Permalink
Merge pull request #708 from splitbrain/overridablelangstrings
Browse files Browse the repository at this point in the history
extend lang file cascade, so users can override some lang strings
  • Loading branch information
splitbrain committed Sep 29, 2014
2 parents 17553fc + 0440ca4 commit 85674a7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 89 deletions.
114 changes: 59 additions & 55 deletions inc/config_cascade.php
Expand Up @@ -8,71 +8,75 @@
$config_cascade = array_merge(
array(
'main' => array(
'default' => array(DOKU_CONF.'dokuwiki.php'),
'local' => array(DOKU_CONF.'local.php'),
'protected' => array(DOKU_CONF.'local.protected.php'),
),
'acronyms' => array(
'default' => array(DOKU_CONF.'acronyms.conf'),
'local' => array(DOKU_CONF.'acronyms.local.conf'),
),
'entities' => array(
'default' => array(DOKU_CONF.'entities.conf'),
'local' => array(DOKU_CONF.'entities.local.conf'),
),
'default' => array(DOKU_CONF . 'dokuwiki.php'),
'local' => array(DOKU_CONF . 'local.php'),
'protected' => array(DOKU_CONF . 'local.protected.php'),
),
'acronyms' => array(
'default' => array(DOKU_CONF . 'acronyms.conf'),
'local' => array(DOKU_CONF . 'acronyms.local.conf'),
),
'entities' => array(
'default' => array(DOKU_CONF . 'entities.conf'),
'local' => array(DOKU_CONF . 'entities.local.conf'),
),
'interwiki' => array(
'default' => array(DOKU_CONF.'interwiki.conf'),
'local' => array(DOKU_CONF.'interwiki.local.conf'),
),
'default' => array(DOKU_CONF . 'interwiki.conf'),
'local' => array(DOKU_CONF . 'interwiki.local.conf'),
),
'license' => array(
'default' => array(DOKU_CONF.'license.php'),
'local' => array(DOKU_CONF.'license.local.php'),
),
'default' => array(DOKU_CONF . 'license.php'),
'local' => array(DOKU_CONF . 'license.local.php'),
),
'mediameta' => array(
'default' => array(DOKU_CONF.'mediameta.php'),
'local' => array(DOKU_CONF.'mediameta.local.php'),
),
'mime' => array(
'default' => array(DOKU_CONF.'mime.conf'),
'local' => array(DOKU_CONF.'mime.local.conf'),
),
'scheme' => array(
'default' => array(DOKU_CONF.'scheme.conf'),
'local' => array(DOKU_CONF.'scheme.local.conf'),
),
'smileys' => array(
'default' => array(DOKU_CONF.'smileys.conf'),
'local' => array(DOKU_CONF.'smileys.local.conf'),
),
'default' => array(DOKU_CONF . 'mediameta.php'),
'local' => array(DOKU_CONF . 'mediameta.local.php'),
),
'mime' => array(
'default' => array(DOKU_CONF . 'mime.conf'),
'local' => array(DOKU_CONF . 'mime.local.conf'),
),
'scheme' => array(
'default' => array(DOKU_CONF . 'scheme.conf'),
'local' => array(DOKU_CONF . 'scheme.local.conf'),
),
'smileys' => array(
'default' => array(DOKU_CONF . 'smileys.conf'),
'local' => array(DOKU_CONF . 'smileys.local.conf'),
),
'wordblock' => array(
'default' => array(DOKU_CONF.'wordblock.conf'),
'local' => array(DOKU_CONF.'wordblock.local.conf'),
),
'default' => array(DOKU_CONF . 'wordblock.conf'),
'local' => array(DOKU_CONF . 'wordblock.local.conf'),
),
'userstyle' => array(
'screen' => DOKU_CONF.'userstyle.css',
'print' => DOKU_CONF.'userprint.css',
'feed' => DOKU_CONF.'userfeed.css',
'all' => DOKU_CONF.'userall.css',
),
'screen' => DOKU_CONF . 'userstyle.css',
'print' => DOKU_CONF . 'userprint.css',
'feed' => DOKU_CONF . 'userfeed.css',
'all' => DOKU_CONF . 'userall.css',
),
'userscript' => array(
'default' => DOKU_CONF.'userscript.js'
),
'acl' => array(
'default' => DOKU_CONF.'acl.auth.php',
),
'default' => DOKU_CONF . 'userscript.js'
),
'acl' => array(
'default' => DOKU_CONF . 'acl.auth.php',
),
'plainauth.users' => array(
'default' => DOKU_CONF.'users.auth.php',
),

'default' => DOKU_CONF . 'users.auth.php',
),
'plugins' => array(
'default' => array(DOKU_CONF.'plugins.php'),
'local' => array(DOKU_CONF.'plugins.local.php'),
'default' => array(DOKU_CONF . 'plugins.php'),
'local' => array(DOKU_CONF . 'plugins.local.php'),
'protected' => array(
DOKU_CONF.'plugins.required.php',
DOKU_CONF.'plugins.protected.php',
),
DOKU_CONF . 'plugins.required.php',
DOKU_CONF . 'plugins.protected.php',
),
),
$config_cascade
'lang' => array(
'core' => array(DOKU_CONF . 'lang/'),
'plugin' => array(DOKU_CONF . 'plugin_lang/'),
'template' => array(DOKU_CONF . 'template_lang/')
)
),
$config_cascade
);

18 changes: 17 additions & 1 deletion inc/init.php
Expand Up @@ -259,17 +259,33 @@ function init_paths(){
$conf['media_changelog'] = $conf['metadir'].'/_media.changes';
}

/**
* Load the language strings
*
* @param string $langCode language code, as passed by event handler
*/
function init_lang($langCode) {
//prepare language array
global $lang;
global $lang, $config_cascade;
$lang = array();

//load the language files
require(DOKU_INC.'inc/lang/en/lang.php');
foreach ($config_cascade['lang']['core'] as $config_file) {
if (@file_exists($config_file . 'en/lang.php')) {
include($config_file . 'en/lang.php');
}
}

if ($langCode && $langCode != 'en') {
if (file_exists(DOKU_INC."inc/lang/$langCode/lang.php")) {
require(DOKU_INC."inc/lang/$langCode/lang.php");
}
foreach ($config_cascade['lang']['core'] as $config_file) {
if (@file_exists($config_file . "$langCode/lang.php")) {
include($config_file . "$langCode/lang.php");
}
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions inc/media.php
Expand Up @@ -582,6 +582,12 @@ function media_notify($id,$file,$mime,$old_rev=false){

/**
* List all files in a given Media namespace
*
* @param string $ns namespace
* @param null|int $auth permission level
* @param string $jump
* @param bool $fullscreenview
* @param bool|string $sort sorting, false skips sorting
*/
function media_filelist($ns,$auth=null,$jump='',$fullscreenview=false,$sort=false){
global $conf;
Expand Down
1 change: 1 addition & 0 deletions inc/parserutils.php
Expand Up @@ -640,6 +640,7 @@ function p_get_renderer($mode) {
}

// not bundled, see if its an enabled renderer plugin & when $mode is 'xhtml', the renderer can supply that format.
/** @var Doku_Renderer $Renderer */
$Renderer = $plugin_controller->load('renderer',$rname);
if ($Renderer && is_a($Renderer, 'Doku_Renderer') && ($mode != 'xhtml' || $mode == $Renderer->getFormat())) {
return $Renderer;
Expand Down
57 changes: 35 additions & 22 deletions inc/plugin.php
Expand Up @@ -30,7 +30,7 @@ class DokuWiki_Plugin {
* desc - Short description of the plugin (Text only)
* url - Website with more information on the plugin (eg. syntax description)
*/
function getInfo() {
public function getInfo(){
$parts = explode('_', get_class($this));
$info = DOKU_PLUGIN . '/' . $parts[2] . '/plugin.info.txt';
if(@file_exists($info)) return confToHash($info);
Expand All @@ -48,16 +48,16 @@ function getInfo() {

// plugin introspection methods
// extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
function getPluginType() {
public function getPluginType() {
list($t) = explode('_', get_class($this), 2);
return $t;
}
function getPluginName() {
list($t, $p, $n) = explode('_', get_class($this), 4);
public function getPluginName() {
list(/* $t */, /* $p */, $n) = explode('_', get_class($this), 4);
return $n;
}
function getPluginComponent() {
list($t, $p, $n, $c) = explode('_', get_class($this), 4);
public function getPluginComponent() {
list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_class($this), 4);
return (isset($c)?$c:'');
}

Expand All @@ -71,7 +71,7 @@ function getPluginComponent() {
* @param string $id id of the string to be retrieved
* @return string string in appropriate language or english if not available
*/
function getLang($id) {
public function getLang($id) {
if (!$this->localised) $this->setupLocale();

return (isset($this->lang[$id]) ? $this->lang[$id] : '');
Expand All @@ -86,7 +86,7 @@ function getLang($id) {
* @param string $id id of language dependent wiki page
* @return string parsed contents of the wiki page in xhtml format
*/
function locale_xhtml($id) {
public function locale_xhtml($id) {
return p_cached_output($this->localFN($id));
}

Expand All @@ -95,7 +95,7 @@ function locale_xhtml($id) {
* prepends appropriate path for a language dependent filename
* plugin equivalent of localFN()
*/
function localFN($id) {
public function localFN($id) {
global $conf;
$plugin = $this->getPluginName();
$file = DOKU_CONF.'plugin_lang/'.$plugin.'/'.$conf['lang'].'/'.$id.'.txt';
Expand All @@ -115,16 +115,29 @@ function localFN($id) {
* this function is automatically called by getLang()
*/
function setupLocale() {
if ($this->localised) return;
if($this->localised) return;

global $conf; // definitely don't invoke "global $lang"
$path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
global $conf, $config_cascade; // definitely don't invoke "global $lang"
$path = DOKU_PLUGIN . $this->getPluginName() . '/lang/';

$lang = array();

// don't include once, in case several plugin components require the same language file
@include($path.'en/lang.php');
if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
@include($path . 'en/lang.php');
foreach($config_cascade['lang']['plugin'] as $config_file) {
if(@file_exists($config_file . $this->getPluginName() . '/en/lang.php')) {
include($config_file . $this->getPluginName() . '/en/lang.php');
}
}

if($conf['lang'] != 'en') {
@include($path . $conf['lang'] . '/lang.php');
foreach($config_cascade['lang']['plugin'] as $config_file) {
if(@file_exists($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php')) {
include($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php');
}
}
}

$this->lang = $lang;
$this->localised = true;
Expand All @@ -140,7 +153,7 @@ function setupLocale() {
* @param mixed $notset what to return if the setting is not available
* @return mixed
*/
function getConf($setting, $notset=false){
public function getConf($setting, $notset=false){

if (!$this->configloaded){ $this->loadConfig(); }

Expand Down Expand Up @@ -177,7 +190,7 @@ function loadConfig(){
*
* @return array setting => value
*/
function readDefaultSettings() {
protected function readDefaultSettings() {

$path = DOKU_PLUGIN.$this->getPluginName().'/conf/';
$conf = array();
Expand All @@ -199,7 +212,7 @@ function readDefaultSettings() {
*
* @return object helper plugin object
*/
function loadHelper($name, $msg = true){
public function loadHelper($name, $msg = true){
$obj = plugin_load('helper',$name);
if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1);
return $obj;
Expand All @@ -212,7 +225,7 @@ function loadHelper($name, $msg = true){
* email
* standardised function to generate an email link according to obfuscation settings
*/
function email($email, $name='', $class='', $more='') {
public function email($email, $name='', $class='', $more='') {
if (!$email) return $name;
$email = obfuscate($email);
if (!$name) $name = $email;
Expand All @@ -224,7 +237,7 @@ function email($email, $name='', $class='', $more='') {
* external_link
* standardised function to generate an external link according to conf settings
*/
function external_link($link, $title='', $class='', $target='', $more='') {
public function external_link($link, $title='', $class='', $target='', $more='') {
global $conf;

$link = htmlentities($link);
Expand All @@ -251,7 +264,7 @@ function external_link($link, $title='', $class='', $target='', $more='') {
* @param $arguments
* @return null|string
*/
function __call($name, $arguments) {
public function __call($name, $arguments) {
if($name == 'render'){
dbg_deprecated('render_text()');
if(!isset($arguments[1])) $arguments[1] = 'xhtml';
Expand All @@ -269,7 +282,7 @@ function __call($name, $arguments) {
* @param string $format output format
* @return null|string
*/
function render_text($text, $format='xhtml') {
public function render_text($text, $format='xhtml') {
return p_render($format, p_get_instructions($text),$info);
}

Expand All @@ -278,7 +291,7 @@ function render_text($text, $format='xhtml') {
*
* @return bool false if the plugin has to be instantiated
*/
function isSingleton() {
public function isSingleton() {
return true;
}
}

0 comments on commit 85674a7

Please sign in to comment.