Skip to content
Snippets Groups Projects
Commit 9f01cf6a authored by Gabriel Birke's avatar Gabriel Birke
Browse files

Translatable JavaScript strings for plugins

Strings to be used in plugin provided JavaScript can now be put into the plugin's
lang.php files. It has to be stored as subkeys of $lang['js']. Eg the following in
lib/plugins/blah/lang/en/lang.php

$lang['js']['foo']

darcs-hash:20071026131130-79ce3-75ab69b1ba527c823e0e5ef0fde031032aaa2548.gz
parent 279c0a2e
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,9 @@ function js_out(){ ...@@ -85,6 +85,9 @@ function js_out(){
print "var notSavedYet = '".js_escape($lang['notsavedyet'])."';"; print "var notSavedYet = '".js_escape($lang['notsavedyet'])."';";
print "var reallyDel = '".js_escape($lang['del_confirm'])."';"; print "var reallyDel = '".js_escape($lang['del_confirm'])."';";
// load JS strings form plugins
$lang['js']['plugins'] = js_pluginstrings();
// load JS specific translations // load JS specific translations
$json = new JSON(); $json = new JSON();
echo 'LANG = '.$json->encode($lang['js']).";\n"; echo 'LANG = '.$json->encode($lang['js']).";\n";
...@@ -236,6 +239,34 @@ function js_pluginscripts(){ ...@@ -236,6 +239,34 @@ function js_pluginscripts(){
return $list; return $list;
} }
/**
* Return an two-dimensional array with strings from the language file of each plugin.
*
* - $lang['js'] must be an array.
* - Nothing is returned for plugins without an entry for $lang['js']
*
* @author Gabriel Birke <birke@d-scribe.de>
*/
function js_pluginstrings()
{
global $conf;
$pluginstrings = array();
$plugins = plugin_list();
foreach ($plugins as $p){
if (isset($lang)) unset($lang);
if (@file_exists(DOKU_PLUGIN."$p/lang/en/lang.php")) {
include DOKU_PLUGIN."$p/lang/en/lang.php";
}
if (isset($conf['lang']) && $conf['lang']!='en' && @file_exists(DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php")) {
include DOKU_PLUGIN."$p/lang/".$conf['lang']."/lang.php";
}
if (isset($lang['js'])) {
$pluginstrings[$p] = $lang['js'];
}
}
return $pluginstrings;
}
/** /**
* Escapes a String to be embedded in a JavaScript call, keeps \n * Escapes a String to be embedded in a JavaScript call, keeps \n
* as newline * as newline
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment