MyBB Community Forums

Full Version: Language support for plugin settings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

is there a possibility so provide language support for own plugins?
Something like this should work:
$lang->load("plugins/bdnames");
	$bdnames_setting_1 = array(
		"sid"			=> "NULL",
		"name"			=> "bdnames_use_advanced",
		"title"			=> $lang->bdnames_use_advanced,
		"description"	=> $lang->bdnames_use_advanced_description,
		"optionscode"	=> "yesno",
		"value"			=> "1",
		"disporder"		=> "1",
		"gid"			=> intval($gid),
	);
But this sets the language at the activation of my plugin. How can i make it depending on the users language?
Could something like this work:
	$bdnames_setting_1 = array(
		"sid"			=> "NULL",
		"name"			=> "bdnames_use_advanced",
		"title"			=> '$lang->bdnames_use_advanced',
		"description"	=> '$lang->bdnames_use_advanced_description',
		"optionscode"	=> "yesno",
		"value"			=> "1",
		"disporder"		=> "1",
		"gid"			=> intval($gid),
	);
I think not realy, because how does the mybb knows which file it should load?
You could do something like that:
function my_activate()
{
global $lang;
$lang->load('my');
$new_setting = array(
... => $lang->something
);
}


Or you can use the fact that MyBB searches for language variables (setting group langvars should be named setting_group_{$name} and setting titles are named setting_{$name} whilst descriptions are setting_{$name}_desc)
Yes, this is what i did.
But then the placeholder for the language will be replaced on activation.
All admins will see the settings in the same language and not in their own language. But this is what i wanna have
Then use the second solution I gave...
You could add a plugin hook to load the necessary langvars for the settings page if you want to have it in an external .lang.php file.
The settings that plugins add should be translatable in the same way that default settings are translated.
$l['setting_group_<name>'] = "Setting group name";
$l['setting_group_<name>_desc'] = "Setting group description";

$l['setting_<name>'] = "Name";
$l['setting_<name>_desc'] = "Description";
<name> is replaced with the codename of your setting/group.

As Zinga said, you can have a plugin hook to load your plugin's language file in the settings manager.