Skip to content

Instantly share code, notes, and snippets.

@netcarver
Created October 20, 2008 03:42
Show Gist options
  • Save netcarver/18010 to your computer and use it in GitHub Desktop.
Save netcarver/18010 to your computer and use it in GitHub Desktop.
class sed_lib_mlp
{
var $strings;
var $owner;
var $prefix;
var $lang;
var $event;
function sed_lib_mlp( $plugin_name , $strarray , $prefix='' , $ev='common' , $lng='en-gb' )
{
$this->owner = $plugin_name;
$this->prefix = (empty($prefix)) ? strtolower( strtr($plugin_name, array('-'=>'_') ) ) : $prefix;
$this->strings = $strarray;
$this->lang = $lng;
$this->event = $ev; # valid events are 'public' , 'admin' and 'common'
register_callback( array(&$this, 'callback') , 'l10n.enumerate_strings' );
}
function callback()
{
$r = array(
'owner' => $this->owner,
'prefix' => $this->prefix,
'lang' => $this->lang,
'event' => $this->event,
'strings' => $this->strings,
);
return $r;
}
# Generic lookup
# $what = key to look up, should be a lowercase string.
# $args = any arguments the key is expecting for replacement
function gTxt( $what , $args = array() )
{
global $textarray;
# Prepare the prefixed key for use
#$what = strtolower($what);
$key = $this->prefix . '-' . $what;
# Grab from the global textarray (possibly edited by MLP) if we can
if( isset( $textarray[$key]) )
$str = $textarray[$key];
else
# The string isn't in the localised textarray so fallback to using the (non prefixed) string array in the plugin
$str = ( isset($this->strings[$what]) ) ? $this->strings[$what] : $what;
$str = strtr($str, $args);
return $str;
}
}
$strings =array( ... );
$str = new sed_lib_mlp( 'ebl_batch_upload', $strings );
# Where needed...
echo $str->gTxt('my_string');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment